public void InstallServices(IServiceCollection services, IConfiguration configuration, IWebHostEnvironment env, ILogger logger) { var sapServerSettings = new SapServerSettings(); configuration.Bind(nameof(SapServerSettings), sapServerSettings); var sapContextOptions = new SapContextOptions { DiApiServerConnection = sapServerSettings.SapServerDiAPi, SapSqlServerOptions = new DbContextOptionsBuilder <SapSqlDbContext>() .UseSqlServer(sapServerSettings.SapServerSql) // .EnableSensitiveDataLogging() .Options, ExtrasServerOptions = new DbContextOptionsBuilder <RalDbContext>() .UseSqlServer(sapServerSettings.IamServerSql) // .EnableSensitiveDataLogging() .Options }; services.AddSingleton(sapContextOptions); services.AddSingleton <IUnitOfWork, SapUnitOfWork>(); SapUnitOfWork.CurrentProvider = services.BuildServiceProvider(); services.AddSingleton <IDalService, DalService>(); //for migration and identity services.AddDbContext <RalDbContext>(builder => builder .UseSqlServer(sapServerSettings.IamServerSql) .EnableSensitiveDataLogging()); services.AddIdentityCore <IdentityUser>() .AddEntityFrameworkStores <RalDbContext>() .AddDefaultTokenProviders(); }
protected RepositoryTests(DatabaseFixture fixture) { var webHost = WebHost.CreateDefaultBuilder() .UseEnvironment("SapIntegrationTesting") .UseStartup <Startup>() .Build(); var configuration = (IConfiguration)webHost.Services.GetService(typeof(IConfiguration)); var settings = new TestSettings(); configuration.Bind(nameof(TestSettings), settings); var sapServerSettings = new SapServerSettings(); configuration.Bind(nameof(SapServerSettings), sapServerSettings); fixture.SetBackupPath(settings.SqlBackupPath); DalService = (IDalService)webHost.Services.GetService(typeof(IDalService)); //Clear tests after dispose fixture.SetConnectionString(sapServerSettings.SapServerSql); fixture.BackupDatabase(); fixture.RestoreDatabaseOnDispose(true); }