RhinoMocks中的ReplayAll()和VerifyAll()是什么
[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()
的用途是什么?
[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();
}
What is the purpose of ReplayAll()
and VerifyAll()
in this code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该代码片段演示了Rhino.Mocks的记录/重放/验证语法。您首先记录模拟的期望(使用
Expect.Call()
),然后调用ReplayAll()
运行模拟模拟。然后,调用VerifyAll ()
来验证是否满足了所有期望。顺便说一下,这是一个过时的语法,称为 AAA 语法 - Arrange、Act、Assert 通常比旧的 R 更容易使用/R/V 一个。你的代码被翻译成 AAA:
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 callReplayAll()
to run the mock simulation. Then, you callVerifyAll()
to verify that all the expectations have been met.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: