private static async Task Delete_database_test(bool async, bool open) { using (var testDatabase = OracleTestStore.CreateInitialized("EnsureDeleteBlogging")) { if (!open) { testDatabase.CloseConnection(); } using (var context = new OracleDatabaseCreatorTest.BloggingContext(testDatabase)) { var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(context); Assert.True(async ? await creator.ExistsAsync() : creator.Exists()); if (async) { Assert.True(await context.Database.EnsureDeletedAsync()); } else { Assert.True(context.Database.EnsureDeleted()); } Assert.Equal(ConnectionState.Closed, context.Database.GetDbConnection().State); Assert.False(async ? await creator.ExistsAsync() : creator.Exists()); Assert.Equal(ConnectionState.Closed, context.Database.GetDbConnection().State); } } }
private static async Task Noop_when_database_does_not_exist_test(bool async) { using (var testDatabase = OracleTestStore.Create("NonExisting")) { using (var context = new OracleDatabaseCreatorTest.BloggingContext(testDatabase)) { var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(context); Assert.False(async ? await creator.ExistsAsync() : creator.Exists()); if (async) { Assert.False(await creator.EnsureDeletedAsync()); } else { Assert.False(creator.EnsureDeleted()); } Assert.Equal(ConnectionState.Closed, context.Database.GetDbConnection().State); Assert.False(async ? await creator.ExistsAsync() : creator.Exists()); Assert.Equal(ConnectionState.Closed, context.Database.GetDbConnection().State); } } }
private static async Task Creates_schema_in_existing_database_test(bool async) { using (var testDatabase = OracleTestStore.GetOrCreateInitialized("ExistingBlogging" + (async ? "Async" : ""))) { using (var context = new OracleDatabaseCreatorTest.BloggingContext(testDatabase)) { var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(context); if (async) { await creator.CreateTablesAsync(); } else { creator.CreateTables(); } if (testDatabase.ConnectionState != ConnectionState.Open) { await testDatabase.OpenConnectionAsync(); } var tables = (await testDatabase.QueryAsync <string>( "SELECT table_name FROM user_tables")).ToList(); Assert.Equal(1, tables.Count); Assert.Equal("Blogs", tables.Single()); var columns = (await testDatabase.QueryAsync <string>( "SELECT table_name || '.' || column_name || ' (' || data_type || ')' " + "FROM user_tab_columns WHERE table_name = 'Blogs' " + "ORDER BY table_name, column_name")).ToArray(); Assert.Equal(14, columns.Length); Assert.Equal( new[] { "Blogs.AndChew (BLOB)", "Blogs.AndRow (RAW)", "Blogs.Cheese (NVARCHAR2)", "Blogs.ErMilan (NUMBER)", "Blogs.Fuse (NUMBER)", "Blogs.George (NUMBER)", "Blogs.Key1 (NVARCHAR2)", "Blogs.Key2 (RAW)", "Blogs.NotFigTime (TIMESTAMP(6))", "Blogs.On (FLOAT)", "Blogs.OrNothing (FLOAT)", "Blogs.TheGu (RAW)", "Blogs.ToEat (NUMBER)", "Blogs.WayRound (NUMBER)" }, columns); } } }
private static async Task Returns_false_when_database_does_not_exist_test(bool async) { using (var testDatabase = OracleTestStore.CreateScratch(createDatabase: false)) { using (var context = new OracleDatabaseCreatorTest.BloggingContext(testDatabase)) { var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(context); Assert.False(async ? await creator.ExistsAsync() : creator.Exists()); Assert.Equal(ConnectionState.Closed, context.Database.GetDbConnection().State); } } }
private static async Task Returns_true_when_database_exists_test(bool async) { using (var testDatabase = OracleTestStore.GetOrCreateInitialized("ExistingBlogging")) { using (var context = new OracleDatabaseCreatorTest.BloggingContext(testDatabase)) { var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(context); Assert.True(async ? await creator.ExistsAsync() : creator.Exists()); Assert.Equal(ConnectionState.Closed, context.Database.GetDbConnection().State); } } }