private void GivenADatabase(string context) { _contextOptions = MockDatabaseHelper.CreateNewContextOptions(context); _appContext = new CustomerCentreDbContext(_contextOptions); _settings = Substitute.For <IOptions <DbContextSettings> >(); _settings.Value.Returns(new DbContextSettings { CustomerCentreConnectionString = "test" }); _dbContextFactory = Substitute.For <IDbContextFactory>(); _dbContextFactory.DbContext.Returns(_appContext); _subject = new CustomerRepository(_dbContextFactory, Substitute.For <ILogger>()); }
/// <summary> /// Create Db context with connection string /// </summary> /// <param name="settings"></param> public DbContextFactory(IOptions <DbContextSettings> settings) { var options = new DbContextOptionsBuilder <CustomerCentreDbContext>().UseSqlServer(settings.Value.CustomerCentreConnectionString).Options; DbContext = new CustomerCentreDbContext(options); }