NSubstitute icon indicating copy to clipboard operation
NSubstitute copied to clipboard

Received() is not working for one of the servicebus class

Open Jyothsna425 opened this issue 2 years ago • 1 comments

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.

Jyothsna425 avatar Feb 05 '23 17:02 Jyothsna425

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>>());

Ergamon avatar Feb 06 '23 23:02 Ergamon