private void PrepareDatabase() { var ct = CancellationToken.None; using (var connection = new SqlConnection(ConnectionString)) using (var context = new MigratorTestContext(connection)) { var manager = new SqlServerMigrationManager <MigratorTestContext>( context, new DefaultNamingNormalizer <MigratorTestContext>(), LoggingManager.LoggerFactory); manager.PrepareDatabaseAsync(ct) .ConfigureAwait(false) .GetAwaiter() .GetResult(); string migrationId; string className; MigrationsTestHelper.GenerateMigrationInfo( DateTimeOffset.UtcNow, out migrationId, out className); // Existing static migration manager.AddMigrationAsync(migrationId, className, null, ct) .ConfigureAwait(false) .GetAwaiter() .GetResult(); } }
public ExistingDatabaseFixture() : base( "Data Source=.; Initial Catalog=master; Integrated Security=True; Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;MultipleActiveResultSets=True;App=SimpleSoft.Database.Migrator.Tests.SqlServer", "Data Source=.; Initial Catalog=MigratorTest; Integrated Security=True; Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;MultipleActiveResultSets=True;App=SimpleSoft.Database.Migrator.Tests.SqlServer", "MigratorTest") { PrepareDatabase(); Context = new MigratorTestContext(Connection); Manager = new SqlServerMigrationManager <MigratorTestContext>( Context, new DefaultNamingNormalizer <MigratorTestContext>(), LoggingManager.LoggerFactory); }
/// <inheritdoc /> protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing) { Context?.Dispose(); } Manager = null; Context = null; }
public void GivenANewManagerWhenPassingNullParametersThenArgumentNullExceptionMustBeThrown() { SqlServerMigrationManager <SqlServerMigratorTestContext> manager; Assert.Throws <ArgumentNullException>(() => { manager = new SqlServerMigrationManager <SqlServerMigratorTestContext>(null, LoggingManager.LoggerFactory); Assert.NotNull(manager); }); manager = new SqlServerMigrationManager <SqlServerMigratorTestContext>(_fixture.Context); Assert.NotNull(manager); }
public async Task GivenAnEmptyDatabaseWhenPreparingForMigrationsThenATableMustBeCreated() { var ct = CancellationToken.None; var manager = new SqlServerMigrationManager <SqlServerMigratorTestContext>( _fixture.Context, LoggingManager.LoggerFactory); await manager.PrepareDatabaseAsync(ct); var tableId = await _fixture.Context.RunAsync(async() => await _fixture.Context.QuerySingleAsync <long>(@" select count(*) as Total from ( select -- making sure all columns exist ContextName, MigrationId, ClassName, Description, AppliedOn from __DbMigratorHistory ) V", ct: ct), true, ct); Assert.Equal(0L, tableId); }
public void GivenANewManagerWhenPassingNullParametersThenArgumentNullExceptionMustBeThrown() { Assert.Throws <ArgumentNullException>(() => { var manager = new SqlServerMigrationManager <MigratorTestContext>( null, new DefaultNamingNormalizer <MigratorTestContext>(), LoggingManager.LoggerFactory); Assert.NotNull(manager); }); Assert.Throws <ArgumentNullException>(() => { var manager = new SqlServerMigrationManager <MigratorTestContext>( _fixture.Context, null, LoggingManager.LoggerFactory); Assert.NotNull(manager); }); Assert.Throws <ArgumentNullException>(() => { var manager = new SqlServerMigrationManager <MigratorTestContext>( _fixture.Context, new DefaultNamingNormalizer <MigratorTestContext>(), null); Assert.NotNull(manager); }); }
private void PrepareDatabase() { var ct = CancellationToken.None; using (var context = new SqlServerMigratorTestContext(Options)) { var manager = new SqlServerMigrationManager <SqlServerMigratorTestContext>(context, LoggingManager.LoggerFactory); manager.PrepareDatabaseAsync(ct) .ConfigureAwait(false) .GetAwaiter() .GetResult(); MigrationsTestHelper.GenerateMigrationInfo( DateTimeOffset.UtcNow, out var migrationId, out var className); // Existing static migration manager.AddMigrationAsync(migrationId, className, null, ct) .ConfigureAwait(false) .GetAwaiter() .GetResult(); } }