我使用 NUnit 和 NSubstitute 进行单元测试。我有以下内容:
public interface IDataProvider
{
void Log(int tvmId, DateTime time, int source, int level, int eventCode, string message);
}
...
var fakeDataProvider = Substitute.For<IDataProvider>();
...
fakeDataProvider.Received().Log(
Arg.Any<int>(),
new DateTime(2000, 1, 1),
0,
0,
0,
null);
fakeDataProvider.Received() 抛出 AmbiguousArgumentException 并显示无法确定要使用的参数规范的消息。我在 SO 上找到了以下内容
Cannot determine argument specifications to use
这是相关的,但我不能在上面的代码中应用它。为什么上面的代码有歧义?我还能如何指定 Received() 它应该接受任何参数?
最佳答案
由于 Log
方法中有多个 int
参数,因此您必须为每个参数指定参数。
fakeDataProvider.Received().Log(
Arg.Any<int>(),
new DateTime(2000, 1, 1),
Arg.Is(0),
Arg.Is(0),
Arg.Is(0),
null);
关于c# - NSubstitute 无法确定要使用的参数规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36202435/