我正在尝试使用 Moq 来模拟界面:
public interface IMatchSetupRepository
{
IEnumerable<MatchSetup> GetAll();
}
我正在做:
var matchSetupRepository = new Mock<IMatchSetupRepository>();
matchSetupRepository
.Setup(ms => ms.GetAll())
.Returns(null);
但由于错误,它甚至无法编译:
错误CS0121:以下方法之间的调用不明确或
特性:
'Moq.Language.IReturns>.Returns(System.Collections.Generic.IEnumerable)'
和
'Moq.Language.IReturns>.Returns(System.Func> )'
我在用着:
Moq.dll,v4.0.20926
尝试通用版本Returns
:
var matchSetupRepository = new Mock<IMatchSetupRepository>();
matchSetupRepository
.Setup(ms => ms.GetAll())
.Returns<IEnumerable<MatchSetup>>(null);
or:
var matchSetupRepository = new Mock<IMatchSetupRepository>();
matchSetupRepository
.Setup(ms => ms.GetAll())
.Returns((IEnumerable<MatchSetup>)null);
反而。因为您要传递函数 null (并且有两个重载Returns
),编译器不知道您指的是哪个重载,除非您将参数转换为正确的类型。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)