The unit I'm testing is an IHostedService which communicates using IQueueClient from Microsoft.Azure.ServiceBus. As far as I can see, there is no function such as .Receive() which is why I am doing this:
_inputQueueClient.Setup(x => x.RegisterMessageHandler(
It.IsAny<Func<Message, CancellationToken, Task>>(),
It.IsAny<MessageHandlerOptions>()))
.Callback<Func<Message, CancellationToken, Task>, MessageHandlerOptions>((x, y) => _messageReceivedHandler = x);
so that I can get the message handling method and call it directly in my unit test. Is this an appropriate way to simulate a message received or is there a better way?