I'm mocking a class that has a destrcutor. During some of the test I do not expect my tested code to dispose of the mocked object, and therefore I do not expect the destructor to be called. However, when the object is mocked, TypeMock creates a real .NET instance of the object, which is automatically disposed by the GC after the object gets out of scope.
A call to GC.SuppressFinalize on the object may help, but I was able to do it only when using reflective mocks. With reflective mocks it's very simple: I call GC.SuppressFinalize on the mocked instance that I can get from the MockedInstance property of my mock object.
When using natural mocks, it seems that I do not have access to that instance. I tried calling GC.SuppressFinalize on all the instances received when calling MockManager.GetMockes<MyMockedType>(), but it did not help.
Is there a way to do it, or do I have to give up natural mocks when mocking objects with destructors?