对于下面的代码,我得到这个断言失败并且不知道为什么:
Assert.AreEqual failed. Expected:<2>. Actual:<0>.
public interface IA
{
void MethodA(B b);
}
public class A : IA
{
public void MethodA(B b) {/*no matter*/}
}
public class B
{
public string PropertyB { get; set; }
}
public class MyLogic
{
private IA _a;
public MyLogic(IA a)
{
_a = a;
}
public void DoLogic()
{
_a.MethodA(new B { PropertyB = "first" });
_a.MethodA(new B { PropertyB = "second" });
}
}
[TestClass]
public class MyLogicTests
{
[TestMethod]
public void CallTwiceAndCheckTheParams()
{
List<B> args = new List<B>();
IA a = Substitute.For<IA>();
new MyLogic(a).DoLogic();
a.Received(2).MethodA(Arg.Do<B>(x => args.Add(x)));
Assert.AreEqual(2, args.Count);
}
}