by jfisch
15. May 2009 09:43
I'm just ramping up on Rhino Mocks and I've begun beating my head against what appears to be a common issue experienced by fellow Rhinoers. Some test-driven developers have had the misfortune of having the disease go "south" into their testees. To avoid this painful symptom I've decided to put together an attempt at a comprehensive list of When Rhino Attacks - This action is invalid when the mock object is in verified state.
From my reading, the problem seems to stem from various sources of Dispose being called on your mock object after your object has already been verified. Although, I'm new enough to Rhino Mocks that I have to be honset and I'm not completeyl sure how this manifests and how the Rhino Mocks model runs into this issue. However, there seems to be a number of common solutions to this problem which should be of asisstance.
Ydie's IDisposable solution seems to work for cases where you feel the need to dispose of your mock object explicitly.
Xerxes ExternalDataComponent solution seems to work for cases where you need to utilize ExternalDataComponent.
However, in my case it was caused by a necessary database object instance being used within a Visual Studio codegen class. The test was trying to use a previous static containing a database object that had affectively "expired".
In case you had the neat idea of just adding this exception to the expected exceptions for your test, please rethink your solution.
Ciao!
Jeff Fischer