Mocking void method with Rhino mocks
Only a handful of people use unit test extensively. Out of those people only a handful believes in using Mocking framework. It's a debatable issue to use mocking framework in a unit test, which I'll not touch in this post. For those of you who just started in the software development field, I highly suggest to look into mocking framework in general especially when you're interested in doing Test Driven Development.
One thing that I haven't discovered until now is how to mock void methods with Rhino mocks. Putting something like
simply will not work as the expect.call expect a non void method. Ayende have a post that addresses this same issue here: Using Expect.Call(void method).
For me, I like using lambda expression the best. I think it's the cleanest/most readable technique:
Expect.Call( () => mock.someVoidMethodWithAParameter(someParamValue));
For methods that doesn't have any parameters, the following is acceptable:
Notice that there isn't an empty bracket in the end. It's simply the method name.
Rhino Mocks 126.96.36.1997
Resharper unit test runner