参考以下示例代码:
using NSubstitute;
using NUnit.Framework;
public class Class1
{
}
public class Class2
{
public void Method(Class1 class1)
{
}
}
public class Class3 : Class1
{
}
[TestFixture]
public class ArgAnyTest
{
[Test]
public void Test()
{
var called = false;
var class2 = Substitute.For<Class2>();
class2.When(@this => @this.Method(Arg.Any<Class1>())).Do(invocation => called = true);
class2.Method(new Class3());
Assert.That(called, Is.EqualTo(true));
}
}
断言失败,表明Method
存根不匹配。我是否误解了声称可用于“匹配特定子类型的任何参数”的参数匹配器文档页面?Arg.Any