Search code examples
c#rhino-mocks

How to use the Arg<> matcher from the Stub() in the Return()?


Here's what i'd like to do :

_service.Stub(s => s.Method(Arg<Dto>.Is.Anything)).Return(new OtherDto { Parent = #My Arg# });

How can i replace #My Arg# with the Arg ? If it is even possible ?

Thanks


Solution

  • Func<Dto, OtherDto> returnOtherDto = dto => new OtherDto { Parent = dto };
    _service
        .Stub(s => s.Method(Arg<Dto>.Is.Anything))
        .Do(returnOtherDto);