Beispiel #1
0
        private static async Task RunDatabaseCreationTest(SqlServerTestStore testStore, bool async)
        {
            using (var context = new BloggingContext(testStore))
            {
                var creator = context.GetService <IRelationalDatabaseCreator>();

                Assert.Equal(ConnectionState.Closed, context.Database.GetDbConnection().State);

                if (async)
                {
                    Assert.True(await creator.EnsureCreatedAsync());
                }
                else
                {
                    Assert.True(creator.EnsureCreated());
                }

                Assert.Equal(ConnectionState.Closed, context.Database.GetDbConnection().State);

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

                var tables = await testStore.QueryAsync <string>("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'");

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

                var columns = (await testStore.QueryAsync <string>(
                                   "SELECT TABLE_NAME + '.' + COLUMN_NAME + ' (' + DATA_TYPE + ')' FROM INFORMATION_SCHEMA.COLUMNS  WHERE TABLE_NAME = 'Blog' ORDER BY TABLE_NAME, COLUMN_NAME")).ToArray();
                Assert.Equal(15, columns.Length);

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