NSubstitute
NSubstitute copied to clipboard
Make ReceivedWithAnyArgs ignore optional arguments?
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?
I'm not sure if this is possible, but if it does it would be a great enhancement