Rhino Mocks 2.5.5: Mocking Delegates

time to read 2 min | 380 words

A brand new release of Rhino Mocks, with a twist.

Jeff emailed me a patch yesterday, that enabled the mocking of delegates. This is not something that I would've ever considered, to tell you the truth, but the idea (and the code) were sound, and I can certainly see uses for this. Consider all the possibilities for near-functional programming that .Net 2.0 opens for us, and you'll see what I'm excited about.

Here is an example of using this new functionality:

[Test]
public void GenericDelegate()
{
  Action<int> action = mocks.CreateMock<Action<int>>();
  for (int i = 0; i < 10; i++)
  {
    action(i);
  }
  mocks.ReplayAll();
  ForEachFromZeroToNine(action);
  mocks.VerifyAll();
}
private void ForEachFromZeroToNine(Action<int> act)
{
  for (int i = 0; i < 10; i++)
  {
    act(i);
  }
}

The other big change is removing IDisposable from the MockRepository. This is a breaking change for somet people, but it is a must. The problem is that the #1 problem that we have with new users of Rhino Mocks is exceptions masking. Removing the IDisposable means that it takes a bit longer to setup the mock repository, but I hope it will also encourage the recommended use of putting the setup & verification in the [SetUp] and [TearDown] methods.

Another change that I made was a bug fix for SetupResult not respecting IgnoreParameters(), which drove me crazy for a while. I’ve updated the documentation and the API docs to reflect the changes . As usualy, you can download or get the source.