Using Rhino Mocks to mock a void function

In some of my web applications I use Rhino Mocks to create mock objects. Usually the code has a record section where the expected calls are recorded, and a playback section where the testing is done. In the following code snippet the DoSomething() function calls a void function which is defined in the interface of _myMock. The problem is this void function is not expected and the NUnit test run will fail:

When trying to create an expectation for this void function Visual Studio will give a syntax error:

On the internet I found two solutions to fix this problem. The first solution uses a delegate:

The second solution uses a lambda:

Now the test will succeed.

3 thoughts on “Using Rhino Mocks to mock a void function

Leave a Reply

Your email address will not be published. Required fields are marked *