Given an object o
, how can I tell if it's a mocked or a real object?
The only way I can see doing this looks a bit hacky:
public bool IsMockedObject(object o)
{
try
{
o.GetMockRepository();
return true;
}
catch(InvalidOperationException)
{
return false;
}
}
Please tell me there's a better way!
You can check if the object implements IMockedObject
:
bool isMocked = o is Rhino.Mocks.Interfaces.IMockedObject;
This of course would require referencing the RhinoMocks assembly, which I would try to avoid for your production code.