public NotificationEntitiesSqlServerFixture()
 {
     _options = new DbContextOptionsBuilder()
                .UseSqlServer(SqlServerTestStore.CreateConnectionString(DatabaseName), b => b.ApplyConfiguration())
                .UseInternalServiceProvider(new ServiceCollection()
                                            .AddEntityFrameworkSqlServer()
                                            .AddSingleton(TestModelSource.GetFactory(OnModelCreating))
                                            .BuildServiceProvider(validateScopes: true))
                .Options;
 }
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     if (UseSqlServer)
     {
         optionsBuilder.UseSqlServer(SqlServerTestStore.CreateConnectionString(StoreName), b => b.ApplyConfiguration());
     }
     else
     {
         optionsBuilder.UseInMemoryDatabase(StoreName);
     }
 }
Exemplo n.º 3
0
        public SqlAzureFixture()
        {
            SqlServerTestStore.CreateDatabase("adventureworks", scriptPath: "SqlAzure/adventureworks.sql", nonMasterScript: true);

            Services = new ServiceCollection()
                       .AddEntityFrameworkSqlServer()
                       .AddSingleton <ILoggerFactory>(new TestSqlLoggerFactory()).BuildServiceProvider();

            Options = new DbContextOptionsBuilder()
                      .UseInternalServiceProvider(Services)
                      .EnableSensitiveDataLogging()
                      .UseSqlServer(SqlServerTestStore.CreateConnectionString("adventureworks")).Options;
        }
            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 FindSqlServerFixture()
            {
                var serviceProvider = new ServiceCollection()
                                      .AddEntityFrameworkSqlServer()
                                      .AddSingleton(TestModelSource.GetFactory(OnModelCreating))
                                      .AddSingleton <ILoggerFactory>(TestSqlLoggerFactory)
                                      .BuildServiceProvider(validateScopes: true);

                _options = new DbContextOptionsBuilder()
                           .UseSqlServer(SqlServerTestStore.CreateConnectionString(DatabaseName), b => b.ApplyConfiguration())
                           .UseInternalServiceProvider(serviceProvider)
                           .EnableSensitiveDataLogging()
                           .Options;
            }
Exemplo n.º 6
0
            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();
                    }
                }));
            }
Exemplo n.º 7
0
        public void Connect_with_encryption(bool encryptionEnabled)
        {
            var connectionStringBuilder =
                new SqlConnectionStringBuilder(SqlServerTestStore.CreateConnectionString("adventureworks"))
            {
                Encrypt = encryptionEnabled
            };
            var options = new DbContextOptionsBuilder();

            options.UseSqlServer(connectionStringBuilder.ConnectionString, b => b.ApplyConfiguration());

            using var context = new AdventureWorksContext(options.Options);
            context.Database.OpenConnection();
            Assert.Equal(ConnectionState.Open, context.Database.GetDbConnection().State);
        }
Exemplo n.º 8
0
            public NullKeysSqlServerFixture()
            {
                var name             = "StringsContext";
                var connectionString = SqlServerTestStore.CreateConnectionString(name);

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

                _testStore = SqlServerTestStore.GetOrCreateShared(name, EnsureCreated);
            }
Exemplo n.º 9
0
        public SqlAzureFixture()
        {
            SqlServerTestStore.GetOrCreateShared(
                "adventureworks",
                () => SqlServerTestStore.ExecuteScript("adventureworks", "SqlAzure/adventureworks.sql"),
                cleanDatabase: false);

            Services = new ServiceCollection()
                       .AddEntityFrameworkSqlServer()
                       .AddSingleton <ILoggerFactory>(new TestSqlLoggerFactory()).BuildServiceProvider();

            Options = new DbContextOptionsBuilder()
                      .UseInternalServiceProvider(Services)
                      .EnableSensitiveDataLogging()
                      .UseSqlServer(SqlServerTestStore.CreateConnectionString("adventureworks"), b => b.ApplyConfiguration()).Options;
        }
Exemplo n.º 10
0
    private static byte GetProductMajorVersion()
    {
        if (_productMajorVersion.HasValue)
        {
            return(_productMajorVersion.Value);
        }

        using var sqlConnection = new SqlConnection(SqlServerTestStore.CreateConnectionString("master"));
        sqlConnection.Open();

        using var command = new SqlCommand(
                  "SELECT SERVERPROPERTY('ProductVersion');", sqlConnection);
        _productMajorVersion = (byte)Version.Parse((string)command.ExecuteScalar()).Major;

        return(_productMajorVersion.Value);
    }
Exemplo n.º 11
0
    private static int GetEngineEdition()
    {
        if (_engineEdition.HasValue)
        {
            return(_engineEdition.Value);
        }

        using var sqlConnection = new SqlConnection(SqlServerTestStore.CreateConnectionString("master"));
        sqlConnection.Open();

        using var command = new SqlCommand(
                  "SELECT SERVERPROPERTY('EngineEdition');", sqlConnection);
        _engineEdition = (int)command.ExecuteScalar();

        return(_engineEdition.Value);
    }
Exemplo n.º 12
0
        public SqlAzureFixture()
        {
            SqlServerTestStore.CreateDatabase("adventureworks", scriptPath: "SqlAzure/adventureworks.sql", recreateIfAlreadyExists: false);

            var optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.EnableSensitiveDataLogging()
            .UseSqlServer(SqlServerTestStore.CreateConnectionString("adventureworks"));
            Options = optionsBuilder.Options;

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddEntityFramework()
            .AddSqlServer();
            serviceCollection.AddSingleton <ILoggerFactory>(new TestSqlLoggerFactory());
            Services = serviceCollection.BuildServiceProvider();
        }
Exemplo n.º 13
0
            public ExecutionStrategyFixture()
            {
                var serviceProvider = new ServiceCollection()
                                      .AddEntityFrameworkSqlServer()
                                      .AddSingleton <ILoggerFactory>(TestSqlLoggerFactory)
                                      .AddScoped <ISqlServerConnection, TestSqlServerConnection>()
                                      .AddScoped <IRelationalCommandBuilderFactory, TestRelationalCommandBuilderFactory>()
                                      .BuildServiceProvider();

                _baseOptions = new DbContextOptionsBuilder()
                               .UseInternalServiceProvider(serviceProvider)
                               .EnableSensitiveDataLogging()
                               .Options;

                _options = new DbContextOptionsBuilder(_baseOptions)
                           .UseSqlServer(SqlServerTestStore.CreateConnectionString(DatabaseName), ApplySqlServerOptions)
                           .Options;
            }
Exemplo n.º 14
0
        public SqlAzureFixture()
        {
            SqlServerTestStore.GetOrCreateShared(
                "adventureworks",
                () => SqlServerTestStore.ExecuteScript(
                    "adventureworks",
                    Path.Combine(
                        Path.GetDirectoryName(typeof(SqlAzureFixture).GetTypeInfo().Assembly.Location),
                        "SqlAzure",
                        "adventureworks.sql")),
                cleanDatabase: false);

            Services = new ServiceCollection()
                       .AddEntityFrameworkSqlServer()
                       .AddSingleton <ILoggerFactory>(TestSqlLoggerFactory).BuildServiceProvider();

            Options = new DbContextOptionsBuilder()
                      .UseInternalServiceProvider(Services)
                      .EnableSensitiveDataLogging()
                      .UseSqlServer(SqlServerTestStore.CreateConnectionString("adventureworks"), b => b.ApplyConfiguration()).Options;
        }
            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);
            }
Exemplo n.º 16
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 => optionsBuilder
 .UseInternalServiceProvider(_serviceProvider)
 .UseSqlServer(SqlServerTestStore.CreateConnectionString(_databaseName), b => b.ApplyConfiguration());
Exemplo n.º 17
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 => optionsBuilder.UseSqlServer(SqlServerTestStore.CreateConnectionString($"Seeds{TestId}"));