Commit d6716a2

mo_khan <mo@mokhan.ca>
2009-05-25 01:06:21
cleaning up presenter and adding missing specs
1 parent fe27547
product/project/domain/Coordinate.cs
@@ -22,12 +22,12 @@ namespace mars.rover.domain
             coordinate--;
         }
 
-        public Coordinate plus(uint other)
+        public virtual Coordinate plus(uint other)
         {
             return new Coordinate(coordinate + other);
         }
 
-        public Coordinate minus(uint other)
+        public virtual Coordinate minus(uint other)
         {
             return new Coordinate(coordinate - other);
         }
@@ -42,7 +42,7 @@ namespace mars.rover.domain
             return coordinate.coordinate;
         }
 
-        public int CompareTo(Coordinate other)
+        public virtual int CompareTo(Coordinate other)
         {
             return coordinate.CompareTo(other.coordinate);
         }
product/project/domain/NASA.cs
@@ -1,17 +0,0 @@
-namespace mars.rover.domain
-{
-    public class NASA
-    {
-        Plateau plateau;
-
-        public NASA(Plateau plateau)
-        {
-            this.plateau = plateau;
-        }
-
-        public virtual Rover deploy_rover_to(uint x_coordinate, uint y_coordinate, Heading heading)
-        {
-            return new Rover(x_coordinate, y_coordinate, heading);
-        }
-    }
-}
\ No newline at end of file
product/project/domain/Rover.cs
@@ -27,5 +27,10 @@ namespace mars.rover.domain
         {
             heading.move_forward_from(x, y);
         }
+
+        public override string ToString()
+        {
+            return string.Format("{0} {1} {2}", x, y, heading);
+        }
     }
 }
\ No newline at end of file
product/project/presentation/model/UnknownNavigation.cs
@@ -4,7 +4,7 @@ namespace mars.rover.presentation.model
 {
     internal class UnknownNavigation : Navigation
     {
-        public UnknownNavigation() : base('a', null)
+        public UnknownNavigation() : base('?', null)
         {
         }
 
product/project/presentation/CaptureUserInstructionsConsoleView.cs
@@ -28,9 +28,9 @@ namespace mars.rover.presentation
             }
         }
 
-        public void display(uint x, uint y, string heading)
+        public void display(string location)
         {
-            writer.WriteLine("{0} {1} {2}", x, y, heading);
+            writer.WriteLine(location);
         }
     }
 }
\ No newline at end of file
product/project/presentation/CaptureUserInstructionsPresenter.cs
@@ -33,22 +33,22 @@ namespace mars.rover.presentation
             plateau = new Mars(Convert.ToUInt32(coordinates[0]), Convert.ToUInt32(coordinates[1]));
         }
 
-        public virtual void deploy_rover_to(string line)
+        public virtual void deploy_rover_to(string deployment_coordinates)
         {
-            var coordinates = line.Split(new[] {' '});
+            var coordinates = deployment_coordinates.Split(new[] {' '});
             rover = new Rover(Convert.ToUInt32(coordinates[0]), Convert.ToUInt32(coordinates[1]),
                               find_heading_for(coordinates[2]));
         }
 
-        public virtual void navigate_rover_using(string line)
+        public virtual void navigate_rover_using(string navigation_commands)
         {
-            line.each(x => navigations.Single(y => y.is_satisfied_by(x)).run_against(rover));
-            view.display(rover.x, rover.y, rover.heading.ToString());
+            navigation_commands.each(x => navigations.First(y => y.is_satisfied_by(x)).run_against(rover));
+            view.display(rover.ToString());
         }
 
         Heading find_heading_for(string heading)
         {
-            return factories.Single(x => x.is_satisfied_by(heading)).create(plateau);
+            return factories.First(x => x.is_satisfied_by(heading)).create(plateau);
         }
     }
 }
\ No newline at end of file
product/project/presentation/CaptureUserInstructionsView.cs
@@ -3,6 +3,6 @@ namespace mars.rover.presentation
     public interface CaptureUserInstructionsView
     {
         void attach_to(CaptureUserInstructionsPresenter presenter);
-        void display(uint coordinate, uint coordinate1, string heading);
+        void display(string location);
     }
 }
\ No newline at end of file
product/project/project.csproj
@@ -59,7 +59,6 @@
     <Compile Include="domain\East.cs" />
     <Compile Include="domain\Heading.cs" />
     <Compile Include="domain\Headings.cs" />
-    <Compile Include="domain\NASA.cs" />
     <Compile Include="domain\North.cs" />
     <Compile Include="common\ParameterizedCommand.cs" />
     <Compile Include="domain\Mars.cs" />
product/project.specifications/common/DefaultRegistrySpecs.cs
@@ -0,0 +1,33 @@
+using System.Collections.Generic;
+using System.Linq;
+using developwithpassion.bdd.contexts;
+using developwithpassion.bdd.mbunit;
+using developwithpassion.bdd.mbunit.standard.observations;
+using mars.rover.common;
+
+namespace specifications.common
+{
+    public class DefaultRegistrySpecs
+    {
+    }
+
+    public class when_retrieving_all_the_items_added_to_a_registry :
+        observations_for_a_sut_with_a_contract<Registry<int>, DefaultRegistry<int>>
+    {
+        it should_return_each_item_that_was_added = () =>
+                                                        {
+                                                            sut.Count().should_be_equal_to(2);
+                                                            results.should_contain(1);
+                                                            results.should_contain(2);
+                                                        };
+
+        because b = () => { results = sut.all(); };
+
+        public override Registry<int> create_sut()
+        {
+            return new DefaultRegistry<int> {1, 2};
+        }
+
+        static IEnumerable<int> results;
+    }
+}
\ No newline at end of file
product/project.specifications/domain/NASASpecs.cs
@@ -1,20 +0,0 @@
-using developwithpassion.bdd.contexts;
-using developwithpassion.bdd.mbunit;
-using developwithpassion.bdd.mbunit.standard.observations;
-using mars.rover.domain;
-
-namespace specifications.domain
-{
-    public class NASASpecs
-    {
-    }
-
-    public class when_nasa_deploys_a_rover_to_a_position_on_mars : observations_for_a_sut_without_a_contract<NASA>
-    {
-        it should_return_a_new_rover = () => result.should_not_be_null();
-
-        because b = () => { result = sut.deploy_rover_to(1, 2, Headings.North); };
-
-        static Rover result;
-    }
-}
\ No newline at end of file
product/project.specifications/presentation/model/HeadingFactorySpecs.cs
@@ -0,0 +1,56 @@
+using System;
+using developwithpassion.bdd.contexts;
+using developwithpassion.bdd.mbunit;
+using developwithpassion.bdd.mbunit.standard.observations;
+using mars.rover.domain;
+using mars.rover.presentation.model;
+
+namespace specifications.presentation.model
+{
+    public class HeadingFactorySpecs
+    {
+    }
+
+    public class when_checking_if_a_heading_factory_can_produce_a_heading_for_a_type_that_it_cannot :
+        observations_for_a_sut_without_a_contract<HeadingFactory>
+    {
+        it should_return_false = () => result.should_be_equal_to(false);
+
+        context c = () => { provide_a_basic_sut_constructor_argument("S"); };
+        because b = () => { result = sut.is_satisfied_by("N"); };
+
+        static bool result;
+    }
+
+    public class when_checking_if_a_heading_factory_can_produce_a_heading_for_a_type_that_it_can :
+        observations_for_a_sut_without_a_contract<HeadingFactory>
+    {
+        it should_return_true = () => result.should_be_equal_to(true);
+
+        context c = () => { provide_a_basic_sut_constructor_argument("S"); };
+        because b = () => { result = sut.is_satisfied_by("s"); };
+
+        static bool result;
+    }
+
+    public class when_telling_the_factory_to_produce_a_heading :
+        observations_for_a_sut_without_a_contract<HeadingFactory>
+    {
+        it should_return_the_correct_type = () => { result.should_be_equal_to(heading); };
+
+        context c = () =>
+                        {
+                            heading = an<Heading>();
+                            plateau = an<Plateau>();
+                            Func<Plateau, Heading> factory = x => heading;
+                            provide_a_basic_sut_constructor_argument("E");
+                            provide_a_basic_sut_constructor_argument(factory);
+                        };
+
+        because b = () => { result = sut.create(plateau); };
+
+        static Heading result;
+        static Heading heading;
+        static Plateau plateau;
+    }
+}
\ No newline at end of file
product/project.specifications/presentation/model/NavigationSpecs.cs
@@ -0,0 +1,63 @@
+using System;
+using developwithpassion.bdd;
+using developwithpassion.bdd.contexts;
+using developwithpassion.bdd.mbunit;
+using developwithpassion.bdd.mbunit.standard.observations;
+using mars.rover.domain;
+using mars.rover.presentation.model;
+using Rhino.Mocks;
+
+namespace specifications.presentation.model
+{
+    public class NavigationSpecs
+    {
+    }
+
+    public class when_applying_a_navigation_against_a_rover : observations_for_a_sut_without_a_contract<Navigation>
+    {
+        it should_direct_the_rover_correctly = () => rover.received(x => x.turn_left());
+
+        context c = () =>
+                        {
+                            an<object>();
+                            rover = MockRepository.GenerateStub<Rover>(new Coordinate(0), new Coordinate(0),
+                                                                       an<Heading>());
+                            provide_a_basic_sut_constructor_argument('l');
+                            provide_a_basic_sut_constructor_argument((Action<Rover>) (x => x.turn_left()));
+                        };
+
+        because b = () => sut.run_against(rover);
+
+        static Rover rover;
+    }
+
+    public class when_checking_if_a_navigation_knows_how_to_process_input_from_nasa :
+        observations_for_a_sut_without_a_contract<Navigation>
+    {
+        context c = () =>
+                        {
+                            code = 'l';
+                            provide_a_basic_sut_constructor_argument(code);
+                        };
+
+        static protected char code;
+    }
+
+    public class when_input_is_recognized : when_checking_if_a_navigation_knows_how_to_process_input_from_nasa
+    {
+        it should_return_true = () => result.should_be_equal_to(true);
+
+        because b = () => { result = sut.is_satisfied_by(char.ToUpperInvariant(code)); };
+
+        static bool result;
+    }
+
+    public class when_input_is_not_recognized : when_checking_if_a_navigation_knows_how_to_process_input_from_nasa
+    {
+        it should_return_false = () => result.should_be_equal_to(false);
+
+        because b = () => { result = sut.is_satisfied_by('M'); };
+
+        static bool result;
+    }
+}
\ No newline at end of file
product/project.specifications/project.specifications.csproj
@@ -65,13 +65,15 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="common\DefaultRegistrySpecs.cs" />
     <Compile Include="domain\CoordinateSpecs.cs" />
     <Compile Include="domain\EastSpecs.cs" />
     <Compile Include="domain\NorthSpecs.cs" />
     <Compile Include="domain\MarsSpecs.cs" />
     <Compile Include="presentation\CaptureUserInstructionsPresenterSpecs.cs" />
-    <Compile Include="domain\NASASpecs.cs" />
     <Compile Include="domain\PositionSpecs.cs" />
+    <Compile Include="presentation\model\HeadingFactorySpecs.cs" />
+    <Compile Include="presentation\model\NavigationSpecs.cs" />
     <Compile Include="ProgramSpecs.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="domain\RoverSpecs.cs" />