コード例 #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);
        }
コード例 #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);
        }