What is ReplayAll() and VerifyAll() in RhinoMocks

↘锁芯ラ 提交于 2019-12-04 20:35:41

问题


[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?


回答1:


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.

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();
  }


来源:https://stackoverflow.com/questions/6078061/what-is-replayall-and-verifyall-in-rhinomocks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!