We are using Rhino Mocks to perform some unit testing and need to mock two interfaces. Only one interface is implemented on the object and the other is implemented dynamically using an aspect-oriented approach. Is there an easy way to combine the two interfaces dynamically so that a mock can be created and the methods stubbed for both interfaces?
+2
A:
It's not dynamic, but certainly easy: create an interface within your testing assembly which does nothing other than implementing the other two interfaces:
internal interface ICombined : IFirstInterface, ISecondInterface {}
Then mock ICombined
.
jalbert
2009-01-29 14:50:29
A:
A mock with multiple interfaces using Rhino Mocks can be generated like so:
var mocker = new MockRepository();
var mock = mocker.CreateMultiMock<IPrimaryInterface>(typeof(IFoo), typeof(IBar));
mocker.ReplayAll();
sduplooy
2010-06-04 12:58:08