I thought I would share a little nugget of greatness with RhinoMocks.
Today I was in the process of mocking out a webservice call for an application I was working on. But the method I wanted to mock took a out parameter in its signature. Normally this is not an issue, but since this out parameter result was used in my code, I needed to setup an expectation on that value.
Fortunately for us, Rhino handles this pretty easily. In order to set expectations on an Our or Ref all I need to do is add a call to the OutRef() method on my Expect call.
Here is an example of this:
using ( mocker.Record() )
{
Expect.Call( mockAPI.Create( out emptyString, out emptyString ) ).IgnoreArguments().OutRef( "", "OK" ).Repeat.Once().Return( results );
}
If you notice when I call OutRef, I am providing 2 values. The first is an empty string because I do not care about that value and the second is "OK". The "OK" value is the value that I cared about.
The OutRef method takes in one parameter, a Parameter Array. In order to use this all you need to do is pass in a value for each out/ref argument in there ordinal positions.
Hope this helps someone.
Till next time,
Posted
04-16-2008 1:25 PM
by
Derik Whittaker