【发布时间】:2018-04-05 10:20:54
【问题描述】:
我收到以下错误:
NSubstitute.Exceptions.UnexpectedArgumentMatcherException: '参数 matchers (Arg.Is, Arg.Any) 只能用来代替 member 论据。不要在 Returns() 语句或其他任何地方使用 在成员调用之外。正确使用:
sub.MyMethod(Arg.Any()).Returns("hi") 使用不正确:
sub.MyMethod("hi").Returns(Arg.Any())'
当试图模拟出以下界面时:
public interface IMyDate
{
DateTime GetDate();
}
这是我嘲笑它的地方:
var myDate = Substitute.For<IMyDate>();
myDate.GetDate().Returns(testDate); // Error thrown here
请任何人解释我做错了什么?
var myDate = Substitute.For<IMyDate>();
myDate.GetDate().Returns(new DateTime(2018, 04, 05)); // Error thrown here
给出相同的结果。
【问题讨论】:
标签: c# mocking nsubstitute