public void ExtraFiles_Excluded() { // Arrange string filename = "somefilename"; string hash = "somehash"; // This one matches, and shouldn't show in the results MigrationHistory expectedMigration = new MigrationHistory { Filename = filename, FileHash = hash, }; List<MigrationHistory> source = new List<MigrationHistory> { expectedMigration }; List<MigrationFile> fileMigrations = new List<MigrationFile> { // This one matches new MigrationFile { Filename = filename, FileHash = hash }, // This one doesn't match new MigrationFile { Filename = "anotherfile", FileHash = "anotherhash" } }; List<MigrationHistory> expectedResults = new List<MigrationHistory>(); // empty // Act App app = this.MockServiceLocator.Get<App>(); List<MigrationHistory> actualResults = app.MigrationsToRemove( source, fileMigrations ); // Assert Assert.That( actualResults, Is.Not.Null ); Assert.That( actualResults, Is.EquivalentTo( expectedResults ) ); }
/// <returns>The SQL that was executed (roughly)</returns> public string AddMigration( string ConnectionString, MigrationHistory Migration ) { string query = "INSERT INTO dbo.MigrationHistory ( [Filename], [FileHash], [ExecutionDate], [Version], [DownScript] ) VALUES ( @Filename, @FileHash, @ExecutionDate, @Version, @DownScript )"; List<IDataParameter> parameters = new List<IDataParameter> { new SqlParameter( "@Filename", SqlDbType.NVarChar, 255 ) { Value = Migration.Filename }, new SqlParameter( "@FileHash", SqlDbType.NVarChar, 32 ) { Value = Migration.FileHash }, new SqlParameter( "@ExecutionDate", Migration.ExecutionDate ), new SqlParameter( "@Version", SqlDbType.NVarChar, 40 ) { Value = Migration.Version }, new SqlParameter( "@DownScript", SqlDbType.NVarChar ) { Value = Migration.DownScript } }; this.sqlHelper.ExecuteQueryToFunc( ConnectionString, query, Parameters: parameters, Map: cmd => cmd.ExecuteNonQuery() ); string results = query .Replace( "@Filename", this.sqlHelper.SqlEscapeParameter( Migration.Filename ) ) .Replace( "@FileHash", this.sqlHelper.SqlEscapeParameter( Migration.FileHash ) ) .Replace( "@ExecutionDate", this.sqlHelper.SqlEscapeParameter( Migration.ExecutionDate.ToString("G") ) ) .Replace( "@Version", this.sqlHelper.SqlEscapeParameter( Migration.Version ) ) .Replace( "@DownScript", this.sqlHelper.SqlEscapeParameter( Migration.DownScript ) ); return results; }
public void DifferentHash_Included() { // Arrange string filename = "somefilename"; string hash = "somehash"; MigrationHistory expectedMigration = new MigrationHistory { Filename = filename, FileHash = hash, }; List<MigrationHistory> source = new List<MigrationHistory> { expectedMigration }; List<MigrationFile> fileMigrations = new List<MigrationFile> { // This one doesn't match by hash new MigrationFile { Filename = filename, FileHash = hash+"doesn'tmatch" } }; List<MigrationHistory> expectedResults = new List<MigrationHistory> { expectedMigration }; // Act App app = this.MockServiceLocator.Get<App>(); List<MigrationHistory> actualResults = app.MigrationsToRemove( source, fileMigrations ); // Assert Assert.That( actualResults, Is.Not.Null ); Assert.That( actualResults, Is.EquivalentTo( expectedResults ) ); }
/// <returns>The SQL that was executed (roughly)</returns> public string RemoveMigration( string ConnectionString, MigrationHistory Migration ) { string query = "DELETE FROM dbo.MigrationHistory WHERE Filename = @Filename"; List<IDataParameter> parameters = new List<IDataParameter> { new SqlParameter( "@Filename", SqlDbType.NVarChar, 255 ) { Value = Migration.Filename } }; this.sqlHelper.ExecuteQueryToFunc( ConnectionString, query, Parameters: parameters, Map: cmd => cmd.ExecuteNonQuery() ); string results = query .Replace( "@Filename", this.sqlHelper.SqlEscapeParameter( Migration.Filename ) ); return results; }