main
1using developwithpassion.bdd.contexts;
2using developwithpassion.bdd.harnesses.mbunit;
3using developwithpassion.bdd.mocking.rhino;
4using developwithpassion.bdddoc.core;
5using gorilla.migrations;
6using gorilla.migrations.data;
7using gorilla.migrations.io;
8using tests.helpers;
9
10namespace tests.core
11{
12 public class RunMigrationsCommandSpecs
13 {
14 public class concern : observations_for_a_sut_with_a_contract<ConsoleCommand, RunMigrationsCommand>
15 {
16 context c = () =>
17 {
18 file_system = controller.the_dependency<FileSystem>();
19 database_gateway_factory = controller.the_dependency<DatabaseGatewayFactory>();
20 };
21
22 static protected FileSystem file_system;
23 static protected DatabaseGatewayFactory database_gateway_factory;
24 }
25
26 [Concern(typeof (RunMigrationsCommand))]
27 public class when_the_proper_arguments_are_specified_to_run_the_database_migrations : concern
28 {
29 context c = () =>
30 {
31 proper_arguments =
32 new[]
33 {
34 "-migrations_dir:'c:\\tmp' -connection_string:'Server=(local);Database=test;Integrated Security=True;' -data_provider:'System.Data.SqlClient'"
35 };
36 };
37
38 because b = () =>
39 {
40 result = controller.sut.can_handle(proper_arguments);
41 };
42
43 it should_recognize_the_arguments = () => result.should_be_true();
44
45 static ConsoleArguments proper_arguments;
46 static bool result;
47 }
48
49 [Concern(typeof (RunMigrationsCommand))]
50 public class when_unknown_arguments_are_specified : concern
51 {
52 context c = () =>
53 {
54 unknown_arguments = new[] {""};
55 };
56
57 because b = () =>
58 {
59 result = controller.sut.can_handle(unknown_arguments);
60 };
61
62 it should_not_recognize_the_arguments_to_run_the_database_migrations = () => result.should_be_false();
63
64 static ConsoleArguments unknown_arguments;
65
66 static bool result;
67 }
68
69 [Concern(typeof (RunMigrationsCommand))]
70 public class When_the_migrations_command_is_run : concern
71 {
72 context c = () =>
73 {
74 old_migration = controller.an<SqlFile>();
75 new_migration = controller.an<SqlFile>();
76 arguments = controller.an<ConsoleArguments>();
77 gateway = controller.an<DatabaseGateway>();
78
79 database_gateway_factory
80 .is_told_to(x => x.gateway_to("blah=blah;", "System.Data.SqlClient"))
81 .it_will_return(gateway);
82 file_system
83 .is_told_to(x => x.all_sql_files_from("c:\\tmp"))
84 .it_will_return(old_migration, new_migration);
85
86 arguments.is_told_to(x => x.parse_for("migrations_dir")).it_will_return("c:\\tmp");
87 arguments.is_told_to(x => x.parse_for("connection_string")).it_will_return("blah=blah;");
88 arguments.is_told_to(x => x.parse_for("data_provider")).it_will_return("System.Data.SqlClient");
89 };
90
91 because b = () =>
92 {
93 controller.sut.run_against(arguments);
94 };
95
96 it should_run_each_migration_script = () =>
97 {
98 gateway.received(x => x.run(new_migration));
99 };
100
101 static SqlFile new_migration;
102 static SqlFile old_migration;
103 static ConsoleArguments arguments;
104 static DatabaseGateway gateway;
105 }
106 }
107}