I’,m trying to mock IEndpointinstance with NSubstitute to test what was actually sent, but I get an System.ArgumentNullException. Using IBus in similar way works fine.
This is the code:
var endpointInstance = Substitute.For<IEndpointInstance>(); var myService = new MyService(endpointInstance); myService.DoSomething(myObject); // this calls IEndpointInstance.Send(....) endpointInstance.Received().Send(Arg.Any<MyMessage>());
This throws this exception, (and no, mye message object is not null):
System.ArgumentNullException : Value cannot be null. Parameter name: message at NServiceBus.IMessageSessionExtensions.Send(IMessageSession session, Object message) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\IMessageSessionExtensions.cs:line 19
Is this by design? Reading the last comment from this SO-topic it seems tho be working with Moq, so I was wondering whether there is an issue with NSubstitute.
Note: I have refactored the code to use TestableEndpointInstance instead, and that works fine.