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_physical_database_but_not_tables_test(bool async)
        {
            using (var testDatabase = OracleTestStore.GetOrCreate("CreateTest"))
            {
                var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(testDatabase);

                creator.EnsureDeleted();

                if (async)
                {
                    await creator.CreateAsync();
                }
                else
                {
                    creator.Create();
                }

                Assert.True(creator.Exists());

                if (testDatabase.ConnectionState != ConnectionState.Open)
                {
                    await testDatabase.OpenConnectionAsync();
                }

                Assert.Equal(
                    0, (await testDatabase.QueryAsync <string>(
                            "SELECT table_name FROM user_tables")).Count());
            }
        }
 private static async Task Returns_false_when_database_exists_but_has_no_tables_test(bool async)
 {
     using (var testDatabase = OracleTestStore.GetOrCreateInitialized("Empty"))
     {
         var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(testDatabase);
         Assert.False(async ? await creator.HasTablesAsyncBase() : creator.HasTablesBase());
     }
 }
        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_true_when_database_exists_and_has_any_tables_test(bool async)
 {
     using (var testDatabase = OracleTestStore.GetOrCreate("ExistingTables")
                               .InitializeOracle(null, t => new OracleDatabaseCreatorTest.BloggingContext(t), null))
     {
         var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(testDatabase);
         Assert.True(async ? await creator.HasTablesAsyncBase() : creator.HasTablesBase());
     }
 }
示例#7
0
        private static async Task Returns_true_when_database_exists_and_has_any_tables_test(bool async)
        {
            using (var testDatabase = OracleTestStore.CreateScratch())
            {
                await testDatabase.ExecuteNonQueryAsync("CREATE TABLE SomeTable (Id NUMBER)");

                var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(testDatabase);
                Assert.True(async ? await creator.HasTablesAsyncBase() : creator.HasTablesBase());
            }
        }
示例#8
0
        public void Throws_when_no_user_id()
        {
            var connectionStringBuilder = new OracleConnectionStringBuilder(TestEnvironment.DefaultConnection);

            connectionStringBuilder.Remove("User Id");

            var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(connectionStringBuilder.ToString());

            var ex = Assert.Throws <InvalidOperationException>(() => creator.Delete());

            Assert.Equal(OracleStrings.NoUserId, ex.Message);
        }
示例#9
0
        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);
                }
            }
        }
        private static async Task Throws_if_database_already_exists_test(bool async)
        {
            using (var testDatabase = OracleTestStore.GetOrCreateInitialized("ExistingBlogging"))
            {
                var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(testDatabase);

                var ex = async
                    ? await Assert.ThrowsAsync <OracleException>(() => creator.CreateAsync())
                    : Assert.Throws <OracleException>(() => creator.Create());

                Assert.Equal(
                    1920, // Database with given name already exists
                    ex.Number);
            }
        }
示例#12
0
        private static async Task Throws_if_database_does_not_exist_test(bool async)
        {
            using (var testDatabase = OracleTestStore.CreateScratch(createDatabase: false))
            {
                var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(testDatabase);

                var errorNumber
                    = async
                        ? (await Assert.ThrowsAsync <OracleException>(() => creator.CreateTablesAsync())).Number
                        : Assert.Throws <OracleException>(() => creator.CreateTables()).Number;

                Assert.Equal(
                    1017, // Login failed error number
                    errorNumber);
            }
        }
        private static async Task Throws_when_database_does_not_exist_test(bool async)
        {
            using (var testDatabase = OracleTestStore.GetOrCreate("NonExistingBlogging"))
            {
                var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(testDatabase);

                if (async)
                {
                    await Assert.ThrowsAsync <OracleException>(() => creator.DeleteAsync());
                }
                else
                {
                    Assert.Throws <OracleException>(() => creator.Delete());
                }
            }
        }
        private static async Task Throws_if_database_does_not_exist_test(bool async)
        {
            using (var testDatabase = OracleTestStore.GetOrCreate("NonExisting"))
            {
                var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(testDatabase);

                var errorNumber
                    = async
                        ? (await Assert.ThrowsAsync <OracleException>(() => creator.CreateTablesAsync())).Number
                        : Assert.Throws <OracleException>(() => creator.CreateTables()).Number;

                if (errorNumber != 233) // skip if no-process transient failure
                {
                    Assert.Equal(
                        1017, // Login failed error number
                        errorNumber);
                }
            }
        }
示例#15
0
        private static async Task Throws_when_database_does_not_exist_test(bool async)
        {
            using (var testDatabase = OracleTestStore.CreateScratch(createDatabase: false))
            {
                var databaseCreator = OracleDatabaseCreatorTest.GetDatabaseCreator(testDatabase);

                await databaseCreator.ExecutionStrategyFactory.Create().ExecuteAsync(
                    databaseCreator,
                    async creator =>
                {
                    var errorNumber = async
                                ? (await Assert.ThrowsAsync <OracleException>(() => creator.HasTablesAsyncBase())).Number
                                : Assert.Throws <OracleException>(() => creator.HasTablesBase()).Number;

                    Assert.Equal(
                        1017,         // Login failed error number
                        errorNumber);
                });
            }
        }
        private static async Task Throws_when_database_does_not_exist_test(bool async)
        {
            using (var testDatabase = OracleTestStore.GetOrCreate("NonExisting"))
            {
                var databaseCreator = OracleDatabaseCreatorTest.GetDatabaseCreator(testDatabase);
                await databaseCreator.ExecutionStrategyFactory.Create().ExecuteAsync(
                    databaseCreator,
                    async creator =>
                {
                    var errorNumber = async
                                ? (await Assert.ThrowsAsync <OracleException>(() => creator.HasTablesAsyncBase())).Number
                                : Assert.Throws <OracleException>(() => creator.HasTablesBase()).Number;

                    if (errorNumber != 233)         // skip if no-process transient failure
                    {
                        Assert.Equal(
                            1017,         // Login failed error number
                            errorNumber);
                    }
                });
            }
        }
        private static async Task Deletes_database_test(bool async)
        {
            using (var testDatabase = OracleTestStore.CreateInitialized("DeleteBlogging"))
            {
                testDatabase.CloseConnection();

                var creator = OracleDatabaseCreatorTest.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());
            }
        }