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

moc*_*ect 10 c# unit-testing rhino-mocks

我不能为我的生活找到使用Rhino中的Fluent/AAA语法来验证操作顺序的正确语法.

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

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

        using (repository.Playback())
        {
            // test
        }
Run Code Online (Sandbox Code Playgroud)

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

tva*_*son 6

试试这个:

  //
  // Arrange
  //
  var mockFoo = MockRepository.GenerateMock<Foo>();
  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();
Run Code Online (Sandbox Code Playgroud)


mar*_*sen 5

这是一个交互测试示例,您通常希望将有序期望用于:

// 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();
Run Code Online (Sandbox Code Playgroud)

这种语法非常类似于 Expect/Verify,但据我所知,这是目前唯一的方法,并且它确实利用了 3.5 引入的一些不错的功能。