我想验证传递给随后的模拟方法调用(同一方法)的参数值,但找不到有效的方法。一个普通的例子如下:使用Moq验证具有不同参数的单独调用
public class Foo
{
[Dependency]
public Bar SomeBar
{
get;
set;
}
public void SomeMethod()
{
this.SomeBar.SomeOtherMethod("baz");
this.SomeBar.SomeOtherMethod("bag");
}
}
public class Bar
{
public void SomeOtherMethod(string input)
{
}
}
public class MoqTest
{
[TestMethod]
public void RunTest()
{
Mock<Bar> mock = new Mock<Bar>();
Foo f = new Foo();
mock.Setup(m => m.SomeOtherMethod(It.Is<string>("baz")));
mock.Setup(m => m.SomeOtherMethod(It.Is<string>("bag"))); // this of course overrides the first call
f.SomeMethod();
mock.VerifyAll();
}
}
在安装使用功能可能是一种选择,但后来好像我会减少到某种全局变量的知道我验证这论点/迭代。也许我忽略了Moq框架中的明显内容?
这不完全是我想要的,因为它不能确保以所需的特定顺序调用该方法,并且链接的帖子基本上解释了那里这并不是Moq的直接支持,但我同意这可能是最好的选择。 – Thermite 2011-01-11 01:48:17