While Rhino Mocks is compatible with the .Net framework 1.1, it offer several goodies for those who use the 2.0 version of the .Net framework. Among them are mocking generic interfaces and classes, and using generic version of the methods in order to reduce casting.
Here is Rhino Mocks mocking a generic interface:
[Test]
public void MockAGenericInterface()
{
MockRepository mocks = new MockRepository();
IList<int> list = mocks.CreateMock<IList<int>>();
Assert.IsNotNull(list);
Expect.Call(list.Count).Return(5);
mocks.ReplayAll();
Assert.AreEqual(5, list.Count);
mocks.VerifyAll();
}
And here is how to use the generic methods to create mocks:
IDemo demo = (IDemo) mocks.CreateMock(typeof(IDemo));
IDemo demo = (IDemo) mocks.DynamicMock(typeof(IDemo));
IDemo demo = mocks.CreateMock<IDemo>();
IDemo demo = mocks.DynamicMock<IDemo>()
Up:
Rhino Mocks Documentation
Next:
Rhino Mocks Partial Mocks