How to check if any interaction with the fake has happened?

Skip to first unread message

Martin From

Jun 21, 2018, 7:23:29 PM6/21/18
to NSubstitute

How do I check if any interaction with the fake has happened?

Bascially I want to test that no call has been made to the fake without declaring every single method and also having to remember to update every single test if a new method is added etc.

Bascially something like : fake.DidNotRecieveAnyCall() 

In case there is no such functionality, the reason why I am looking for such functionality is that I want to test and make sure that during construction of object A that takes interface B, I want to make sure A never interacts with B as this could be costly performance wise and the construction of A should be cheap/fast.

/ Martin

PS. Just getting started with NSubstitute, but it seems great so far. I like the setup much better than MOQ.

David Tchepak

Jun 21, 2018, 7:39:49 PM6/21/18
Hi Martin,

Glad you're enjoying NSub! We're spoiled for choice with great mocking libs in .NET: Moq, FakeItEasy, NSub (imo ;)) etc. Something to fit every taste! :)

I think the `ReceivedCalls()` extension [1] will help you with this. `sub.ReceivedCalls()` will return an enumerable of all calls made to the sub, so you can assert that it is empty (or do other queries if you want to be more selective, although the standard API should be preferred for those cases).

Hope this helps.

You received this message because you are subscribed to the Google Groups "NSubstitute" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

Martin From

Jun 21, 2018, 8:25:02 PM6/21/18
to NSubstitute
Hi David,

Thanks for the quick reply.
RecievedCalls().Any() works perfectly :)

(don't know why I didn't notice it when looking through the Api)

/ Martin
Reply all
Reply to author
0 new messages