Add Way to Exclude Calls from VerifyNoOtherCalls
When verifying calls on mocks, it often happens that there is some trivial operation (like a property read) that you really don't care about, and the executing code is allowed to invoke any number of times. However, because of the way VerifyNoOtherCalls works, there's no way to mark things as ignored - you have to explicitly specify each individual call, which leads to unit tests either being too tightly coupled to the main code base, or using hackish work-arounds (like doing Times.AtMost(1000)). There ought to be a way to tell Moq that such-and-such a call just isn't relevant.
As side note, the most obvious way to implement this would be to let Times.AtLeast accept a 0 value as a parameter.
Wouldn't turn your mock into a loose mock and only verify what you're interested in work better in this case?
For situations where there aren't many methods you need to verify, sure. But the use case for this is when you have a LOT of functions, and you want to verify that most of them are never touched, with the possible exception of a few accessors. In that scenario, it's much more convenient to handle everything in bulk, using VerifyNoOtherCalls.
If most should not be called, then a strict mock with no setups for them seems like a better approach?
Hmmmm. Fair point. Maybe this is more of a documentation issue then? It is not obvious that strict mocks are the way to handle this case, for someone with limited familiarity with the library.
Yeah, perhaps. I guess this is something that is typically covered by the multiple blogs/stackoverflow/online curses you can find by now on using Moq itself. But I'll keep that in mind for vNext.
Feel free to close this issue if you feel the strict mock will suffice.
Thanks!
Due to lack of recent activity, this issue has been labeled as 'stale'. It will be closed if no further activity occurs within 30 more days. Any new comment will remove the label.
This issue will now be closed since it has been labeled 'stale' without activity for 30 days.
