One of my favorite things about being a blog owner and operator is when I’m looking for something and find that I’ve already answered my own question. This just happened to me as I was trying to re-figure out how to use output parameters with argument constraints with Rhino Mocks.
I found an article on this very topic written by me (thanks, self!), but as I was reading I noticed that I left something important out. So here’s a quick, mini do-over!
Let’s say we need to stub function Bar as it’s defined in the following interface:
public interface IFoo { bool Bar(out string outty); }
To use an argument constraint with the output argument, I need to do two things. First, I need to use Arg<T>.Out. The second thing–the thing that I failed to mention in my previous post–is that I need to use the Dummy property to make it compile.
Here’s what an example might look like. I stubbed the Bar function to return true and assign the value fake value! to the output argument.
IFoo mockFoo = MockRepository.GenerateMock<IFoo>(); mockFoo(x => x.Bar(out Arg<string>.Out("fake value!").Dummy)).Return(true);
Not too shabby!