Mocking multiple interfaces using Rhino Mocks
A while back on StackOverflow I asked a question on how to create a mock object with Rhino Mocks that implements multiple interfaces. In other words, I want to generate a mock that implements more than one interface. This baffled me for a while and I was shown the light by one of my colleagues.
A multi-mock is created like so:
var mocker = new MockRepository(); var mock = mocker.CreateMultiMock<IPrimaryInterface>(typeof(IFoo), typeof(IBar)); mock.Expect(x => x.AnswerToUniverse()).Return(42); mocker.ReplayAll();
Note the call to ReplayAll. Without this call the mock will not be setup with the intended values.

leave a comment