public void DropTable_Always_Drops() { using (_mocks.Record()) { SetupResult.For(_databaseProvider.ExecuteNonQuery("DROP TABLE {0}", "TheTable")).Return(true); } _target.DropTable("TheTable"); }
public void SetMigrationVersionUnapplied(long version, string scope) { if (string.IsNullOrEmpty(scope)) { _databaseProvider.ExecuteNonQuery("DELETE FROM {0} WHERE {1} = {2} AND {3} IS NULL", TableName, VersionColumnName, version, ScopeColumnName); } else { _databaseProvider.ExecuteNonQuery("DELETE FROM {0} WHERE {1} = {2} AND {3} = '{4}'", TableName, VersionColumnName, version, ScopeColumnName, scope); } }
public void AddColumn(string table, string column, Type type, short size, bool allowNull, object currentValue) { _schemaProvider.AddColumn(table, column, type, size, false, true); if (currentValue != null) { _databaseProvider.ExecuteNonQuery("UPDATE {0} SET {1} = '{2}'", table, column, currentValue); } if (!allowNull) { _schemaProvider.ChangeColumn(table, column, type, 0, allowNull); } }
public void SetMigrationVersionUnapplied_Always_NukesRow() { long version = 1; using (_mocks.Record()) { SetupResult.For(_databaseProvider.ExecuteNonQuery( "DELETE FROM {0} WHERE {1} = {2} AND {3} IS NULL", "schema_info", "version", version, "scope")).Return(true); } _target.SetMigrationVersionUnapplied(version, null); _mocks.VerifyAll(); }
public void AddTable(string table, ICollection <Column> columns) { if (columns.Count == 0) { throw new ArgumentException("columns"); } var sb = new StringBuilder(); sb.Append("CREATE TABLE ").Append(table).Append(" ("); var first = true; foreach (var column in columns) { if (!first) { sb.Append(","); } sb.AppendLine().Append(ColumnToCreateTableSql(column)); first = false; } foreach (var column in columns) { var sql = ColumnToConstraintsSql(table, column); if (sql != null) { sb.Append(",").AppendLine().Append(sql); } } sb.AppendLine().Append(")"); _databaseProvider.ExecuteNonQuery(sb.ToString()); }
public void Up_does_not_execute_a_query_when_Up_script_is_not_provided() { _target = new SqlScriptMigration("", ""); _target.Initialize(_mockedMigrationContext); using (_mocks.Record()) { Expect.Call(_dbProvider.ExecuteNonQuery("")).IgnoreArguments().Repeat.Never(); } using (_mocks.Playback()) { _target.Up(); } _mocks.VerifyAll(); }
public void AddColumn_WithCurrentValues_AddsAndUpdatesAndAlters() { using (_mocks.Record()) { _schemaProvider.AddColumn("TheTable", "TheColumn", typeof(Int32), 0, false, true); Expect.Call(_databaseProvider.ExecuteNonQuery("UPDATE {0} SET {1} = '{2}'", "TheTable", "TheColumn", 1)).Return( true); _schemaProvider.ChangeColumn("TheTable", "TheColumn", typeof(Int32), 0, false); } _target.AddColumn("TheTable", "TheColumn", typeof(Int32), 0, false, 1); _mocks.VerifyAll(); }