什么是ReplayAll()和VerifyAll()中RhinoMocks的 [英] What is ReplayAll() and VerifyAll() in RhinoMocks
问题描述
[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();
}
什么是 ReplayAll()的目的
和 VerifyAll()
这段代码?
推荐答案
代码片段演示了在录制/回放/校验 Rhino.Mocks的语法。你先录制预期为模拟(使用 Expect.Call()
,然后调用 ReplayAll()
运行模拟仿真,然后,你叫 VerifyAll()
来验证所有的期望都得到满足。
The code snippet demonstrates the Record/Replay/Verify syntax of Rhino.Mocks. You first record the expectations for a mock (using Expect.Call()
, then you call ReplayAll()
to run the mock simulation. Then, you call VerifyAll()
to verify that all the expectations have been met.
这是一种过时的语法,顺便说一句,新的语法称为 <强> AAA语法 - 安排,法,断言 ,通常更容易比旧R / R / v一个工作你剪断代码转换为AAA。
This is an obsolete syntax, by the way. The new syntax is called AAA Syntax - Arrange, Act, Assert and is usually easier to work with than the old R/R/V one. You code snipped translated to AAA:
[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();
}
这篇关于什么是ReplayAll()和VerifyAll()中RhinoMocks的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!