I would like to create tests for our NServiceBus configuration by creating an endpoint and send messages to it (to be able to test different scenarios).
To do that I’ve created a handler and then use ep.SendLocal
to send a message to it.
[Fact]
public async Task SomeTest()
{
// Our own builder that wraps the NServiceBus configuration
var sut = new EndpointBuilder("Myname");
sut.RegisterServices(x =>
{
x.RegisterType<MyService>().AsSelf().SingleInstance();
x.RegisterType<MyMessageHandler>().AsImplementedInterfaces();
});
// Will call Endpoint.Start(_endpointConfiguration) and return the ep
var ep = await sut.BuildEndpoint(ConnectionString);
// Creates a new static TaskCompletionSource
MyMessageHandler.Reset();
await ep.SendLocal(new MyMessage());
// waits on the tcs which will be completed when the handler is invoked
await MyMessageHandler.Wait(TimeSpan.FromSeconds(5));
await ep.Stop();
}
The handler is never invoked, do NSB wait for something before it actually sends and processes the message?