Ayende @ Rahien

Unnatural acts on source code

Rhino Mocks: Extending the Mockable

Well, thanks to Ivan Krivyakov, who did most of the work, this is now possible:

[Test]
public void CanMockAppDomain()
{
	MockRepository mocks = new MockRepository();
	AppDomain appDomain = mocks.RemotingMock<AppDomain>();
	Expect.Call(appDomain.BaseDirectory).Return("/home/user/ayende");
	mocks.ReplayAll();
	Assert.AreEqual(appDomain.BaseDirectory, "/home/user/ayende" );
	mocks.VerifyAll();
}

As you can guess, this means that Rhino Mocks now also integrate with the Remoting infrastructure of the CLR. There are are quite a few types that inherit from MarshalByRefObject, and all of those are now mockable by Rhino Mocks.

I tried to compile a list of stuff that people wanted to mock but where unable to before, but the only thing that comes to mind is: System.Drawing.Graphics

The main benefit is if you want to mock WinForms stuff, since all of those inherit from MarshalByRefObject. Another interesting new mockable is System.IO.FileSystemWatcher.

The change is on the repository, but I am not making a release yet, I want to do some more testing first.

Comments

Gian Maria
10/16/2007 08:22 AM by
Gian Maria

Ayende, you really rock :D. I must admit that I really love Rhino Mocks.

Alk.

Jeff Brown
10/16/2007 09:51 PM by
Jeff Brown

Nifty both dynamic mocks and transparent proxies behind the same interface! We could do ContextBoundObject too, I guess. There aren't all that many of those though.

ulu
10/26/2007 06:54 PM by
ulu

Wait, isn't the Graphics class sealed?

Ayende Rahien
10/26/2007 07:13 PM by
Ayende Rahien

Ulu,

Yes, it is.

It is still mockable now, cool, eh?

ulu
10/26/2007 08:07 PM by
ulu

It's so cool it looks like black magic. I mean, I can imagine how you could theoretically mock virtual methods, but this..

Anyway, this is sort of moving the same direction as TypeMock.. which is considered bad for some folks..

Not for me though, I still insist that too many possibilities can't be bad, at least for an experienced developer. So, big big thanks Ayende and Ivan for this!

Comments have been closed on this topic.