什么是等效于在Rhino Mocks中使用Ordered()的AAA语法

我无法为我的生活找到使用Rhino中的Fluent / AAA语法来validation操作顺序的正确语法。

我知道如何使用旧的学校记录/播放语法执行此操作:

MockRepository repository = new MockRepository(); using (repository.Ordered()) { // set some ordered expectations } using (repository.Playback()) { // test } 

任何人都可以告诉我在Rhino Mocks的AAA语法中与此相当的是什么。 如果你能指点我的一些文件,那就更好了。

试试这个:

  // // Arrange // var mockFoo = MockRepository.GenerateMock(); mockFoo.GetRepository().Ordered(); // or mockFoo.GetMockRepository().Ordered() in later versions var expected = ...; var classToTest = new ClassToTest( mockFoo ); // // Act // var actual = classToTest.BarMethod(); // // Assert // Assert.AreEqual( expected, actual ); mockFoo.VerifyAllExpectations(); 

以下是交互测试的示例,您通常希望使用有序期望:

 // Arrange var mockFoo = MockRepository.GenerateMock< Foo >(); using( mockFoo.GetRepository().Ordered() ) { mockFoo.Expect( x => x.SomeMethod() ); mockFoo.Expect( x => x.SomeOtherMethod() ); } mockFoo.Replay(); //this is a necessary leftover from the old days... // Act classToTest.BarMethod //Assert mockFoo.VerifyAllExpectations(); 

这个语法非常期待/validation,但据我所知,它是目前唯一的方法,它确实利用了3.5引入的一些不错的function。

GenerateMock静态助手和Ordered()没有按预期工作。 这就是我的诀窍(关键似乎是显式创建自己的MockRepository实例):

  [Test] public void Test_ExpectCallsInOrder() { var mockCreator = new MockRepository(); _mockChef = mockCreator.DynamicMock(); _mockInventory = mockCreator.DynamicMock(); mockCreator.ReplayAll(); _bakery = new Bakery(_mockChef, _mockInventory); using (mockCreator.Ordered()) { _mockInventory.Expect(inv => inv.IsEmpty).Return(false); _mockChef.Expect(chef => chef.Bake(CakeFlavors.Pineapple, false)); } _bakery.PleaseDonate(OrderForOnePineappleCakeNoIcing); _mockChef.VerifyAllExpectations(); _mockInventory.VerifyAllExpectations(); } 

tvanfosson的解决方案对我也不起作用。 我需要validation是否按特定顺序进行了2次嘲笑。

根据Ayende在Google Groups中的回复Ordered()在AAA语法中不起作用。