I have a question about testing my application where I use a message broker (mass transit library, Azure Service Bus implementation) to communicate between services. Let's say I have ServiceA and ServiceB.
As far as integration tests are concerned, I guess it's clear there I just start up ServiceB and Message broker and test. However, I was more thinking if there is such a thing as contract tests with message broker? I tried searching and googling and couldn't find anything much.
Thanks a lot in advance.
Edit: ServiceA - This method send over mass transit topic message
public async Task Send()
{
await _publishEndpoint.Publish(new TestMessage(), cancellationToken);
}
ServiceB - Here is consumer of TestMessage
public class TestConsumer : IConsumer<TestMessage>
{
public async Task Consume(ConsumeContext<TestMessage> context)
{
// Do some work
}
}
The below code is for ServiceA and ServiceB along with an integration test to test the message flow between them using Azure Service Bus with MassTransit:
Test cases: