NSubstitute
NSubstitute copied to clipboard
Received() is not working for one of the servicebus class
ServiceBusSender substitute is not working..
I have a scenario where i send messages to servicebusender and check the received calls. here is the code:
**public ServiceBusSender serviceBusSender;
serviceBusSender = Substitute.For<ServiceBusSender>();
//iam sending some real messages to servicebusender
await serviceBusSender.Received()
.SendMessagesAsync(Arg.Is<IList<ServiceBusSender>>(messages));**
I need assistance in resolving this issue.
The code looks basically double wrong.
The signature of SendMessagesAsync looks like this:
public virtual async Task SendMessagesAsync(
IEnumerable<ServiceBusMessage> messages,
CancellationToken cancellationToken = default)
So you are having neither a list nor a T of ServiceBusSender.
If you are using a list as an argument, the assertion will work. Personally I would still advice to use IEnumerable instead of IList, cause you are asserting the internal implementation.
I made a small console app and everything works as intended:
var serviceBusSender = Substitute.For<ServiceBusSender>();
await serviceBusSender.SendMessagesAsync(new List<ServiceBusMessage>());
await serviceBusSender.Received().SendMessagesAsync(Arg.Any<IList<ServiceBusMessage>>());