Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the AAA syntax equivalent to using Ordered() in Rhino Mocks

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.

like image 293
mockobject Avatar asked Apr 21 '09 15:04

mockobject


2 Answers

Try this:

  //
  // 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();
like image 185
tvanfosson Avatar answered Sep 27 '22 19:09

tvanfosson


Here's an example with interaction testing which is what you usually want to use ordered expectations for:

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

This syntax is very much Expect/Verify but as far as I know it's the only way to do it right now, and it does take advantage of some of the nice features introduced with 3.5.

like image 41
martinnjensen Avatar answered Sep 27 '22 21:09

martinnjensen