Commit ab987a4
Changed files (10)
product
application
application.console
application.console
application.tests
core
utility
product/application/utility/CommandExtensions.cs
@@ -0,0 +1,10 @@
+namespace gorilla.migrations.utility
+{
+ static public class CommandExtensions
+ {
+ static public Command then(this Command first_command, Command next_command)
+ {
+ return new CompositeCommand(first_command, next_command);
+ }
+ }
+}
\ No newline at end of file
product/application/utility/CompositeCommand.cs
@@ -0,0 +1,20 @@
+namespace gorilla.migrations.utility
+{
+ public class CompositeCommand : Command
+ {
+ readonly Command left;
+ readonly Command right;
+
+ public CompositeCommand(Command left, Command right)
+ {
+ this.left = left;
+ this.right = right;
+ }
+
+ public void run()
+ {
+ left.run();
+ right.run();
+ }
+ }
+}
\ No newline at end of file
product/application/application.csproj
@@ -68,6 +68,8 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RunMigrationsCommand.cs" />
<Compile Include="StringExtensions.cs" />
+ <Compile Include="utility\CommandExtensions.cs" />
+ <Compile Include="utility\CompositeCommand.cs" />
<Compile Include="utility\ConversionExtensions.cs" />
<Compile Include="utility\IterationExtensions.cs" />
</ItemGroup>
product/application.console/application.console/infrastructure/ComponentRegistry.cs
@@ -0,0 +1,17 @@
+namespace gorilla.migrations.console.infrastructure
+{
+ static public class ComponentRegistry
+ {
+ static Container underlying_container;
+
+ static public T get_a<T>()
+ {
+ return underlying_container.get_a<T>();
+ }
+
+ static public void initialize_with(Container container)
+ {
+ underlying_container = container;
+ }
+ }
+}
\ No newline at end of file
product/application.console/application.console/application.console.csproj
@@ -31,6 +31,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="developwithpassion.commons.core.infrastructure, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\..\thirdparty\developwithpassion.commons\developwithpassion.commons.core.infrastructure.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
@@ -46,6 +50,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="infrastructure\ComponentFactory.cs" />
+ <Compile Include="infrastructure\ComponentRegistry.cs" />
<Compile Include="infrastructure\Container.cs" />
<Compile Include="infrastructure\Factory.cs" />
<Compile Include="infrastructure\GenericRegistration.cs" />
@@ -56,6 +61,8 @@
<Compile Include="infrastructure\Singleton.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="RegisterConsoleCommands.cs" />
+ <Compile Include="WireUpContainer.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\application\application.csproj">
product/application.console/application.console/Program.cs
@@ -1,7 +1,17 @@
-namespace gorilla.migrations.console
+using gorilla.migrations.console.infrastructure;
+using gorilla.migrations.utility;
+
+namespace gorilla.migrations.console
{
class Program
{
- static void Main(string[] args) {}
+ static void Main(string[] args)
+ {
+ new WireUpContainer()
+ .then(new RegisterConsoleCommands())
+ .run();
+
+ ComponentRegistry.get_a<Console>().run_against(args);
+ }
}
}
\ No newline at end of file
product/application.console/application.console/RegisterConsoleCommands.cs
@@ -0,0 +1,12 @@
+using gorilla.migrations.console.infrastructure;
+
+namespace gorilla.migrations.console
+{
+ class RegisterConsoleCommands : Command
+ {
+ public void run()
+ {
+ ComponentRegistry.get_a<CommandRegistry>().register(ComponentRegistry.get_a<RunMigrationsCommand>());
+ }
+ }
+}
\ No newline at end of file
product/application.console/application.console/WireUpContainer.cs
@@ -0,0 +1,15 @@
+using gorilla.migrations.console.infrastructure;
+
+namespace gorilla.migrations.console
+{
+ class WireUpContainer : Command
+ {
+ public void run()
+ {
+ var builder = new SimpleContainerBuilder();
+ builder.register(() => new ConsoleApplication(ComponentRegistry.get_a<CommandRegistry>())).as_an<Console>();
+ builder.register(() => new ConsoleArgumentsCommandRegistry()).as_an<CommandRegistry>().scoped_as<Singleton>();
+ ComponentRegistry.initialize_with(builder.build());
+ }
+ }
+}
\ No newline at end of file
product/application.tests/core/utility/CommandExtensionsSpecs.cs
@@ -0,0 +1,75 @@
+using System;
+using System.Threading;
+using developwithpassion.bdd.contexts;
+using developwithpassion.bdd.harnesses.mbunit;
+using developwithpassion.bdddoc.core;
+using gorilla.migrations;
+using gorilla.migrations.utility;
+
+namespace tests.core.utility
+{
+ public class CommandExtensionsSpecs
+ {
+ public abstract class concern : observations_for_a_static_sut {}
+
+ [Concern(typeof (CommandExtensions))]
+ public class when_chaining_a_set_of_commands : concern
+ {
+ context c = () =>
+ {
+ first_command = new TestCommand();
+ second_command = new TestCommand.SubCommand();
+ };
+
+ because b = () =>
+ {
+ first_command.then(second_command).run();
+ };
+
+ it should_run_each_command_in_the_correct_order = () =>
+ {
+ first_command.ran_first().should_be_true();
+ second_command.ran().should_be_true();
+ };
+
+ static TestCommand first_command;
+ static TestCommand.SubCommand second_command;
+ }
+ }
+
+ class TestCommand : Command
+ {
+ public TestCommand()
+ {
+ first_has_run = DateTime.MinValue;
+ second_has_run = DateTime.MinValue;
+ }
+
+ public void run()
+ {
+ first_has_run = DateTime.Now;
+ Thread.Sleep(10);
+ }
+
+ public bool ran_first()
+ {
+ return first_has_run < second_has_run;
+ }
+
+ static DateTime second_has_run;
+ static DateTime first_has_run;
+
+ public class SubCommand : Command
+ {
+ public void run()
+ {
+ second_has_run = DateTime.Now;
+ }
+
+ public bool ran()
+ {
+ return !second_has_run.Equals(DateTime.MinValue);
+ }
+ }
+ }
+}
\ No newline at end of file
product/application.tests/application.tests.csproj
@@ -78,6 +78,7 @@
<Compile Include="core\data\SqlDatabaseGatewayFactorySpecs.cs" />
<Compile Include="core\data\SqlFileSpecs.cs" />
<Compile Include="core\data\SqlDatabaseGatewaySpecs.cs" />
+ <Compile Include="core\utility\CommandExtensionsSpecs.cs" />
<Compile Include="EmptyTestFixture.cs" />
<Compile Include="helpers\RhinoStubbingExtensions.cs" />
<Compile Include="core\io\WindowsFileSystemSpecs.cs" />