Rhino Mocks: How do I know if an object or reality is mocking?

Given an o object, how can I determine if it is a mocked or real object?

The only way I can do this looks a bit hacky:

 public bool IsMockedObject(object o) { try { o.GetMockRepository(); return true; } catch(InvalidOperationException) { return false; } } 

Please tell me the best way!

+7
source share
1 answer

You can check if the IMockedObject object IMockedObject :

 bool isMocked = o is Rhino.Mocks.Interfaces.IMockedObject; 

This, of course, will require a reference to the RhinoMocks assembly, which I will try to avoid for your production code.

+12
source

All Articles