No Clean Feed - Stop Internet Censorship in Australia

Nigel Thorne's software development blog, focusing on finding simple solutions to real work problems.

Sunday, June 01, 2008

Mocking templated methods with NMock2

Mocking a method like T GetSomething();

This is something that I have resorted to RinoMock to achieve in the past...
... well it turns out you can do it with NMock2 v1.0 as follows:

Expect.Once.On(a).Method("GetSomething", typeof(int)).Will(Return.Value(42));

I've tried to find this before.. and failed.. so I thought I should blog it to make it easier to find in google.

Thanks to ursenzler for commenting on http://www.fluidscape.co.nz/?q=node/82#comment-1692

2 comments:

Nigel said...

I may have prematurly posted. I can't find a set of assemblies for NMock2 where this syntax works.

Anyone found one?

Urs Enzler - NMock2 dev team said...

You can get a version containing the support for generics from http://sourceforge.net/projects/nmock2/

I suggest that you get the latest version directly from the svn repository because the downloadable release is quite old.

Or send me an email to ursenzler(at)users.sourceforge.net and I'll send you the binaries.

Happy mocking

Search This Blog

Loading...

Blog Archive

About Me

My Photo
Nigel Thorne
I'm an agile developer with a focus in finding the simple solution that will scale.
View my complete profile

GitHub Projects