Commit 88902e4
Changed files (6)
product
application
application.tests
product/application/data/SqlFile.cs
@@ -1,4 +1,37 @@
namespace simple.migrations.Data
{
- public class SqlFile {}
+ public class SqlFile
+ {
+ public virtual string path { get; set; }
+
+ static public implicit operator SqlFile(string file_path)
+ {
+ return new SqlFile {path = file_path};
+ }
+
+ public bool Equals(SqlFile other)
+ {
+ if (ReferenceEquals(null, other)) return false;
+ if (ReferenceEquals(this, other)) return true;
+ return Equals(other.path, path);
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ if (ReferenceEquals(this, obj)) return true;
+ if (obj.GetType() != typeof (SqlFile)) return false;
+ return Equals((SqlFile) obj);
+ }
+
+ public override int GetHashCode()
+ {
+ return (path != null ? path.GetHashCode() : 0);
+ }
+
+ public override string ToString()
+ {
+ return path;
+ }
+ }
}
\ No newline at end of file
product/application/io/WindowsFileSystem.cs
@@ -0,0 +1,17 @@
+using System.Collections.Generic;
+using System.IO;
+using simple.migrations.Data;
+
+namespace simple.migrations.io
+{
+ public class WindowsFileSystem : FileSystem
+ {
+ public IEnumerable<SqlFile> all_sql_files_from(string directory)
+ {
+ foreach (var file in Directory.GetFiles(directory, "*.sql", SearchOption.AllDirectories))
+ {
+ yield return file;
+ }
+ }
+ }
+}
\ No newline at end of file
product/application/application.csproj
@@ -57,6 +57,7 @@
<Compile Include="data\SqlFile.cs" />
<Compile Include="HelpCommand.cs" />
<Compile Include="io\FileSystem.cs" />
+ <Compile Include="io\WindowsFileSystem.cs" />
<Compile Include="ParameterizedCommand.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RunMigrationsCommand.cs" />
product/application.tests/io/WindowsFileSystemSpecs.cs
@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using developwithpassion.bdd.contexts;
+using developwithpassion.bdd.harnesses.mbunit;
+using developwithpassion.bdddoc.core;
+using simple.migrations.Data;
+using simple.migrations.io;
+
+namespace tests.io
+{
+ public class WindowsFileSystemSpecs
+ {
+ public abstract class concern : observations_for_a_sut_with_a_contract<FileSystem, WindowsFileSystem> {}
+
+ [Concern(typeof (WindowsFileSystem))]
+ public class when_retrieving_all_the_sql_migrations_scripts_from_a_directory : concern
+ {
+ context c = () =>
+ {
+ var directory = Path.Combine(Environment.CurrentDirectory, "sample_files");
+ first_sql_file = Path.Combine(directory, "0001_first_test_file.sql");
+ second_sql_file = Path.Combine(directory, "0002_first_test_file.sql");
+ template_file = Path.Combine(directory, "0001_first_test_file.sql.template");
+ };
+
+ because b = () =>
+ {
+ results = sut.all_sql_files_from("sample_files");
+ };
+
+ it should_return_each_sql_file_found_in_the_directory = () =>
+ {
+ results.Count().should_be_equal_to(2);
+ results.should_contain(second_sql_file);
+ results.should_contain(first_sql_file);
+ };
+
+ it should_not_return_any_other_types_of_files = () =>
+ {
+ results.should_not_contain(template_file);
+ };
+
+ static IEnumerable<SqlFile> results;
+ static SqlFile first_sql_file;
+ static SqlFile second_sql_file;
+ static SqlFile template_file;
+ }
+ }
+}
\ No newline at end of file
product/application.tests/sample_files/0001_first_test_file.sql.template
@@ -0,0 +1,1 @@
+
\ No newline at end of file
product/application.tests/application.tests.csproj
@@ -74,6 +74,7 @@
<Compile Include="ConsoleSpecs.cs" />
<Compile Include="EmptyTestFixture.cs" />
<Compile Include="helpers\RhinoStubbingExtensions.cs" />
+ <Compile Include="io\WindowsFileSystemSpecs.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RunMigrationsCommandSpecs.cs" />
</ItemGroup>
@@ -83,6 +84,20 @@
<Name>application</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <None Include="sample_files\0001_first_test_file.sql">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="sample_files\0001_first_test_file.sql.template">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </None>
+ <None Include="sample_files\0002_second_sql_file.sql">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </None>
+ </ItemGroup>
+ <ItemGroup>
+ <Folder Include="data\" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.