Returning value that was passed into a method

后端 未结 3 912
闹比i
闹比i 2020-12-07 08:36

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

3条回答
  •  -上瘾入骨i
    2020-12-07 09:04

    The generic Returns method can handle this situation nicely.

    _mock.Setup(x => x.DoSomething(It.IsAny())).Returns(x => x);
    

    Or if the method requires multiple inputs, specify them like so:

    _mock.Setup(x => x.DoSomething(It.IsAny(), It.IsAny())).Returns((string x, int y) => x);
    

提交回复
热议问题