public async Task ApplyMigratonsFromDefaultAssembly_ExpectsOk() { using (var sp = CreateServiceProvider()) { var ctx = sp.GetRequiredService <TestContext>(); ctx.Database.CreateIfNotExists(); var migrator = new DataMigrator(ctx, new DataMigrationOptions()); await migrator.MigrateAsync(); var applied = await migrator.GetAppliedMigrationsAsync(); Assert.Equal(new[] { nameof(D0000001_InitialDataMigration), AddDummyCustomer.MigrationId }, applied); } }
public async Task ApplyMigratonsWithSurroundingTransactionRollback_ExpectsEmptyDb() { using (var sp = CreateServiceProvider()) { var ctx = sp.GetRequiredService <TestContext>(); ctx.Database.Create(); var migrator = new DataMigrator(ctx, new DataMigrationOptions()); using (var transaction = ctx.Database.BeginTransaction()) { await migrator.MigrateAsync(); } var applied = await migrator.GetAppliedMigrationsAsync(); Assert.Empty(applied); } }
public async Task ApplyMigratonsWithSurroundingTransaction_ExpectsOk() { using (var sp = CreateServiceProvider()) { var ctx = sp.GetRequiredService <TestContext>(); ctx.Database.Create(); var migrator = new DataMigrator(ctx, new DataMigrationOptions()); using (var transaction = ctx.Database.BeginTransaction()) { await migrator.MigrateAsync(); transaction.Commit(); } var applied = await migrator.GetAppliedMigrationsAsync(); Assert.Equal(new[] { nameof(D0000001_InitialDataMigration), AddDummyCustomer.MigrationId }, applied); } }
public async Task ApplyMigratonsFromExternalAssembly_ExpectsOk() { using (var sp = CreateServiceProvider()) { var ctx = sp.GetRequiredService <TestContext>(); ctx.Database.CreateIfNotExists(); var migrator = new DataMigrator(ctx, new DataMigrationOptions { MigrationAssembly = "Extensions.EntityFramework.Migration" }); await migrator.MigrateAsync(); var applied = await migrator.GetAppliedMigrationsAsync(); var data = await ctx.Currencies.ToListAsync(); Assert.Equal(new[] { nameof(ExternalMigration) }, applied); Assert.Single(data); Assert.Equal("CHF", data[0].IsoCode); } }
public async Task ApplyMigratonsFromDefaultAndExternalAssembly_ExpectsOk() { using (var sp = CreateServiceProvider()) { var ctx = sp.GetRequiredService <TestContext>(); ctx.Database.CreateIfNotExists(); var migrator = new DataMigrator(ctx, new DataMigrationOptions()); await migrator.MigrateAsync(); var migratorExternal = new DataMigrator(ctx, new DataMigrationOptions { MigrationAssembly = "Extensions.EntityFramework.Migration" }); await migratorExternal.MigrateAsync(); var applied = await migrator.GetAppliedMigrationsAsync(); applied = applied.Concat(await migratorExternal.GetAppliedMigrationsAsync()); Assert.Equal(new[] { nameof(D0000001_InitialDataMigration), AddDummyCustomer.MigrationId, nameof(ExternalMigration) }, applied); } }