Alireza Farokhi
2 min readApr 15, 2022

Unit Testing Message Delivery in Message-Based Microservices — Part2(Unit Test Messaging)

in pervious part we setup microservices and messages. you can access to part1 by bellow link

in this part we setup test projects and write unit tests for messages

Testing Consumer

Right-click “Consumer” folder and create “xUnitTestProject” project and name it “ PaymentMicroservice.Unit.Tests” then add reference to “PaymentMicroservice” and install following Nuget packages:

Rename generated class to ‘InvoiceMessagingTests’ and add following code

run tests and here is the result

Testing Producer

Right-click “Producer” folder and create “xUnitTestProject” project and name it “ InvoiceMicroservice.Unit.Tests” then add reference to “InvoiceMicroservice” and install following Nuget packages:

Rename generated class to ‘InvoiceMessagingTests’ and add following code

run tests and here is the result

and solution is as bellow

download source code

Resource and more detail

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Alireza Farokhi
Alireza Farokhi

No responses yet

Write a response