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