Can I customize a mock object to always return the object specified as a parameter? I have a method
public MyObject DoSomething(MyObject obj)
and I want to have a mock that always returns obj for every DoSomething call, sort of like:
mock.Stub(x=>x.DoSomething(Arg<MyObject>.Is.Anything).Return(Arg<MyObject>)
although I'm not sure what to put the return bit ...
EDIT: I tried this:
MyObject o=null;
mock.Stub(x=>x.DoSomething(Arg<MyObject>.Is.Anything).WhenCalled (y=>
{
o = y.Arguments[0] as MyObject;
}).Return (o);
which seemed to be promising, but no luck. Posting it in case it runs through someone's memory ...
source
share