Arrange Act Assert with StructureMap RhinoAutoMocker


Fresh on the heels of finally figuring out how to make the AAA syntax in Rhino.Mocks work, I’ve added support to StructureMap’s RhinoAutoMocker. If you pass MockMode.AAA to the constructor of your RhinoAutoMocker, all of the mocks that it creates will be in replay mode. This is required to successfully use the AssertWasCalled extension method. By default, if you do not pass a MockMode to the constructor, mocks will be created in record mode so that you can continue to set expectations the old fashioned way.

[Test]
public void TheAutoMockerOptionallyPushesInMocksInReplayModeToAllowForAAAsyntax()
{
    var autoMocker = new RhinoAutoMocker<ConcreteClass>(MockMode.AAA);

    autoMocker.ClassUnderTest.CallService();

    autoMocker.Get<IMockedService>().AssertWasCalled(s => s.Go());
}

The code is in the trunk, and will be included in the eventual StructureMap 2.5 release.

Updated Oct 8, 2008: The MockMode enumeration to enable AAA syntax has been changed to MockMode.AAA to be more self-explanatory.

The Rhino.Mocks’ AssertWasCalled method does work