public void Execute_create_migration_table_and_update_filename_row(string connectionString, DatabaseProvider provider) { //Arrange const string table = "minimigTableTest5"; string filePath = $"SampleMigrations\\{provider}\\0001 - Add One and Two tables.sql"; var options = new Options() { ConnectionString = connectionString, Provider = provider, MigrationsTable = table }; var migration = new FakeMigration(filePath); var row = new FakeMigrationRow(migration.Filename, migration.Hash); const string dateFormat = "yyyy-MM-dd hh:mm"; //Act using var context = new ConnectionContext(options); context.Open(); context.CreateMigrationsTable(); context.InsertMigrationRecord(row); context.RenameMigration(migration); var ran = context.GetAlreadyRan(); context.DropMigrationsTable(); //Assert Assert.Equal(ConnectionState.Open, context.Connection.State); Assert.Equal(ran.Last.Hash, row.Hash); Assert.Equal(ran.Last.Id, row.Id); Assert.Equal(ran.Last.Filename, row.Filename); Assert.Equal(ran.Last.ExecutionDate.ToString(dateFormat), row.ExecutionDate.ToString(dateFormat)); Assert.Equal(ran.Last.Duration, row.Duration); }
public void Execute_create_migration_table_and_update_check_row(string connectionString, DatabaseProvider provider) { //Arrange const string table = "minimigTableTest4"; var options = new Options() { ConnectionString = connectionString, Provider = provider, MigrationsTable = table }; var row = new FakeMigrationRow(); const int newDuration = 20; string newHash = Guid.NewGuid().ToString(); const string dateFormat = "yyyy-MM-dd hh:mm"; //Act var context = new ConnectionContext(options); context.Open(); context.CreateMigrationsTable(); context.InsertMigrationRecord(row); row.Duration = newDuration; row.Hash = newHash; context.UpdateMigrationRecordHash(row); var ran = context.GetAlreadyRan(); context.DropMigrationsTable(); context.Dispose(); //Assert Assert.Equal(ConnectionState.Closed, context.Connection.State); Assert.Equal(ran.Last.Hash, row.Hash); Assert.Equal(ran.Last.Id, row.Id); Assert.Equal(ran.Last.Filename, row.Filename); Assert.Equal(ran.Last.ExecutionDate.ToString(dateFormat), row.ExecutionDate.ToString(dateFormat)); Assert.Equal(ran.Last.Duration, row.Duration); }
public void Execute_create_migration_table_and_insert_row(string connectionString, DatabaseProvider provider) { //Arrange const string table = "minimigTableTest2"; var options = new Options() { ConnectionString = connectionString, Provider = provider, MigrationsTable = table }; var row = new FakeMigrationRow(); //Act using var context = new ConnectionContext(options); context.Open(); context.CreateMigrationsTable(); bool exists = context.MigrationTableExists(); context.InsertMigrationRecord(row); context.DropMigrationsTable(); bool existsAfter = context.MigrationTableExists(); //Assert Assert.Equal(ConnectionState.Open, context.Connection.State); Assert.True(exists); Assert.False(existsAfter); }
public void Execute_create_and_drop_schema_table(string connectionString, DatabaseProvider provider) { //Arrange const string schema = "minimigtest2"; const string table = "minimigtabletest"; var options = new Options() { ConnectionString = connectionString, Provider = provider, MigrationsTableSchema = schema, MigrationsTable = table }; //Act using var context = new ConnectionContext(options); context.Open(); context.BeginTransaction(); context.ExecuteCommand($"Create schema {schema}"); context.Commit(); bool existsSchema = context.SchemaMigrationExists(); context.CreateMigrationsTable(); bool existsTable = context.SchemaMigrationExists(); //Clean Up context.DropMigrationsTable(); context.ExecuteCommand($"Drop schema {schema}"); context.Dispose(); //Assert Assert.Equal(ConnectionState.Closed, context.Connection.State); Assert.True(existsSchema); Assert.True(existsTable); }
public void Update_migration_without_record(string connectionString, DatabaseProvider provider) { //Arrange var options = new Options() { ConnectionString = connectionString, Provider = provider }; var row = new FakeMigrationRow(); //Act using var context = new ConnectionContext(options); context.Open(); context.CreateMigrationsTable(); void action() => context.UpdateMigrationRecordHash(row); //Assert Assert.Throws <Exception>(action); //Cleanup context.DropMigrationsTable(); }
public void Rename_migration_without_record(string connectionString, DatabaseProvider provider) { //Arrange string filePath = $"SampleMigrations\\{provider}\\0001 - Add One and Two tables.sql"; var options = new Options() { ConnectionString = connectionString, Provider = provider }; var migration = new FakeMigration(filePath); //Act using var context = new ConnectionContext(options); context.Open(); context.CreateMigrationsTable(); void action() => context.RenameMigration(migration); //Assert Assert.Throws <Exception>(action); //Cleanup context.DropMigrationsTable(); }
public void Execute_create_and_drop_migration_table(string connectionString, DatabaseProvider provider) { //Arrange var options = new Options() { ConnectionString = connectionString, Provider = provider }; //Act using var context = new ConnectionContext(options); context.Open(); context.CreateMigrationsTable(); bool exists = context.MigrationTableExists(); context.DropMigrationsTable(); bool existsAfter = context.MigrationTableExists(); //Assert Assert.Equal(ConnectionState.Open, context.Connection.State); Assert.True(exists); Assert.False(existsAfter); }