public BloggingContext(SqlServerTestDatabase testDatabase)
     : base(CreateServiceProvider())
 {
     _testDatabase = testDatabase;
 }
 private static SqlServerDataStoreCreator GetDataStoreCreator(SqlServerTestDatabase testDatabase)
 {
     return CreateConfiguration(testDatabase).Services.ServiceProvider.GetService<SqlServerDataStoreCreator>();
 }
        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.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.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);
            }
        }
 private static DbContextConfiguration CreateConfiguration(SqlServerTestDatabase testDatabase)
 {
     var serviceCollection = new ServiceCollection();
     serviceCollection.AddEntityFramework().AddSqlServer();
     return new DbContext(
         serviceCollection.BuildServiceProvider(),
         new DbContextOptions().UseSqlServer(testDatabase.Connection.ConnectionString))
         .Configuration;
 }