Ability to disable saving references to arguments the mock was invoked with
At my company I'm using Mock to unit test for memory leaks.
Our UI controls typically take some interface of a model, binds to its events and then updates the UI state depending on this model. When the UI gets disposed it's crucial that it unhooks completely from the model and can be garbage collected.
I unit test this by
1. Making a mock of the model interface
2. Use the mock to create the control
3. Attach a weak reference to the control
4. Dispose the control
5. Run a garbage collection
6. Check if the weak reference is alive or not.
This works great for most of our controls. However, some of our controls call the (mocked) model with a reference to the control itself.
// In my control
Even if I call _model.SetSomeFunction(null) in the Dispose-method of the control, the garbage collector will not be able to collect it.
The problem is that the mock saves the arguments whenever it gets invoked. I can see that in mock.Interceptor.actualInvocations, there is a reference to the control's SomeFunction, which hinders garbage collection of the control.
I understand that this is a feature needed to be able to vertify that calls have been made to mocked objects. In this case however, I don't need it, and it destroys the test for some of my controls. Therefore I would much appreciate if functionality was added to
a) Disable this functionality
b) Clear the actualInvocations list.