Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RhinoMocks - Fetching parameters of called functions

Using RhinoMocks - can I fetch the parameters of a called function? I mean; can I get some of the unknown parameters from the function call out?

I have a mock, and I expect some function to be called on this. I know one of the parameters, but the other one is unknown as this comes from the class that uses the mock and calls a function on it. More specificly - in this case - the unknown argument is a lambda function. This is a callback function that is supposed to be called when the function is finished executing. As the mock prevents the callback from being called I want to fetch it and call it myself.

So; I want to check that the function was called. I want to make sure some of the arguments were the expected ones. And I want to get out the unknown arguments to do some operations on them afterwards.

Assuming both arguments are ints (for simplicity) I'd like to do something like this:

int unknownInt; 
_fakeSomething.AssertWasCalled(factory => factory.Foo(1, out unknownInt));
// then play around with unknownInt.. 

Can this be done? I see there is an Arg.Out, but couldn't quite make it work..

Note: Updated the question as it seemed to be misleading.

like image 487
stiank81 Avatar asked Jan 13 '10 12:01

stiank81


1 Answers

Arg<string>.Matches(arg => you got the argument here...);

UPDATE:

To fetch the second argument made on the first call of the Foo method on _fakeSomething:

string someArg = null;
var args = _fakeSomething.GetArgumentsForCallsMadeOn(
    x => x.Foo(0, 0), 
    x => x.IgnoreArguments()
);
var int = (int)args[0][1];
like image 71
Darin Dimitrov Avatar answered Oct 07 '22 06:10

Darin Dimitrov