【发布时间】:2018-11-02 20:50:51
【问题描述】:
我有一个测试方法:
public class MyTests
{
[Fact]
public void Test_Method()
{
// Arrange
var returns = Result.Ok(new List<string>() { "Test" }.AsEnumerable());
this.mockService.ServiceMethod(Arg.Any<Guid>()).Returns(returns); //returns Result<IEnumerable<string>>
//Act
var actResult = this.anotherService.Backup();
//Assert
Assert.True(actResult.Success);
}
...
测试这个方法:
public class AnotherService
{
internal Result Backup()
{
var ret = this.mockService.ServiceMethod().Value;
...
return Result.Ok();
}
当我仅为Test_Method() 运行该方法时,一切正常。当我尝试为整个 MyTests 类运行时,此引用方法出现以下错误:
NSubstitute.Exceptions.AmbiguousArgumentsException: '无法确定 要使用的参数规范。请使用所有规格 相同类型的参数。'
我相信这个问题与这种情况无关: How NOT to use argument matchers
NSubstitute.Analyzers:
有什么事吗?
【问题讨论】:
-
你应该为模拟服务定义返回值
this.mockService.ServiceMethod(Arg.Any<Guid>()).Returns(Result.With(Enumerable.Empty<string>())) -
感谢法比奥!但是我已经尝试过了……但我仍然有同样的错误。我更新了问题。
标签: mocking nsubstitute