最小起订量:返回被传递给方法的价值 [英] MOQ: Returning value that was passed into a method
本文介绍了最小起订量:返回被传递给方法的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个接口上的一个方法:
I have a method on an interface:
string DoSomething(string whatever);
我想与MOQ嘲笑这一点,所以它返回无论是在传递 - 是这样的:
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?
推荐答案
您可以使用lambda与输入参数,像这样:
You can use a lambda with an input parameter, like so:
.Returns((string myval) => { return myval; });
或稍微更具可读性:
.Returns<string>(x => x);
这篇关于最小起订量:返回被传递给方法的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文