Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Rhinomock中的ReplayAll()和VerifyAll()是什么_C#_Rhino Mocks - Fatal编程技术网

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