Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
448 views
in Technique[技术] by (71.8m points)

c# - What is the NSubstitute equivalent of the Moq VerifyNoOtherCalls() method

I'm currently a heavy Moq user and I'm researching other mocking frameworks.

I'm looking on NSubstitute and like their syntax and the ease of creating test spies.

The only feature i's missing in NSubstitute is VerifyNoOtherCalls. It is very handy because it lets me to quickly explore existing calls for all method's methods and decide if they are legitimate or not. This is especially helpful when I have to cover legacy code which has no tests at all or covered partially.

I've searched the NSubstitute docs and cannot find the equivalent option in their framework. Can anyone suggest how I might do this?

question from:https://stackoverflow.com/questions/65844078/what-is-the-nsubstitute-equivalent-of-the-moq-verifynoothercalls-method

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is no equivalent for this in NSubstitute. It is possible to implement something similar using the ReceivedCalls() extension method, which will return a list of all calls received. It's a bit fiddly, but possible to query this to ensure no additional calls were received.

If you don't mind checking internal details, you can check Received.InOrder for some other implementation ideas.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...