private static async Task Create_creates_physical_database_but_not_tables_test(bool async) { using (var testDatabase = SqlServerTestStore.CreateScratch(createDatabase: false)) { var creator = SqlServerDatabaseCreatorTest.GetDatabaseCreator(testDatabase); Assert.False(creator.Exists()); if (async) { await creator.CreateAsync(); } else { creator.Create(); } Assert.True(creator.Exists()); if (testDatabase.Connection.State != ConnectionState.Open) { await testDatabase.Connection.OpenAsync(); } Assert.Equal(0, (await testDatabase.QueryAsync <string>("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'")).Count()); Assert.True( await testDatabase.ExecuteScalarAsync <bool>( string.Concat( "SELECT is_read_committed_snapshot_on FROM sys.databases WHERE name='", testDatabase.Connection.Database, "'"))); } }
private static async Task HasTables_returns_true_when_database_exists_and_has_any_tables_test(bool async) { using (var testDatabase = SqlServerTestStore.CreateScratch(createDatabase: true)) { await testDatabase.ExecuteNonQueryAsync("CREATE TABLE SomeTable (Id uniqueidentifier)"); var creator = SqlServerDatabaseCreatorTest.GetDatabaseCreator(testDatabase); Assert.True(async ? await((SqlServerDatabaseCreatorTest.TestDatabaseCreator)creator).HasTablesAsyncBase() : ((SqlServerDatabaseCreatorTest.TestDatabaseCreator)creator).HasTablesBase()); } }
private static async Task HasTables_returns_false_when_database_exists_but_has_no_tables_test(bool async) { using (var testDatabase = SqlServerTestStore.CreateScratch(createDatabase: true)) { var creator = SqlServerDatabaseCreatorTest.GetDatabaseCreator(testDatabase); Assert.False( async ? await((SqlServerDatabaseCreatorTest.TestDatabaseCreator)creator).HasTablesAsyncBase() : ((SqlServerDatabaseCreatorTest.TestDatabaseCreator)creator).HasTablesBase()); } }
private static async Task Create_throws_if_database_already_exists_test(bool async) { using (var testDatabase = SqlServerTestStore.CreateScratch(createDatabase: true)) { var creator = SqlServerDatabaseCreatorTest.GetDatabaseCreator(testDatabase); var ex = async ? await Assert.ThrowsAsync <SqlException>(() => creator.CreateAsync()) : Assert.Throws <SqlException>(() => creator.Create()); Assert.Equal( 1801, // Database with given name already exists ex.Number); } }
private static async Task Delete_throws_when_database_doesnt_exist_test(bool async) { using (var testDatabase = SqlServerTestStore.CreateScratch(createDatabase: false)) { var creator = SqlServerDatabaseCreatorTest.GetDatabaseCreator(testDatabase); if (async) { await Assert.ThrowsAsync <SqlException>(() => creator.DeleteAsync()); } else { Assert.Throws <SqlException>(() => creator.Delete()); } } }
private static async Task CreateTables_throws_if_database_does_not_exist_test(bool async) { using (var testDatabase = SqlServerTestStore.CreateScratch(createDatabase: false)) { var creator = SqlServerDatabaseCreatorTest.GetDatabaseCreator(testDatabase); var errorNumber = async ? (await Assert.ThrowsAsync <SqlException>(() => creator.CreateTablesAsync())).Number : Assert.Throws <SqlException>(() => creator.CreateTables()).Number; if (errorNumber != 233) // skip if no-process transient failure { Assert.Equal( 4060, // Login failed error number errorNumber); } } }
private static async Task HasTables_throws_when_database_doesnt_exist_test(bool async) { using (var testDatabase = SqlServerTestStore.CreateScratch(createDatabase: false)) { await((SqlServerDatabaseCreatorTest.TestDatabaseCreator)SqlServerDatabaseCreatorTest.GetDatabaseCreator(testDatabase)).ExecutionStrategyFactory.Create() .ExecuteAsync( async creator => { var errorNumber = async ? (await Assert.ThrowsAsync <SqlException>(() => creator.HasTablesAsyncBase())).Number : Assert.Throws <SqlException>(() => creator.HasTablesBase()).Number; if (errorNumber != 233) // skip if no-process transient failure { Assert.Equal( 4060, // Login failed error number errorNumber); } }, (SqlServerDatabaseCreatorTest.TestDatabaseCreator)SqlServerDatabaseCreatorTest.GetDatabaseCreator(testDatabase)); } }
private static async Task Delete_will_delete_database_test(bool async) { using (var testDatabase = SqlServerTestStore.CreateScratch(createDatabase: true)) { testDatabase.Connection.Close(); var creator = SqlServerDatabaseCreatorTest.GetDatabaseCreator(testDatabase); Assert.True(async ? await creator.ExistsAsync() : creator.Exists()); if (async) { await creator.DeleteAsync(); } else { creator.Delete(); } Assert.False(async ? await creator.ExistsAsync() : creator.Exists()); } }