Thursday, March 15, 2007
« SSL in ASP.NET - Part II | Main | NMock Trick II - Mocking Indexers »

If you are using the NMock mock objects framework, you are probably familiar with the following syntax:

Stub.On(...).Method(...).Will(Return.Value(...));

This will cause your mock object to return a specific value from some invoked method.

Now, for something less not documented:

To mock a method that sets value of an out parameter, use:

Stub.On(...).Method(...).Will(new SetNamedParameterAction([parameter name], [value]));

You can also use the SetIndexedParameterAction class.

This is not in the documentation, so using Reflector on the NMock2.dll helped find this.

Want to join me as partner in a cool new startup?
Get in touch: pasha at cohai dot co

Bookmark and Share Thursday, March 15, 2007 8:09:03 PM (Jerusalem Standard Time, UTC+02:00)  #    Comments [8]  
Thursday, October 04, 2007 4:31:57 PM (Jerusalem Daylight Time, UTC+03:00)
Hi,

Can you give an example on how to implement this.
Been trying to do this one but I always got an error.

Thanks in advance.
Dax
Wednesday, June 04, 2008 7:19:09 PM (Jerusalem Daylight Time, UTC+03:00)
Thanks alot. This is just what I needed.
Mike
Sunday, June 22, 2008 2:15:26 AM (Jerusalem Daylight Time, UTC+03:00)
With NMock2 V1.0 at http://sourceforge.net/projects/nmock2 this gets even easier:

Stub.On(...).Method(...).Will(Return.OutValue([parameter name], [value]));

Happy mocking
Urs
Thursday, May 28, 2009 6:52:15 AM (Jerusalem Daylight Time, UTC+03:00)
Hi guys. He had learned over the years that poor people did not feel so poor when allowed to give occasionally. Help me! Need information about: Turbo Tax. I found only this - <a href="http://turbo-tax.biz">turbo tax</a>. These people. Have been told that there is. Many of the top alcohol treatment programs include a variety of. With best wishes :o, Venus from Poland.
Saturday, April 16, 2011 6:45:16 PM (Jerusalem Daylight Time, UTC+03:00)
Thanks alot - your answer solved all my problems after several days struggilng
Saturday, April 23, 2011 8:39:00 PM (Jerusalem Daylight Time, UTC+03:00)
Bph65t <a href="http://jstfbiyzltfc.com/">jstfbiyzltfc</a>
Monday, April 25, 2011 12:16:34 AM (Jerusalem Daylight Time, UTC+03:00)
Ld7Sdt , [url=http://wngzkucgkixl.com/]wngzkucgkixl[/url], [link=http://hvgrggjgspas.com/]hvgrggjgspas[/link], http://ilnhvljrgszd.com/
Wednesday, August 17, 2011 7:20:00 PM (Jerusalem Daylight Time, UTC+03:00)
Every body remembers that modern life seems to be not cheap, however different people require cash for various issues and not every man earns big sums cash. Thence to receive quick loans and commercial loan would be a correct way out.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):