NSubstitute icon indicating copy to clipboard operation
NSubstitute copied to clipboard

How to tell if a method/property has been substituted/configured?

Open Metritutus opened this issue 5 months ago • 0 comments

Question If you create a Substitute for a type via Substitute.For<MyType>(), you can detect if the instance is a substitute by checking if myInstance is ICallRouterProvider (as per https://github.com/nsubstitute/NSubstitute/issues/659).

However, what I have been unable to figure out is how to tell whether a method/property has been configured (ie via Returns(), Do(), etc). With Moq you could do this via searching the Setups collection, but there does not seem to be any equivalent here.

If there's no public API available to access this information, I don't mind having to utilise reflection to achieve this, however I'm not very familiar with NSubstitute, and my initial investigative efforts have only led me so far (ie that I may potentially be looking to try and access CallActions from somewhere, however I could be mistaken).

Metritutus avatar Aug 30 '24 16:08 Metritutus