Rhino Mocks 2.8 Released – Multi Mocks

time to read 3 min | 457 words

I said it before, but I just have to say it again. It is a big mistake to release software. Any time that I do it, I need to make a new release soon after. (And no, not a bug fix release {usually} ).

Yet I did make the mistake of releasing the most dangerous software of them all, Rhino Mocks. The moment I do something to this beast, a new feature request come up. The problem is that I’m a sucker for frequent releases, I just can’t help implement features and ship them.

This release brings one major feature to the table, Multi Mocks. What is a Multi Mock?

A Multi Mock is a mock object that implements several interfaces. For instance, you may want to test this code:

public void CleanCollection(CollectionBase collection)



IDisposable disposable = collection as IDisposable;





As you can see, we accept a collection, and we make sure to dispose of it if it is disposable. CollectionBase does not implements IDisposable, so this would usually force us to create a dummy class to make the MockRepository think that we need all those interfaces.

Instead, we can now do this:


public void ClearCollectionAndDisposesIt()


MockRepository mocks = new MockRepository();

CollectionBase collection = (CollectionBase)mocks.CreateMultiMock(        typeof (CollectionBase), typeof (IDisposable));









There is also a DynamicMultiMock, with the same behavior. The functionality exists with generic overloads for 2.0, of course. Oh, I also added AtLeastOnce to the default options for repeating. I was asked to do this a long time ago, and I just forgot.

You can read the feature request here. This is also very useful in Remoting scenarios.

By my calculations, it is less than 6 hours from the feature request to shipping a well tested version out the door. Take that, Test Driven Development naysayers! As usual, you can get both binaries and source here.

Thanks against for Royston Shufflebotham for presenting such a clear need.