Rhino Mocks 3.0 Beta: Almost Ready

time to read 23 min | 4531 words

I just got a bing sound from the computer, telling me that an important message has arrived:

------ Test started: Assembly: Rhino.Mocks.Tests.dll ------

486 passed, 0 failed, 0 skipped, took 6.56 seconds.

Yup, that is correct. All, but all, of Rhino Mocks tests are currently passing. What is so suprising about Rhino Mocks passing all its tests? The surprising part is that now it is running on Dynamic Proxy 2, which means that there is support for mocking Generic Methods! This has long been Rhino Mock's weakest point, and it is now working!

Check out the syntax:

[Test]

public void CanCreateMockOfInterfaceWithGenericMethod()

{

       MockRepository mocks = new MockRepository();

       mocks.CreateMock<IFactory>();

}

 

[Test]

public void CanSetExpectationsOnInterfaceWithGenericMethod()

{

       MockRepository mocks = new MockRepository();

       IFactory factory = mocks.CreateMock<IFactory>();

       Expect.Call(factory.Create<string>()).Return("working?");

       mocks.ReplayAll();

       string result = factory.Create<string>();

       Assert.AreEqual("working?",result, "Should have worked, hm..." );

       mocks.VerifyAll();

}

 

[Test]

[ExpectedException(typeof(ExpectationViolationException),@"IFactory.Create<System.Int32>(); Expected #1, Actual #1.

IFactory.Create<System.String>(); Expected #1, Actual #0." )]

public void WillGetErrorIfCallingMethodWithDifferentGenericArgument()

{

       MockRepository mocks = new MockRepository();

       IFactory factory = mocks.CreateMock<IFactory>();

       Expect.Call(factory.Create<string>()).Return("working?");

       mocks.ReplayAll();

       factory.Create<int>();

}

 

 

[Test]

[ExpectedException(typeof(InvalidOperationException),"Type 'System.Int32' doesn't match the return type 'System.String' for method 'IFactory.Create<System.String>();'")]

public void WillGiveErrorIfThereIsTypeMismatchInGenericParameters()

{

       MockRepository mocks = new MockRepository();

       IFactory factory = mocks.CreateMock<IFactory>();

       Expect.Call(factory.Create<string>()).Return(1);

}

 

[Test]

[ExpectedException(typeof(ExpectationViolationException), "IFactory.Create<System.String>(); Expected #1, Actual #0.")]

public void WillGiveErrorIfMissingCallToGenericMethod()

{

       MockRepository mocks = new MockRepository();

       IFactory factory = mocks.CreateMock<IFactory>();

       Expect.Call(factory.Create<string>()).Return("working?");

       mocks.ReplayAll();

       mocks.VerifyAll();

}

What remains to do is to run some more tests (feel free to suggest some), implement some more accumolated bug fixes / feature requests that I have gathered, and release!

The last release was about three months ago, which is probably the longest time that Rhino Mocks had without a release. I am a bit afraid of release it, to tell the truth, every time that I do, I end up release another version shortly, with additional features/bug fixes. The problem is that the algorithm is recursive... :-)