Lotzi11
Lotzi11

Reputation: 549

NSubstitute.Received(1) Catching Multiple Recieved Calls

I am writing test cases using NSubstitute to check that a certain method is called only once within our logic.

await _memberAddUpdateService.Received(1).UpdateMemberNameAsync(member);
await _customerAddUpdateService.DidNotReceive().AddCustomerAsync(member.Customer!);
await _customerAddUpdateService.Received(1).UpdateCustomerAsync(member.Customer!);
await _customerAddUpdateService.DidNotReceive().UpdateCustomerAsync(member.RfmsCustomer);

This check usually works most of the time, but will fail occasionally saying that either methods are being called twice. The only issue is that those methods are only called once within our entire project, and there is no looping that would cause the method to be called again.

Can NSubstitute's Received call be glitchy like this, or could there be an aspect of our code design that could be leading it to call the methods multiple times?

Upvotes: 0

Views: 124

Answers (1)

MatFied
MatFied

Reputation: 99

It is propably something in your code that call's the methods multiple times.

Upvotes: 1

Related Questions