Rhino Mocks 2.9.5: Extending Rhino Mocks...
After getting a request for implementing a feature that I don't want to have in Rhino Mocks (very narrow scenario, very confusing semantics), I decided to follow my own advice and open up the API.
In this case, it involved making MockRepository.CreateMockObject() and the MockRepository.CreateMockState delegate protected. Now, users of the library can extend it with their own recorders and replayers.
Of course, using this require a bit of understanding of how Rhino Mocks Internals work. Basically, when Rhino Mocks is returning a type, its state is set to RecordMockState. This means that any call to the mock object will be recorded for later time. When Replay or ReplayAll are called, the mock state is queried for its next state.
This architecture allows plugging in additional mock state, and cutomize behaviors as much as you wish. This was what enabled me to add dynamic mocks, and later on delegate mocks and partial mocks. Now this is opened for you, to do as you please. In 95% of the cases, I don't think that you will need this, but it is good to have for the 5% chance.
You can see an example of this extensability here.
I also fixed BackToRecordAll(), making sure that it would erase all state from the mocked object, including when it is on the recording phase.
A more radical change is that now Rhino Mocks will now throw when you try to verify whose expectations failed at some point. This is done to aid valid mocking when the code under test need to handle all exception cases, and so catch the ExpectationViolationException. I lost the mail that request this feature, so I am using this as a way to inform whom ever it was :-)
As usual, code and source are here.
Happy Mocking...
Comments
Comment preview