C# Rhinomock中的ReplayAll()和VerifyAll()是什么
C# Rhinomock中的ReplayAll()和VerifyAll()是什么,c#,rhino-mocks,C#,Rhino Mocks,[测试] public void MockAGenericInterface() { MockRepository mocks=新建MockRepository(); IList list=mocks.Create Mock(); Assert.IsNotNull(列表); Expect.Call(list.Count).Return(5); mocks.ReplayAll(); Assert.AreEqual(5,list.Count); mocks.VerifyAll(); } 此代码中的
[测试]
public void MockAGenericInterface()
{
MockRepository mocks=新建MockRepository();
IList list=mocks.Create Mock();
Assert.IsNotNull(列表);
Expect.Call(list.Count).Return(5);
mocks.ReplayAll();
Assert.AreEqual(5,list.Count);
mocks.VerifyAll();
}
此代码中的
ReplayAll()
和VerifyAll()
的目的是什么?代码片段演示了Rhino.Mocks的记录/回放/验证语法。首先记录模拟的预期(使用Expect.Call()
),然后调用ReplayAll()
运行模拟。然后调用VerifyAll()
验证是否满足所有预期
顺便说一句,这是一种过时的语法。新语法被调用,并且通常比旧的R/R/V语法更容易使用。您的代码被截断并翻译为AAA:
[Test]
public void MockAGenericInterface()
{
MockRepository mocks = new MockRepository();
IList<int> list = mocks.Create Mock<IList<int>>();
Assert.IsNotNull(list);
Expect.Call(list.Count).Return(5);
mocks.ReplayAll();
Assert.AreEqual(5, list.Count);
mocks.VerifyAll();
}
[测试]
public void MockAGenericInterface()
{
IList list=MockRepository.GenerateMock();
Assert.IsNotNull(列表);
Expect(x=>x.Count).Return(5);
Assert.AreEqual(5,list.Count);
list.verifyallexpections();
}
[Test]
public void MockAGenericInterface()
{
IList<int> list = MockRepository.GenerateMock<IList<int>>();
Assert.IsNotNull(list);
list.Expect (x => x.Count).Return(5);
Assert.AreEqual(5, list.Count);
list.VerifyAllExpectations();
}