NSubstitute icon indicating copy to clipboard operation
NSubstitute copied to clipboard

Add .ReceivedNothingElse() method

Open GPWebb opened this issue 6 years ago • 2 comments

NSubstitute already allows powerful assertion that calls were made. However that's only part of the problem.

If can also be useful to check that other calls haven't happened. For smaller objects this isn't too bad, but for larger objects it can quickly become cluttered. Worse, if the object being substituted is itself extended the tests must be manually extended to cover those methods.

If NSubstitute were extended with a .ReceivedNothingElse() method, it would be trivial in a code review to check that that was the final call made to a substitute object, and be confident that a passing test was correctly asserting all calls.

GPWebb avatar Apr 04 '19 14:04 GPWebb

A duplicate of #203?

zvirja avatar Apr 04 '19 14:04 zvirja

I still like this idea from #203 for achieving this:

Have you seen Received.InOrder? It uses the beginnings of a call query model, and checks the query against a SequenceInOrderAssertion. This works differently to the assertion you're after (only checks for extra calls to methods in the query while ignoring other calls, excludes properties), but if you write your own assertion code you could probably have Received.Only(...) or similar that will let you check you got the required calls, and throw if there are extra ReceivedCalls(). (If you need it, we could look at adding a NonMatchingCalls property to IQueryResults?)

dtchepak avatar Apr 04 '19 23:04 dtchepak