Rhino Mocks 2.8.5 – Declarative Out / Ref

time to read 2 min | 236 words

Here is the story, Rhino Mocks supports out/ref parameters, and you can change their values by passing a delegate with the appropriate signature. The problem is that this is a lot of code to write if you just want to setup the output / ref parameters to a certain value. This is especially true if you are working in VB or C# 1.1, where anonymous method do not exists.

I added a new way to specify the values of output and reference parameters, like this:

myClass.MyMethod(out i, ref s, 1, out s2);

LastCall.IgnoreArguments().OutRef(100, "s", "b");

 

A couple of notes about the implementation, the OutRef method accept an (params) array of values, which is based on zero indexing of the parameters disregarding any non out/ref parameters. In the example above, we setup i to 100, s to “s” and s2 to “b”.

As usual, you can find the sources and binaries here.

The really fun part about this feature is that the time it took to implement it, I got up, check my mail, saw the request, implemented it (20 minutes including testing and deploying) and now I am going out to work. I just love working with Rhino Mocks code.