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
395 views
in Technique[技术] by (71.8m points)

nsubstitute - How to verify that a substitute received no calls at all?

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

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

1 Answer

0 votes
by (71.8m points)

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());

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

...