Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public void Check_migration_row_count()
        {
            //Arrange
            var row = new FakeMigrationRow();
            var ran = new FakeAlreadyRan(row);

            //Act
            int count = ran.Count;

            //Assert
            Assert.Equal(1, count);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public void Check_if_migration_row_already_ran_last()
        {
            //Arrange
            var row = new FakeMigrationRow();
            var ran = new FakeAlreadyRan(row);

            //Act
            var found = ran.Last;

            //Assert
            Assert.Equal(row.Id, found.Id);
            Assert.Equal(row.Hash, found.Hash);
            Assert.Equal(row.Filename, found.Filename);
            Assert.Equal(row.Duration, found.Duration);
            Assert.Equal(row.ExecutionDate, found.ExecutionDate);
        }
Exemplo n.º 8
0
        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();
        }