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);
        }
Beispiel #2
0
        public void Check_migration_exception(string filePath)
        {
            //Arrange
            const string modified = "has been modified since it was run";
            var          mig      = new FakeMigration(filePath);

            //Act
            var exception = new MigrationChangedException(mig);

            //Assert
            Assert.Contains(modified, exception.Message);
            Assert.Contains(mig.Filename, exception.Message);
        }
Beispiel #3
0
        public void Get_migration_mode_run_has_mismatch(string filepath, string key, string filename)
        {
            //Arrange
            var row = new FakeMigrationRow(filename, key);
            var ran = new FakeAlreadyRan(row);

            //Act
            var migration = new FakeMigration(Path.Combine(filepath, filename));
            var mode      = migration.GetMigrateMode(ran);

            //Assert
            Assert.Equal(MigrateMode.HashMismatch, mode);
        }
Beispiel #4
0
        public void Get_migration_mode_run_renamed(string filepath, string key, string filename)
        {
            //Arrange
            var row = new FakeMigrationRow(filename, key);
            var ran = new FakeAlreadyRan(row);

            //Act
            var migration = new FakeMigration(filepath);
            var mode      = migration.GetMigrateMode(ran);

            //Assert
            Assert.Equal(MigrateMode.Rename, mode);
        }
Beispiel #5
0
        public void Get_migration_no_transaction(string filepath)
        {
            //Arrange
            string filename = Path.GetFileName(filepath);

            //Act
            var migration = new FakeMigration(filepath);

            //Assert
            Assert.Equal(migration.Filename, filename);
            Assert.True(Guid.TryParse(migration.Hash, out _));
            Assert.False(migration.UseTransaction);
        }
        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();
        }