summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo k <mo@mokhan.ca>2012-05-30 21:54:09 -0600
committermo k <mo@mokhan.ca>2012-05-30 21:54:09 -0600
commit959434b36702eb2effe6788d22d1eddea6681d8c (patch)
treede4964ffd0157dd0ed5762cfb025594eef2e780b
parentfb697a4189ca283ed57bbf05cd8ac503fc87dd78 (diff)
publish an event when hit by a bullet.
-rwxr-xr-xsrc/core/RoboMom.cs9
-rwxr-xr-xsrc/specs/EventAggregatorSpec.cs1
-rwxr-xr-xsrc/specs/RoboMomSpecs.cs44
-rwxr-xr-xsrc/specs/specs.csproj6
4 files changed, 58 insertions, 2 deletions
diff --git a/src/core/RoboMom.cs b/src/core/RoboMom.cs
index 3e958c2..50d577e 100755
--- a/src/core/RoboMom.cs
+++ b/src/core/RoboMom.cs
@@ -4,6 +4,13 @@ namespace core
{
public class RoboMom : Robot
{
+ readonly IPublishEvents publisher;
+
+ public RoboMom(IPublishEvents publisher)
+ {
+ this.publisher = publisher;
+ }
+
public override void Run()
{
while(true)
@@ -15,7 +22,7 @@ namespace core
public override void OnBulletHit(BulletHitEvent evnt)
{
- base.OnBulletHit(evnt);
+ publisher.Publish(evnt);
}
public override void OnBulletHitBullet(BulletHitBulletEvent evnt)
diff --git a/src/specs/EventAggregatorSpec.cs b/src/specs/EventAggregatorSpec.cs
index d40b9f8..b30cffc 100755
--- a/src/specs/EventAggregatorSpec.cs
+++ b/src/specs/EventAggregatorSpec.cs
@@ -1,5 +1,6 @@
using Machine.Specifications;
using Rhino.Mocks;
+using core;
namespace specs
{
diff --git a/src/specs/RoboMomSpecs.cs b/src/specs/RoboMomSpecs.cs
index a1fbe02..d20b81b 100755
--- a/src/specs/RoboMomSpecs.cs
+++ b/src/specs/RoboMomSpecs.cs
@@ -1,6 +1,48 @@
-namespace specs
+using Machine.Specifications;
+using Rhino.Mocks;
+using Robocode;
+using core;
+
+namespace specs
{
public class RoboMomSpecs
{
+ Establish context = () =>
+ {
+ publisher = Mock.An<IPublishEvents>();
+ sut = new RoboMom(publisher);
+ };
+
+ static RoboMom sut;
+ static IPublishEvents publisher;
+
+
+ public class when_hit
+ {
+ It should_publish_the_event = () =>
+ {
+ publisher.AssertWasCalled(x => x.Publish(message));
+ };
+
+ Establish context = () =>
+ {
+ message = new BulletHitEvent("blah", 0, new Bullet(0,0,0,0,"","", false, 0));
+ };
+
+ Because of = () =>
+ {
+ sut.OnBulletHit(message);
+ };
+
+ static BulletHitEvent message;
+ }
+ }
+
+ public static class Mock
+ {
+ public static T An<T>() where T : class
+ {
+ return MockRepository.GenerateMock<T>();
+ }
}
} \ No newline at end of file
diff --git a/src/specs/specs.csproj b/src/specs/specs.csproj
index d0ecf7c..0d7bef0 100755
--- a/src/specs/specs.csproj
+++ b/src/specs/specs.csproj
@@ -62,6 +62,12 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\core\core.csproj">
+ <Project>{925E4841-5CE2-427E-8D0B-74B26474BB1E}</Project>
+ <Name>core</Name>
+ </ProjectReference>
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.