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

Categories

Using NSubstitute. For some tests I want to assert that a Substitute has received no calls whatsoever. I could use DidNotReceiveWithAnyArgs() for every method in the interface, but that is tedious and not as robust (if a new method is added to the interface, a developer could easily overlook adding that to the test).

I'm looking for something functionally similar to Moq's VerifyNoOtherCalls() being called without any other Verify checks.

question from:https://stackoverflow.com/questions/65940440/how-to-verify-that-a-substitute-received-no-calls-at-all

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

1 Answer

The extension method ReceivedCalls(), which returns all calls that were received by the substitute, can be used to test that no calls were received.

For example (using FluentAssertions):

mySubstitute.ReceivedCalls().Should().BeEmpty();

Or using MSTest assertions:

Assert.IsFalse(mySubstitute.ReceivedCalls().Any());

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...