Example #1
0
        private static async Task RunDatabaseCreationTest(SqlServerTestDatabase testDatabase, bool async)
        {
            using (var context = new BloggingContext(testDatabase))
            {
                Assert.Equal(ConnectionState.Closed, context.Database.AsRelational().Connection.DbConnection.State);

                if (async)
                {
                    Assert.True(await context.Database.AsRelational().EnsureCreatedAsync());
                }
                else
                {
                    Assert.True(context.Database.AsRelational().EnsureCreated());
                }

                Assert.Equal(ConnectionState.Closed, context.Database.AsRelational().Connection.DbConnection.State);

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

                var tables = await testDatabase.QueryAsync <string>("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES");

                Assert.Equal(1, tables.Count());
                Assert.Equal("Blog", tables.Single());

                var columns = (await testDatabase.QueryAsync <string>(
                                   "SELECT TABLE_NAME + '.' + COLUMN_NAME + ' (' + DATA_TYPE + ')' FROM INFORMATION_SCHEMA.COLUMNS")).ToArray();
                Assert.Equal(19, columns.Length);

                Assert.Equal(
                    new[]
                {
                    "Blog.Key1 (nvarchar)",
                    "Blog.Key2 (varbinary)",
                    "Blog.AndChew (varbinary)",
                    "Blog.AndRow (timestamp)",
                    "Blog.Cheese (nvarchar)",
                    "Blog.CupOfChar (int)",
                    "Blog.ErMilan (int)",
                    "Blog.Fuse (smallint)",
                    "Blog.George (bit)",
                    "Blog.NotFigTime (datetime2)",
                    "Blog.NotToEat (smallint)",
                    "Blog.On (real)",
                    "Blog.OrNothing (float)",
                    "Blog.OrULong (int)",
                    "Blog.OrUShort (numeric)",
                    "Blog.OrUSkint (bigint)",
                    "Blog.TheGu (uniqueidentifier)",
                    "Blog.ToEat (tinyint)",
                    "Blog.WayRound (bigint)"
                },
                    columns);
            }
        }