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); } }
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; }
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(); } })); }
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); }
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); }
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; }
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); }
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); }
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(); }
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; }
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); }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder .UseInternalServiceProvider(_serviceProvider) .UseSqlServer(SqlServerTestStore.CreateConnectionString(_databaseName), b => b.ApplyConfiguration());
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseSqlServer(SqlServerTestStore.CreateConnectionString($"Seeds{TestId}"));