Total Pageviews

Thursday, October 11, 2012

Rhino Mocks and mocking Out/Ref params


Today I was in the process of mocking out a service 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.

_findTask.Stub(
  a => a.TryFind(somePoint, out coordinates, out coordinatesSuggestions))
.Return(results)
.OutRef(coordinates = new List(), 
       coordinatesSuggestions  new List());

No comments:

Post a Comment