Rhino.Mocks - StrictMock vs. MockRepository.GenerateStrictMock
Recently, I had to use the MultiMock functionality of Rhino.Mocks, which is regrettably not exposed through the static MockRepository
helper functions. I ended up having to do it by hand by calling StrictMultiMock
on a MockRepository
instance. However, I found that calling the Stubbed property on my strict mock returned the error “requires a return value or an exception to throw” after interacting with that property.
After looking into the Rhino.Mocks source on GitHub, I found that the static helper functions in MockRepository
invoked MockRepository.Replay
on the freshly created mock before returning it. Presumably, just calling StrictMock
or StrictMultiMock
did not advance the mock to ‘replay’ mode, and it would not return anything when interrogated.
Changing my mock setup code to the following allowed it to function as I expected.
Hopefully this helps someone else who runs into the same issue. This was tested on the 3.6.1 package available from NuGet.