Unit Testing SendLocal not documented

Hello, I’m trying to test wether for given data, a Saga sends out the correct SendLocal messages.

Testing NServiceBus • Testing • Particular Docs

var context = new TestableMessageHandlerContext();
await saga.Handle(DoSomething, context)
.ConfigureAwait(false);

var processMessage = context.SentMessages[0].Message;

I have the tests working and running, and I have used the debugger to confirm how it’s running through the Saga.

However when the Saga does a SendLocal, it never appears in the context.SentMessages[…] array.

How can I confirm which SendLocal messages have been sent?

Thanks.

Turns out I was reading something from the debugger wrong and expecting the SentMessages was empty.

SendLocal also populates the SentMessages.

So this is one way of checking if a particluar message has been sent inside a Saga.

Let’s assume our Saga runs this

context.SendLocal(new MyLocalCommand { Id = message.Id });

This is how we check if MyLocalCommand was run:

var sent = context.SentMessages;
Assert.That(sent, Has.Some.Matches<dynamic>(m => m.Message is MyLocalCommand));