我有一个带有这个签名的方法:
public static void foo(int x, int y)
{
//do something...
}
我想验证此方法在 x = 5
和 y = 10
时被调用了 2 次。我如何使用 Typemock 做到这一点?
最佳答案
我试了一下,得出了以下结论:
给定类:
public class Bar
{
public static void Foo(int x, int y)
{
//do something...
Debug.WriteLine($"Method called with {x} {y}");
}
}
您的测试将如下所示:
[TestClass]
public class Test
{
[TestMethod]
public void TestMethod()
{
var callCount = 0;
Isolate.WhenCalled(() => Bar.Foo(2, 10))
.WithExactArguments()
.DoInstead(context =>
{
callCount++;
context.WillCallOriginal();
});
Bar.Foo(2, 6);
Bar.Foo(2, 10);
Bar.Foo(2, 10);
Assert.AreEqual(2, callCount);
}
}
关于c# - 使用 Typemock 断言一个方法被调用了 x 次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47156499/