Returning value that was passed into a method

后端 未结 3 922
闹比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条回答
  •  盖世英雄少女心
    2020-12-07 09:13

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

    .Returns((string myval) => { return myval; });
    

    Or slightly more readable:

    .Returns(x => x);
    

提交回复
热议问题