Пример #1
0
        private static void CreateTestStore <TContext>(
            string databaseName,
            IServiceProvider serviceProvider,
            Func <IServiceProvider, DbContextOptions, TContext> contextCreator,
            Action <TContext> contextInitializer)
            where TContext : DbContext, IDisposable
        {
            var connectionString = SqlServerTestStore.CreateConnectionString(databaseName);

            SqlServerTestStore.GetOrCreateShared(databaseName, () =>
            {
                var optionsBuilder = new DbContextOptionsBuilder();
                optionsBuilder.UseSqlServer(connectionString);

                using (var context = contextCreator(serviceProvider, optionsBuilder.Options))
                {
                    if (context.Database.EnsureCreated())
                    {
                        contextInitializer(context);
                    }

                    TestSqlLoggerFactory.SqlStatements.Clear();
                }
            });
        }
Пример #2
0
 public virtual void CreateDatabase()
 {
     SqlServerTestStore.GetOrCreateShared(DatabaseName, () =>
     {
         using (var context = new ChipsContext(ServiceProvider))
         {
             context.Database.EnsureClean();
         }
     });
 }
Пример #3
0
 protected override void CreateAndSeedDatabase(string databaseName, Func <MonsterContext> createContext, Action <MonsterContext> seed)
 {
     _testStore = SqlServerTestStore.GetOrCreateShared(databaseName, () =>
     {
         using (var context = createContext())
         {
             context.Database.EnsureCreated();
             seed(context);
         }
     });
 }
 public ExecutionStrategyTest(ExecutionStrategyFixture fixture)
 {
     Fixture   = fixture;
     TestStore = SqlServerTestStore.GetOrCreateShared(DatabaseName, () =>
     {
         using (var context = CreateContext())
         {
             context.Database.EnsureCreated();
         }
     });
 }
 public override SqlServerTestStore CreateTestStore()
 {
     return(SqlServerTestStore.GetOrCreateShared(DatabaseName, () =>
     {
         using (var context = new FindContext(_options))
         {
             context.Database.EnsureCreated();
             Seed(context);
         }
     }));
 }
            public override SqlServerTestStore CreateTestStore()
            => SqlServerTestStore.GetOrCreateShared(DatabaseName, () =>
            {
                var optionsBuilder = new DbContextOptionsBuilder()
                                     .UseSqlServer(SqlServerTestStore.CreateConnectionString(DatabaseName), b => b.ApplyConfiguration())
                                     .UseInternalServiceProvider(_serviceProvider);

                using (var context = new AdvancedPatternsMasterContext(optionsBuilder.Options))
                {
                    context.Database.EnsureCreated();
                    Seed(context);
                }
            });
            public override SqlServerTestStore CreateTestStore()
            {
                return(SqlServerTestStore.GetOrCreateShared(DatabaseName, () =>
                {
                    var optionsBuilder = new DbContextOptionsBuilder()
                                         .UseSqlServer(SqlServerTestStore.CreateConnectionString(DatabaseName), b => { b.ApplyConfiguration(); })
                                         .UseInternalServiceProvider(_serviceProvider);

                    using (var context = new StoreGeneratedContext(optionsBuilder.Options))
                    {
                        context.Database.EnsureCreated();
                    }
                }));
            }
Пример #8
0
            public override SqlServerTestStore CreateTestStore()
            {
                return(SqlServerTestStore.GetOrCreateShared(DatabaseName, () =>
                {
                    var optionsBuilder = new DbContextOptionsBuilder();
                    optionsBuilder.UseSqlServer(SqlServerTestStore.CreateConnectionString(DatabaseName));

                    using (var context = new StoreGeneratedContext(_serviceProvider, optionsBuilder.Options))
                    {
                        context.Database.EnsureDeleted();
                        context.Database.EnsureCreated();
                    }
                }));
            }
            public NullKeysSqlServerFixture()
            {
                var name             = "StringsContext";
                var connectionString = SqlServerTestStore.CreateConnectionString(name);

                _options = new DbContextOptionsBuilder()
                           .UseSqlServer(connectionString, b => b.ApplyConfiguration())
                           .UseInternalServiceProvider(new ServiceCollection()
                                                       .AddEntityFrameworkSqlServer()
                                                       .AddSingleton(TestSqlServerModelSource.GetFactory(OnModelCreating))
                                                       .BuildServiceProvider())
                           .Options;

                _testStore = SqlServerTestStore.GetOrCreateShared(name, EnsureCreated);
            }
Пример #10
0
            public override SqlServerTestStore CreateTestStore()
            {
                return(SqlServerTestStore.GetOrCreateShared(DatabaseName, () =>
                {
                    var optionsBuilder = new DbContextOptionsBuilder()
                                         .UseSqlServer(SqlServerTestStore.CreateConnectionString(DatabaseName))
                                         .UseInternalServiceProvider(_serviceProvider);

                    using (var context = new GraphUpdatesContext(optionsBuilder.Options))
                    {
                        context.Database.EnsureClean();
                        Seed(context);
                    }
                }));
            }
            public override SqlServerTestStore CreateTestStore()
            {
                var testStore = SqlServerTestStore.GetOrCreateShared(DatabaseName, () =>
                {
                    var options = new DbContextOptionsBuilder()
                                  .UseSqlServer(SqlServerTestStore.CreateConnectionString(DatabaseName), b => b.ApplyConfiguration())
                                  .UseInternalServiceProvider(_serviceProvider)
                                  .Options;

                    using (var context = new GraphUpdatesContext(options))
                    {
                        context.Database.EnsureCreated();
                        Seed(context);
                    }
                });

                _options = new DbContextOptionsBuilder()
                           .UseSqlServer(testStore.Connection, b => b.ApplyConfiguration())
                           .UseInternalServiceProvider(_serviceProvider)
                           .Options;

                return(testStore);
            }
 public virtual SqlServerTestStore CreateDatabase() => SqlServerTestStore.GetOrCreateShared("CommandConfiguration", null);
Пример #13
0
 public override SqlServerTestStore CreateTestStore()
 => SqlServerTestStore.GetOrCreateShared(DatabaseName, EnsureCreated);