diff options
| author | mo khan <mo@mokhan.ca> | 2010-07-17 16:28:18 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2010-07-17 16:28:18 -0600 |
| commit | 7ae11d344475c3e7528883c92bb0598b61b62f57 (patch) | |
| tree | b9df1e564b4887a984f1057eea3a0601d5d6808c | |
| parent | 850c4ede434ae06590337429a2f198d453adc295 (diff) | |
refactored out some of the mocking duplication.
| -rw-r--r-- | product/support/unit/Helpers.cs | 12 | ||||
| -rw-r--r-- | product/support/unit/Mocking.cs | 11 | ||||
| -rw-r--r-- | product/support/unit/client/presenters/AddFamilyMemberPresenterSpecs.cs | 12 | ||||
| -rw-r--r-- | product/support/unit/client/presenters/WpfCommandBuilderSpecs.cs | 11 | ||||
| -rw-r--r-- | product/support/unit/unit.csproj | 1 |
5 files changed, 33 insertions, 14 deletions
diff --git a/product/support/unit/Helpers.cs b/product/support/unit/Helpers.cs new file mode 100644 index 0000000..ca7a8b4 --- /dev/null +++ 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 diff --git a/product/support/unit/Mocking.cs b/product/support/unit/Mocking.cs index 1685a97..57ebbec 100644 --- a/product/support/unit/Mocking.cs +++ b/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 diff --git a/product/support/unit/client/presenters/AddFamilyMemberPresenterSpecs.cs b/product/support/unit/client/presenters/AddFamilyMemberPresenterSpecs.cs index 1f93cb0..8a59a68 100644 --- a/product/support/unit/client/presenters/AddFamilyMemberPresenterSpecs.cs +++ b/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 = () =>
diff --git a/product/support/unit/client/presenters/WpfCommandBuilderSpecs.cs b/product/support/unit/client/presenters/WpfCommandBuilderSpecs.cs index 779ce38..10d1614 100644 --- a/product/support/unit/client/presenters/WpfCommandBuilderSpecs.cs +++ 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 = () =>
diff --git a/product/support/unit/unit.csproj b/product/support/unit/unit.csproj index d6a0336..7dfc41a 100644 --- a/product/support/unit/unit.csproj +++ b/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>
|
