由于验证功能未包含在Microsoft Fakes Beta中,以下代码是对依赖关系的方法是否被调用的基本测试.您可以增强对测试参数值或正确调用的其他条件的真实测试.
测试:
[TestMethod] public void TestMethod1() { var secondDoItCalled = false; var secondStub = new Fakes.ShimSecond(); secondStub.DoIt = () => { secondDoItCalled = true; }; var first = new First(secondStub); first.DoIt(); Assert.IsTrue(secondDoItCalled); }
类别:
public class First { readonly Second _second; public First(Second second) { _second = second; } public void DoIt() { //_second.DoIt(); } } public class Second {public void DoIt(){}}
取消上述行以查看测试通行证.