NSubstitute icon indicating copy to clipboard operation
NSubstitute copied to clipboard

Make ReceivedWithAnyArgs ignore optional arguments?

Open rklec opened this issue 4 years ago • 1 comments

My question seems similar to https://github.com/nsubstitute/NSubstitute/issues/629, but the issue there seems to discard ReceivedWithAnyArgs, but my issue is about the fact that ReceivedWithAnyArgs does not ignore the number of arguments.

I.e. something like this (if it has optional parameters). To properly assert it, you would have to do this:

calculator.ReceivedWithAnyArgs(1).Add(default);
calculator.DidNotReceiveWithAnyArgs(1).Add(default, default);

This e.g. asserts, the .Add is only called once. If you did not add the second line, and you add a call calculator.Add(1, 2), the test would not fail, because well.. it's "just" an optional argument.

For the sake of testing, it, however, IMHO makes sense to fail here, because well... you do only expect one call to Add (with any parameters), but not two calls - no matter whether there are additional parameters.

Is there any way to make ReceivedWithAnyArgs or so more generic, so it also does not care for argument count?

rklec avatar Aug 13 '21 11:08 rklec

I'm not sure if this is possible, but if it does it would be a great enhancement

304NotModified avatar Apr 29 '24 12:04 304NotModified