tags:

views:

210

answers:

3

I have a method on an interface:

string DoSomething(string whatever);

I want to mock this with MOQ, so that it returns whatever was passed in - something like:

_mock.Setup( theObject => theObject.DoSomething( It.IsAny<string>( ) ) )
   .Returns( [the parameter that was passed] ) ;

Any ideas?

+1  A: 

You can use a lambda with an input parameter, like so:

.Returns((string myval) => { return myval; });
mhamrah
+3  A: 

You should be able to do something similar to this

BenA
A: 

You can do this:

string parameter;
_mock.Setup( theObject => theObject.DoSomething( parameter ) ).Returns(parameter);
Praveen Angyan