public async Task CanCreateAndDropSchema(bool isDatabaseMissing) { using TestDatabase testDb = this.CreateTestDb(!isDatabaseMissing); IOrchestrationService service = this.CreateServiceWithTestDb(testDb); // Create the DB schema for the first time await service.CreateAsync(recreateInstanceStore : true); LogAssert.NoWarningsOrErrors(this.logProvider); LogAssert .For(this.logProvider) .Expect( LogAssert.CheckedDatabase()) .ExpectIf( isDatabaseMissing, LogAssert.CommandCompleted($"CREATE DATABASE [{testDb.Name}]"), LogAssert.CreatedDatabase(testDb.Name)) .Expect( LogAssert.AcquiredAppLock(), LogAssert.ExecutedSqlScript("drop-schema.sql"), LogAssert.ExecutedSqlScript("schema-0.2.0.sql"), LogAssert.ExecutedSqlScript("logic.sql"), LogAssert.ExecutedSqlScript("permissions.sql"), LogAssert.SprocCompleted("dt._UpdateVersion")) .EndOfLog(); ValidateDatabaseSchema(testDb); // Create the DB schema again - should be a no-op since it already exists this.logProvider.Clear(); await service.CreateIfNotExistsAsync(); ValidateDatabaseSchema(testDb); // The subsequent execution should run exactly one sproc and no scripts. // It's important to verify this to ensure the overhead of CreateIfNotExistsAsync is very small. LogAssert.NoWarningsOrErrors(this.logProvider); LogAssert.Sequence( this.logProvider, LogAssert.CheckedDatabase(), LogAssert.AcquiredAppLock(), LogAssert.SprocCompleted("dt._GetVersions")); // Delete the database and validate this.logProvider.Clear(); await service.DeleteAsync(); LogAssert.NoWarningsOrErrors(this.logProvider); LogAssert.Sequence( this.logProvider, LogAssert.AcquiredAppLock(), LogAssert.ExecutedSqlScript("drop-schema.sql")); // The previous schema validation ensures all objects are in the "dt" schema. // We know that all objects were successfully removed if the "dt" no longer exists. Assert.DoesNotContain("dt", testDb.GetSchemas()); }
public Task CreateAsync() { return(_innerOrchestrationService.CreateAsync()); }