I mean Grokking Rhino Mocks. My usage of Rhino Mocks has changed quite a bit since I first started using it a year ago, as well as the way I write tests.

First it was like this:

 1 [TestFixture]
 2   public class ConsoleTest {
 3       private MockRepository mockery;
 4       private IReportPresenter presenter;
 5   
 6       [SetUp]
 7       public void SetUp() {
 8           mockery = new MockRepository();
 9           presenter = mockery.CreateMock<IReportPresenter>();
10       }
11   
12       [TearDown]
13       public void TearDown() {
14           mockery.VerifyAll();
15       }
16   
17       [Test]
18       public void ShouldInitializeTheReportPresenter() {
19           var commandLineArguments = new[] {"blah"};
20           presenter.Initialize();
21   
22           mockery.ReplayAll();
23           new Console(presenter).Execute(commandLineArguments);
24       }
25   }

Then it evolved to this...

 1 [TestFixture]
 2   public class ConsoleTest {
 3       private MockRepository mockery;
 4       private IReportPresenter presenter;
 5   
 6       [SetUp]
 7       public void SetUp() {
 8           mockery = new MockRepository();
 9           presenter = mockery.DynamicMock<IReportPresenter>();
10       }
11   
12       [Test]
13       public void ShouldInitializeTheReportPresenter() {
14           var commandLineArguments = new[] {"blah"};
15   
16           using (mockery.Record()) {
17               presenter.Initialize();
18           }
19           using (mockery.Playback()) {
20               CreateSUT().Execute(commandLineArguments);
21           }
22       }
23   
24       private IConsole CreateSUT() {
25           return new Console(presenter);
26       }
27   }

Then for a short time I tried this...

 1 [TestFixture]
 2   public class when_giving_the_console_valid_arguments {
 3       private IReportPresenter presenter;
 4   
 5       [SetUp]
 6       public void SetUp() {
 7           presenter = MockRepository.GenerateMock<IReportPresenter>();
 8       }
 9   
10       [Test]
11       public void should_initialize_the_report_presenter() {
12           var commandLineArguments = new[] {"blah"};
13           CreateSUT().Execute(commandLineArguments);
14           presenter.AssertWasCalled(p => p.Initialize());
15       }
16   
17       private IConsole CreateSUT() {
18           return new Console(presenter);
19       }
20   }

Now I'm trying this...

 1 [Concern(typeof (Console))]
 2   public class when_the_console_is_given_valid_console_arguments : context_spec<IConsole> {
 3       private string[] command_line_arguments;
 4       private IReportPresenter presenter;
 5   
 6       protected override IConsole UnderTheseConditions() {
 7           command_line_arguments = new[] {"path", "testfixtureattributename"};
 8           presenter = Dependency<IReportPresenter>();
 9   
10           return new Console(presenter);
11       }
12   
13       protected override void BecauseOf() {
14           sut.Execute(command_line_arguments);
15       }
16   
17       [Test]
18       public void should_initialize_the_report_presenter() {
19           presenter.should_have_been_asked_to(p => p.Initialize());
20       }
21   }

Now I'm generating reports from my tests specs using this. I wonder what's next...

comments powered by Disqus