chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hi,

you propose that for returning ref and out parameters I can use DynamicReturnValues. The delegate is defined returning an object:
public delegate object DynamicReturnValue(
   object[] parameters,
   object context
);


What about void methods with ref and out parameters. How do I handle these? Any example?
Thanks in advance!

Michael
asked by mknaup (8.5k points)

1 Answer

0 votes
Hi Michael

you propose that for returning ref and out parameters I can use DynamicReturnValues.
What about void methods with ref and out parameters. How do I handle these? Any example?


There are two ways to mock ref and out arguments.

1. Use the Assign class as follows:
mock.ExpectCall("DoSomething").Args(new Assign("New String").AndCheck("TypeMock"));

Here we are both checking the the first argument is "TypeMock" and we will change it to "New String".

2. Use the DynamicReturnValues (it can be used for void methods too)
mock.ExpectAndReturn("DoSomething",new  DymanicReturnValue(Method));

In the Method we can perform our checks and change ref and out values.
answered by richard (3.9k points)
...