Commit 7ae11d3

mo khan <mo@mokhan.ca>
2010-07-17 22:28:18
refactored out some of the mocking duplication.
1 parent 850c4ed
product/support/unit/client/presenters/AddFamilyMemberPresenterSpecs.cs
@@ -1,17 +1,17 @@
 using Machine.Specifications;
 using presentation.windows;
 using presentation.windows.presenters;
-using Rhino.Mocks;
 
 namespace unit.client.presenters
 {
+    [Subject(typeof(AddFamilyMemberPresenter))]
     public class AddFamilyMemberPresenterSpecs
     {
-        public class concern
+        public class concern : Helpers
         {
             Establish context = () =>
             {
-                command_builder = MockRepository.GenerateMock<UICommandBuilder>();
+                command_builder = a<UICommandBuilder>();
 
                 sut = new AddFamilyMemberPresenter(command_builder);
             };
@@ -24,14 +24,14 @@ namespace unit.client.presenters
         {
             It should_invoke_the_save_command = () =>
             {
-                save_command.AssertWasCalled(x => x.Execute(null));
+                save_command.received(x => x.Execute(null));
             };
 
             Establish context = () =>
             {
-                save_command = MockRepository.GenerateMock<IObservableCommand>();
+                save_command = a<IObservableCommand>();
 
-                command_builder.Stub(x => x.build<AddFamilyMemberPresenter.SaveCommand>(sut)).Return(save_command);
+                command_builder.is_told_to(x => x.build<AddFamilyMemberPresenter.SaveCommand>(sut)).it_will_return(save_command);
             };
 
             Because b = () =>
product/support/unit/client/presenters/WpfCommandBuilderSpecs.cs
@@ -2,13 +2,13 @@ using Autofac;
 using Machine.Specifications;
 using presentation.windows;
 using presentation.windows.presenters;
-using Rhino.Mocks;
 
 namespace unit.client.presenters
 {
+    [Subject(typeof (WPFCommandBuilder))]
     public class WPFCommandBuilderSpecs
     {
-        public class concern
+        public class concern : Helpers
         {
             Establish context = () =>
             {
@@ -16,11 +16,6 @@ namespace unit.client.presenters
                 sut = new WPFCommandBuilder(container);
             };
 
-            static public T a<T>() where T : class
-            {
-                return MockRepository.GenerateMock<T>();
-            }
-
             static protected WPFCommandBuilder sut;
             static protected IContainer container;
         }
@@ -36,7 +31,7 @@ namespace unit.client.presenters
             {
                 presenter = a<Presenter>();
                 command = a<UICommand>();
-                container.Stub(x => x.Resolve<UICommand>()).Return(command);
+                container.is_told_to(x => x.Resolve<UICommand>()).it_will_return(command);
             };
 
             Because b = () =>
product/support/unit/Helpers.cs
@@ -0,0 +1,12 @@
+using Rhino.Mocks;
+
+namespace unit
+{
+    public class Helpers
+    {
+        static public T a<T>() where T : class
+        {
+            return MockRepository.GenerateMock<T>();
+        }
+    }
+}
\ No newline at end of file
product/support/unit/Mocking.cs
@@ -1,5 +1,6 @@
 using System;
 using Rhino.Mocks;
+using Rhino.Mocks.Interfaces;
 
 namespace unit
 {
@@ -9,5 +10,15 @@ namespace unit
         {
             mock.AssertWasCalled(action);
         }
+
+        static public IMethodOptions<R> is_told_to<T, R>(this T mock, Function<T, R> action) where T : class
+        {
+            return mock.Stub(action);
+        }
+
+        static public IMethodOptions<T> it_will_return<T>(this IMethodOptions<T> options, T objToReturn)
+        {
+            return options.Return(objToReturn);
+        }
     }
 }
\ No newline at end of file
product/support/unit/unit.csproj
@@ -49,6 +49,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="client\presenters\AddFamilyMemberPresenterSpecs.cs" />
+    <Compile Include="Helpers.cs" />
     <Compile Include="client\presenters\WpfCommandBuilderSpecs.cs" />
     <Compile Include="Mocking.cs" />
   </ItemGroup>