Exemplo n.º 1
0
 public async Task Returns_true_when_database_exists_and_has_any_tables(bool async, bool ambientTransaction)
 {
     using (var testDatabase = SqlServerTestStore.GetOrCreate("ExistingTables")
                               .InitializeSqlServer(null, t => new BloggingContext(t), null))
     {
         var creator = GetDatabaseCreator(testDatabase);
         using (CreateTransactionScope(ambientTransaction))
         {
             Assert.True(async ? await creator.HasTablesAsyncBase() : creator.HasTablesBase());
         }
     }
 }
Exemplo n.º 2
0
    public async Task Throws_when_database_does_not_exist(bool async)
    {
        using var testDatabase = SqlServerTestStore.GetOrCreate("NonExistingBlogging");
        var creator = GetDatabaseCreator(testDatabase);

        if (async)
        {
            await Assert.ThrowsAsync <SqlException>(() => creator.DeleteAsync());
        }
        else
        {
            Assert.Throws <SqlException>(() => creator.Delete());
        }
    }
Exemplo n.º 3
0
    public async Task Throws_if_database_does_not_exist(bool async)
    {
        using var testDatabase = SqlServerTestStore.GetOrCreate("NonExisting");
        var creator = 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);
        }
    }
Exemplo n.º 4
0
        public async Task Creates_physical_database_but_not_tables(bool async, bool ambientTransaction)
        {
            using (var testDatabase = SqlServerTestStore.GetOrCreate("CreateTest"))
            {
                var creator = GetDatabaseCreator(testDatabase);

                creator.EnsureDeleted();

                await GetExecutionStrategy(testDatabase).ExecuteAsync(
                    async() =>
                {
                    using (CreateTransactionScope(ambientTransaction))
                    {
                        if (async)
                        {
                            await creator.CreateAsync();
                        }
                        else
                        {
                            creator.Create();
                        }
                    }
                });

                Assert.True(creator.Exists());

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

                Assert.Empty(
                    (await testDatabase.QueryAsync <string>(
                         "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'")));

                Assert.True(
                    await testDatabase.ExecuteScalarAsync <bool>(
                        string.Concat(
                            "SELECT is_read_committed_snapshot_on FROM sys.databases WHERE name='",
                            testDatabase.Name,
                            "'")));
            }
        }
Exemplo n.º 5
0
        public async Task Throws_when_database_does_not_exist(bool async)
        {
            using (var testDatabase = SqlServerTestStore.GetOrCreate("NonExisting"))
            {
                var databaseCreator = GetDatabaseCreator(testDatabase);
                await databaseCreator.ExecutionStrategyFactory.Create().ExecuteAsync(
                    databaseCreator,
                    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);
                    }
                });
            }
        }
Exemplo n.º 6
0
 public override TestStore GetOrCreate(string storeName)
 => SqlServerTestStore.GetOrCreate(Name, "Northwind.sql");
Exemplo n.º 7
0
 public override TestStore GetOrCreate(string storeName)
 => SqlServerTestStore.GetOrCreate(storeName, scriptPath: null, multipleActiveResultSets: true);
 public override TestStore GetOrCreate(string storeName)
 => SqlServerTestStore.GetOrCreate(Name, "Northwind.sql", multipleActiveResultSets: true);