Commit 9a557b5

unknown <mkhan@.arcresources.ca>
2009-10-05 18:50:11
implemented the console application to lookup the appropriate command for the given console arguments.
1 parent 4d24c23
product/application/application.csproj
@@ -48,7 +48,7 @@
     <Compile Include="Command.cs" />
     <Compile Include="Console.cs" />
     <Compile Include="ConsoleApplication.cs" />
-    <Compile Include="ConsoleController.cs" />
+    <Compile Include="CommandRegistry.cs" />
     <Compile Include="ParameterizedCommand.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
product/application/CommandRegistry.cs
@@ -0,0 +1,7 @@
+namespace simple.migrations
+{
+    public interface CommandRegistry
+    {
+        ParameterizedCommand<string[]> command_for(string[] arguments);
+    }
+}
\ No newline at end of file
product/application/ConsoleApplication.cs
@@ -2,16 +2,16 @@ namespace simple.migrations
 {
     public class ConsoleApplication : Console
     {
-        readonly ConsoleController controller;
+        readonly CommandRegistry registry;
 
-        public ConsoleApplication(ConsoleController controller)
+        public ConsoleApplication(CommandRegistry registry)
         {
-            this.controller = controller;
+            this.registry = registry;
         }
 
-        public void run_against(string[] item)
+        public void run_against(string[] arguments)
         {
-            controller.process(item);
+            registry.command_for(arguments).run_against(arguments);
         }
     }
 }
\ No newline at end of file
product/application/ConsoleController.cs
@@ -1,7 +0,0 @@
-namespace simple.migrations
-{
-    public interface ConsoleController
-    {
-        void process(string[] arguments);
-    }
-}
\ No newline at end of file
product/application.tests/ConsoleSpecs.cs
@@ -1,6 +1,7 @@
 using developwithpassion.bdd.contexts;
 using developwithpassion.bdd.harnesses.mbunit;
 using developwithpassion.bdd.mocking.rhino;
+using Rhino.Mocks;
 using simple.migrations;
 
 namespace tests
@@ -9,20 +10,27 @@ namespace tests
     {
         public abstract class concern : observations_for_a_sut_with_a_contract<Console, ConsoleApplication>
         {
-            context c = () => { console_controller = controller.the_dependency<ConsoleController>(); };
+            context c = () => { command_registry = controller.the_dependency<CommandRegistry>(); };
 
-            protected static ConsoleController console_controller;
+            protected static CommandRegistry command_registry;
         }
 
-        public class when_running_a_test : concern
+        public class when_processing_a_new_request : concern
         {
-            it should_not_blow_up = () => { console_controller.received(x => x.process(console_arguments)); };
+            it should_run_the_command_that_can_handle_the_request =
+                () => { correct_command.received(x => x.run_against(console_arguments)); };
 
-            context c = () => { console_arguments = new[] {""}; };
+            context c = () =>
+                            {
+                                console_arguments = new[] {""};
+                                correct_command = controller.an<ParameterizedCommand<string[]>>();
+                                command_registry.Stub(x => x.command_for(console_arguments)).Return(correct_command);
+                            };
 
             because b = () => { controller.sut.run_against(console_arguments); };
 
             static string[] console_arguments;
+            static ParameterizedCommand<string[]> correct_command;
         }
     }
 }
\ No newline at end of file