Derik Whittaker



Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at
Rhino Mocks and mocking Out/Ref params

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
Filed under: ,



Reflective Perspective - Chris Alcock » The Morning Brew #75 wrote Reflective Perspective - Chris Alcock » The Morning Brew #75
on 04-17-2008 3:30 AM

Pingback from  Reflective Perspective - Chris Alcock  » The Morning Brew #75

James Shumaker wrote re: Rhino Mocks and mocking Out/Ref params
on 07-03-2008 9:27 AM


Thank you for taking the time to post this, it was exactly what I needed.


Out parameters in Rhino Mocks « Of Code and Me wrote Out parameters in Rhino Mocks « Of Code and Me
on 03-24-2009 9:24 AM

Pingback from  Out parameters in Rhino Mocks « Of Code and Me

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)