Commit c287527
Changed files (11)
product/application/application.csproj
@@ -49,11 +49,13 @@
<Compile Include="Console.cs" />
<Compile Include="ConsoleApplication.cs" />
<Compile Include="CommandRegistry.cs" />
+ <Compile Include="ConsoleArguments.cs" />
<Compile Include="ConsoleArgumentsCommandRegistry.cs" />
<Compile Include="ConsoleCommand.cs" />
<Compile Include="HelpCommand.cs" />
<Compile Include="ParameterizedCommand.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="RunMigrationsCommand.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
product/application/CommandRegistry.cs
@@ -2,7 +2,7 @@ namespace simple.migrations
{
public interface CommandRegistry
{
- ParameterizedCommand<string[]> command_for(string[] arguments);
+ ParameterizedCommand<ConsoleArguments> command_for(string[] arguments);
void register(ConsoleCommand command);
}
}
\ No newline at end of file
product/application/ConsoleArguments.cs
@@ -0,0 +1,27 @@
+namespace simple.migrations
+{
+ public class ConsoleArguments
+ {
+ readonly string[] arguments;
+
+ ConsoleArguments(string[] arguments)
+ {
+ this.arguments = arguments;
+ }
+
+ public static implicit operator ConsoleArguments(string[] arguments)
+ {
+ return new ConsoleArguments(arguments);
+ }
+
+ public static implicit operator string[](ConsoleArguments arguments)
+ {
+ return arguments.arguments;
+ }
+
+ public bool contains(string key)
+ {
+ return arguments[0].Contains(key);
+ }
+ }
+}
\ No newline at end of file
product/application/ConsoleArgumentsCommandRegistry.cs
@@ -7,7 +7,7 @@ namespace simple.migrations
{
readonly IList<ConsoleCommand> all_commands = new List<ConsoleCommand>();
- public ParameterizedCommand<string[]> command_for(string[] arguments)
+ public ParameterizedCommand<ConsoleArguments> command_for(string[] arguments)
{
if(all_commands.Any(x => x.can_handle(arguments)))
return all_commands.Single(x => x.can_handle(arguments));
product/application/ConsoleCommand.cs
@@ -1,7 +1,7 @@
namespace simple.migrations
{
- public interface ConsoleCommand : ParameterizedCommand<string[]>
+ public interface ConsoleCommand : ParameterizedCommand<ConsoleArguments>
{
- bool can_handle(string[] arguments);
+ bool can_handle(ConsoleArguments arguments);
}
}
\ No newline at end of file
product/application/HelpCommand.cs
@@ -4,12 +4,12 @@ namespace simple.migrations
{
public class HelpCommand : ConsoleCommand
{
- public void run_against(string[] item)
+ public void run_against(ConsoleArguments item)
{
throw new NotImplementedException();
}
- public bool can_handle(string[] arguments)
+ public bool can_handle(ConsoleArguments arguments)
{
throw new NotImplementedException();
}
product/application/RunMigrationsCommand.cs
@@ -0,0 +1,19 @@
+using System;
+
+namespace simple.migrations
+{
+ public class RunMigrationsCommand : ConsoleCommand
+ {
+ public void run_against(ConsoleArguments arguments)
+ {
+ throw new NotImplementedException();
+ }
+
+ public bool can_handle(ConsoleArguments arguments)
+ {
+ return arguments.contains("migrations_dir")
+ && arguments.contains("connection_string")
+ && arguments.contains("data_provider");
+ }
+ }
+}
\ No newline at end of file
product/application.tests/application.tests.csproj
@@ -73,6 +73,7 @@
<Compile Include="ConsoleSpecs.cs" />
<Compile Include="EmptyTestFixture.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="RunMigrationsCommandSpecs.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\application\application.csproj">
product/application.tests/CommandRegistrySpecs.cs
@@ -7,48 +7,40 @@ namespace tests
{
public class CommandRegistrySpecs
{
- public class concern : observations_for_a_sut_with_a_contract<CommandRegistry, ConsoleArgumentsCommandRegistry>
+ public class when_commands_are_registered :
+ observations_for_a_sut_with_a_contract<CommandRegistry, ConsoleArgumentsCommandRegistry>
{
- }
-
- public class when_looking_up_the_appropriate_command_for_some_console_arguments : concern
- {
- it should_return_the_command_that_can_process_the_request = () => { result.should_be_equal_to(command); };
-
context c = () =>
{
- command = an<ConsoleCommand>();
- command.Stub(x => x.can_handle(arguments)).Return(true);
+ command = controller.an<ConsoleCommand>();
+ command.Stub(x => x.can_handle(correct_args)).Return(true);
};
- after_the_sut_has_been_created a = () => { sut.register(command); };
+ after_the_sut_has_been_created a = () => { controller.sut.register(command); };
- because b = () => { result = controller.sut.command_for(arguments); };
+ protected static readonly string[] correct_args = new[] {""};
+ protected static ConsoleCommand command;
+ }
- static readonly string[] arguments = new[] {""};
- static ParameterizedCommand<string[]> result;
- static ConsoleCommand command;
+ public class when_looking_up_the_appropriate_command_for_some_console_arguments : when_commands_are_registered
+ {
+ it should_return_the_command_that_can_process_the_request = () => { result.should_be_equal_to(command); };
+
+ because b = () => { result = controller.sut.command_for(correct_args); };
+
+ static ParameterizedCommand<ConsoleArguments> result;
}
public class when_attempting_to_find_a_command_that_can_process_a_set_of_arguments_that_is_not_recognized :
- concern
+ when_commands_are_registered
{
it should_return_a_command_that_can_inform_the_user_of_the_error =
() => { result.should_be_an_instance_of<HelpCommand>(); };
- context c = () =>
- {
- command = an<ConsoleCommand>();
- command.Stub(x => x.can_handle(arguments)).Return(false);
- };
-
- after_the_sut_has_been_created a = () => { sut.register(command); };
-
- because b = () => { result = controller.sut.command_for(arguments); };
+ because b = () => { result = controller.sut.command_for(unknown_args); };
- static readonly string[] arguments = new[] {""};
- static ParameterizedCommand<string[]> result;
- static ConsoleCommand command;
+ static readonly ConsoleArguments unknown_args = new[] {""};
+ static ParameterizedCommand<ConsoleArguments> result;
}
}
}
\ No newline at end of file
product/application.tests/ConsoleSpecs.cs
@@ -23,14 +23,14 @@ namespace tests
context c = () =>
{
console_arguments = new[] {""};
- correct_command = controller.an<ParameterizedCommand<string[]>>();
+ correct_command = controller.an<ParameterizedCommand<ConsoleArguments>>();
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;
+ static ParameterizedCommand<ConsoleArguments> correct_command;
}
}
}
\ No newline at end of file
product/application.tests/RunMigrationsCommandSpecs.cs
@@ -0,0 +1,30 @@
+using developwithpassion.bdd.contexts;
+using developwithpassion.bdd.harnesses.mbunit;
+using simple.migrations;
+
+namespace tests
+{
+ public class RunMigrationsCommandSpecs
+ {
+ public class when_checking_if_the_proper_console_arguments_are_specified_to_run_the_migrations :
+ observations_for_a_sut_with_a_contract<ConsoleCommand, RunMigrationsCommand>
+ {
+ context c = () =>
+ {
+ proper_arguments =
+ new[]
+ {
+ "-migrations_dir:'c:\\tmp' -connection_string:'Server=(local);Database=test;Integrated Security=True;' -data_provider:'System.Data.SqlClient'"
+ };
+ unknown_arguments = new[] {""};
+ };
+
+ it should_return_true_when_they_are = () => { sut.can_handle(proper_arguments).should_be_true(); };
+
+ it should_return_false_when_they_are_not = () => { sut.can_handle(unknown_arguments).should_be_false(); };
+
+ static ConsoleArguments proper_arguments;
+ static ConsoleArguments unknown_arguments;
+ }
+ }
+}
\ No newline at end of file