Ejemplo n.º 1
0
        private static async Task Creates_physical_database_but_not_tables_test(bool async)
        {
            using (var testDatabase = OracleTestStore.CreateScratch(createDatabase: false))
            {
                var creator = OracleDatabaseCreatorTest.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 user_tables")).Count());
            }
        }
Ejemplo n.º 2
0
        private static async Task Noop_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());

                    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);
                }
            }
        }
Ejemplo n.º 3
0
        private static async Task Delete_database_test(bool async, bool open)
        {
            using (var testDatabase = OracleTestStore.CreateScratch(createDatabase: true))
            {
                if (!open)
                {
                    testDatabase.Connection.Close();
                }

                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);
                }
            }
        }
Ejemplo n.º 4
0
 private static async Task Returns_false_when_database_exists_but_has_no_tables_test(bool async)
 {
     using (var testDatabase = OracleTestStore.CreateScratch())
     {
         var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(testDatabase);
         Assert.False(async ? await creator.HasTablesAsyncBase() : creator.HasTablesBase());
     }
 }
Ejemplo n.º 5
0
        private static async Task Creates_schema_in_existing_database_test(bool async)
        {
            using (var testDatabase = OracleTestStore.CreateScratch())
            {
                using (var context = new OracleDatabaseCreatorTest.BloggingContext(testDatabase))
                {
                    var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(context);

                    if (async)
                    {
                        await creator.CreateTablesAsync();
                    }
                    else
                    {
                        creator.CreateTables();
                    }

                    if (testDatabase.Connection.State != ConnectionState.Open)
                    {
                        await testDatabase.Connection.OpenAsync();
                    }

                    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 (BLOB)",
                        "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);
                }
            }
        }
Ejemplo n.º 6
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());
            }
        }
Ejemplo n.º 7
0
        private static async Task Returns_true_when_database_exists_test(bool async)
        {
            using (var testDatabase = OracleTestStore.CreateScratch(createDatabase: true))
            {
                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);
                }
            }
        }
Ejemplo n.º 8
0
        private static async Task Throws_if_database_already_exists_test(bool async)
        {
            using (var testDatabase = OracleTestStore.CreateScratch())
            {
                var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(testDatabase);

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

                Assert.Equal(
                    1920, // User with given name already exists
                    ex.Number);
            }
        }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
0
        private static async Task Throws_when_database_does_not_exist_test(bool async)
        {
            using (var testDatabase = OracleTestStore.CreateScratch(createDatabase: false))
            {
                var creator = OracleDatabaseCreatorTest.GetDatabaseCreator(testDatabase);

                if (async)
                {
                    await Assert.ThrowsAsync <OracleException>(() => creator.DeleteAsync());
                }
                else
                {
                    Assert.Throws <OracleException>(() => creator.Delete());
                }
            }
        }
Ejemplo n.º 11
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);
                });
            }
        }
Ejemplo n.º 12
0
        private static async Task Deletes_database_test(bool async)
        {
            using (var testDatabase = OracleTestStore.CreateScratch())
            {
                testDatabase.Connection.Close();

                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());
            }
        }