10

I can't for the life of me find the proper syntax using the Fluent/AAA syntax in Rhino for validating order of operations.

I know how to do this with the old school record/playback syntax:

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

        using (repository.Playback())
        {
            // test
        }

Can anyone tell me what the equivalent to this in AAA syntax for Rhino Mocks would be. Even better if you can point me to some documentation for this.

4

4 に答える 4

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();
于 2009-04-21T15:40:53.537 に答える
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();

この構文は非常にExpect/Verificationですが、私が知る限り、これが現時点で唯一の方法であり、3.5で導入された優れた機能のいくつかを利用しています。

于 2009-08-19T11:38:55.023 に答える
2

GenerateMock静的ヘルパーとOrdered()は、期待どおりに機能しませんでした。これが私にとってのトリックでした(重要なのは、独自のMockRepositoryインスタンスを明示的に作成することのようです)。

    [Test]
    public void Test_ExpectCallsInOrder()
    {
        var mockCreator = new MockRepository();
        _mockChef = mockCreator.DynamicMock<Chef>();
        _mockInventory = mockCreator.DynamicMock<Inventory>();
        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();
    }
于 2010-01-23T18:02:14.233 に答える
0

tvanfossonの解決策もうまくいきません。2 つのモックに対して特定の順序で呼び出しが行われることを確認する必要がありました。

Google グループ での Ayende の返信によるとOrdered()、AAA 構文では機能しません。

于 2011-06-03T00:43:50.483 に答える