Skip to main content

Mocking out and ref parameters with Rhino Mocks

Today I learned that you can mock out and ref parameters with the following syntax in Rhino Mocks.

[TestMethod]
public void ShowHowRhinoMocksOutRefParameterWorks()
{
    /* Setup */
    var mock = MockRepository.GenerateMock<IBookRepository>();
    var bookFinder = new BookFinder(mock);

/* Arrange */
mock.Expect(rep =&gt; rep.FindByTitle(Arg&lt;string&gt;.Is.Anything, out Arg&lt;int&gt;.Out(10).Dummy))
    .Return(new List&lt;Book&gt;());

/* Act */
var count = 0;
var books = bookFinder.FindBooks(&quot;hitchhikers guide to the galaxy&quot;, out count);

/* Assert */
Assert.AreEqual(10, count);

}

comments powered by Disqus