diff options
| author | mo k <mo@mokhan.ca> | 2012-05-30 22:26:04 -0600 |
|---|---|---|
| committer | mo k <mo@mokhan.ca> | 2012-05-30 22:26:04 -0600 |
| commit | 18db302a64ad5ace63861a427ea66e0d29af14f3 (patch) | |
| tree | 39959e18f75fe029a20277b7549cff982136542b | |
| parent | c156ffcd25324e4fd49345b7d76df012f8dc1dd9 (diff) | |
register subscribers of different events.main
| -rwxr-xr-x | src/core/extensions/Casting.cs | 2 | ||||
| -rwxr-xr-x | src/core/extensions/Dynamic.cs | 8 | ||||
| -rwxr-xr-x | src/specs/Mock.cs | 7 | ||||
| -rwxr-xr-x | src/specs/RoboMomSpecs.cs | 2 | ||||
| -rwxr-xr-x | src/specs/infrastructure/EventAggregatorSpec.cs | 12 |
5 files changed, 26 insertions, 5 deletions
diff --git a/src/core/extensions/Casting.cs b/src/core/extensions/Casting.cs index 24c12a6..03f6047 100755 --- a/src/core/extensions/Casting.cs +++ b/src/core/extensions/Casting.cs @@ -2,7 +2,7 @@ namespace core.extensions {
public static class Casting
{
- public static T DowncastTo<T>(this object item) where T : class
+ public static T downcast_to<T>(this object item) where T : class
{
return item as T;
}
diff --git a/src/core/extensions/Dynamic.cs b/src/core/extensions/Dynamic.cs index b08f7b1..df34945 100755 --- a/src/core/extensions/Dynamic.cs +++ b/src/core/extensions/Dynamic.cs @@ -6,7 +6,13 @@ namespace core.extensions {
public static void call_as<DynamicType>(this object target, Action<DynamicType> command) where DynamicType : class
{
- command(target.DowncastTo<DynamicType>());
+ target.downcast_to<DynamicType>().run(command);
+ }
+
+ public static void run<T>(this T target, Action<T> command)
+ {
+ if (null == target) return;
+ command(target);
}
}
}
\ No newline at end of file diff --git a/src/specs/Mock.cs b/src/specs/Mock.cs index 6712e45..5ecdae2 100755 --- a/src/specs/Mock.cs +++ b/src/specs/Mock.cs @@ -5,7 +5,7 @@ namespace specs {
public static class Mock
{
- public static T An<T>() where T : class
+ public static T an<T>() where T : class
{
return MockRepository.GenerateMock<T>();
}
@@ -14,5 +14,10 @@ namespace specs {
mock.AssertWasCalled(command);
}
+
+ public static void should_not_have_received<T>(this T mock, Action<T> command)
+ {
+ mock.AssertWasNotCalled(command);
+ }
}
}
\ No newline at end of file diff --git a/src/specs/RoboMomSpecs.cs b/src/specs/RoboMomSpecs.cs index f388923..69034d6 100755 --- a/src/specs/RoboMomSpecs.cs +++ b/src/specs/RoboMomSpecs.cs @@ -9,7 +9,7 @@ namespace specs {
Establish context = () =>
{
- publisher = Mock.An<IPublishEvents>();
+ publisher = Mock.an<IPublishEvents>();
sut = new RoboMom(publisher);
};
diff --git a/src/specs/infrastructure/EventAggregatorSpec.cs b/src/specs/infrastructure/EventAggregatorSpec.cs index 4d6be1b..f6b0ccb 100755 --- a/src/specs/infrastructure/EventAggregatorSpec.cs +++ b/src/specs/infrastructure/EventAggregatorSpec.cs @@ -1,5 +1,7 @@ +using System.Data;
using Machine.Specifications;
using core.infrastructure;
+using Rhino.Mocks;
namespace specs.infrastructure
{
@@ -19,18 +21,26 @@ namespace specs.infrastructure subscriber.received(x => x.notify("hello"));
};
+ It should_not_notify_subscribers_who_are_not_interested_in_that_particular_event = () =>
+ {
+ uninterested_subscriber.should_not_have_received(x => x.notify(Arg<IDbCommand>.Is.Anything));
+ };
+
Establish context = () =>
{
- subscriber = Mock.An<ISubscribeTo<string>>();
+ subscriber = Mock.an<ISubscribeTo<string>>();
+ uninterested_subscriber = Mock.an<ISubscribeTo<IDbCommand>>();
};
Because of = () =>
{
+ sut.register(uninterested_subscriber);
sut.register(subscriber);
sut.publish("hello");
};
static ISubscribeTo<string> subscriber;
+ static ISubscribeTo<IDbCommand> uninterested_subscriber;
}
}
}
\ No newline at end of file |
