Is there a way to set strict mode?

725 views
Skip to first unread message

Jon Gyllenswärd

unread,
Aug 31, 2011, 8:36:21 AM8/31/11
to nsubs...@googlegroups.com
Hi

I want my subsitutes to fail when I call a method without any mocked implementation.
I know this is how Moq works if I use var mock = new Mock<IFoo>(MockBehavior.Strict);

Is there a way to achieve this with NSubstitute?

/Jon

David Tchepak

unread,
Aug 31, 2011, 9:22:09 AM8/31/11
to nsubs...@googlegroups.com
Hi Jon,

Sorry, NSubstitute does not support this.

As a fairly clumsy workaround you could strictly check calls after the fact using sub.ReceivedCalls(), which will return all the calls the substitute received. You could query this enumerable and make sure it only contains the calls you expect. For example, to check a substitute was not called at all you can do Assert.AreEqual(sub.ReceivedCalls().Count(), 0);

Not exactly what you are after I know, but it's the closest I can think of, short of explicitly making other calls throw (from WhenForAnyArgs(...).Do(...) or ReturnsForAnyArgs(...)).

Regards,
David

--
You received this message because you are subscribed to the Google Groups "NSubstitute" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nsubstitute/-/IyyZHrCp0CgJ.
To post to this group, send email to nsubs...@googlegroups.com.
To unsubscribe from this group, send email to nsubstitute...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nsubstitute?hl=en.

Jon Gyllenswärd

unread,
Sep 1, 2011, 2:51:00 AM9/1/11
to nsubs...@googlegroups.com
Ok

Thanks for the suggestions.

/ Jon
Reply all
Reply to author
Forward
0 new messages