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.

Bookmark and Share Thursday, March 15, 2007 8:09:03 PM (Jerusalem Standard Time, UTC+02:00)  #    Comments [4]  
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.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):