// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); string featureBitsConnectionString = Configuration.GetConnectionString(FeatureBitsDbConnectionStringKey); services.AddDbContext <FeatureBitsEfDbContext>(options => options.UseSqlServer(featureBitsConnectionString)); services.AddTransient <IFeatureBitsRepo, FeatureBitsEfRepo>((serviceProvider) => { DbContextOptionsBuilder <FeatureBitsEfDbContext> options = new DbContextOptionsBuilder <FeatureBitsEfDbContext>(); options.UseSqlServer(featureBitsConnectionString); var context = new FeatureBitsEfDbContext(options.Options); return(new FeatureBitsEfRepo(context)); }); services.AddTransient <IFeatureBitEvaluator, FeatureBitEvaluator>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
public FeatureBitsEfRepoTests() { Tuple <FeatureBitsEfDbContext, DbContextOptions <FeatureBitsEfDbContext> > testConfig = FeatureBitEfHelper.SetupDbContext(); _context = testConfig.Item1; _options = testConfig.Item2; _it = new FeatureBitsEfRepo(_context); }
public static Tuple <FeatureBitsEfDbContext, DbContextOptions <FeatureBitsEfDbContext> > SetupDbContext() { string guidDbNameForUniqueness = Guid.NewGuid().ToString(); DbContextOptions <FeatureBitsEfDbContext> options = new DbContextOptionsBuilder <FeatureBitsEfDbContext>() .UseInMemoryDatabase(guidDbNameForUniqueness) .EnableSensitiveDataLogging(false) .Options; var dbContext = new FeatureBitsEfDbContext(options); return(new Tuple <FeatureBitsEfDbContext, DbContextOptions <FeatureBitsEfDbContext> >(dbContext, options)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { string featureBitsConnectionString = Configuration.GetConnectionString("FeatureBitsDbContext"); services.AddDbContext <FeatureBitsEfDbContext>(options => options.UseSqlServer(featureBitsConnectionString)); services.AddTransient <IFeatureBitsRepo, FeatureBitsEfRepo>((serviceProvider) => { DbContextOptionsBuilder <FeatureBitsEfDbContext> options = new DbContextOptionsBuilder <FeatureBitsEfDbContext>(); options.UseSqlServer(featureBitsConnectionString); var context = new FeatureBitsEfDbContext(options.Options); return(new FeatureBitsEfRepo(context)); }); services.AddTransient <IFeatureBitEvaluator, FeatureBitEvaluator>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
public async Task ItCanRemoveIFeatureBitDefinitions() { // Arrange var entities = AddThreeDefinitions(); var entityToRemove = entities[1].Entity; // Act await _it.RemoveAsync(entityToRemove); // Assert using (var context = new FeatureBitsEfDbContext(_options)) { context.FeatureBitDefinitions.Count().Should().Be(2); context.FeatureBitDefinitions.Should().NotContain(f => f.Name == "item2"); } }
static void Main() { BootstrapConfiguration(); string connStr = _configuration[ConnectionSecretName]; DbContextOptionsBuilder <FeatureBitsEfDbContext> options = new DbContextOptionsBuilder <FeatureBitsEfDbContext>(); options.UseSqlServer(connStr); using (var context = new FeatureBitsEfDbContext(options.Options)) { var count = context.FeatureBitDefinitions.Count(); Console.WriteLine(count); } Console.ReadKey(); }
public async Task ItCanAddIFeatureBitDefinitions() { // Arrange var item1 = new FeatureBitEfDefinition { Name = "item1", CreatedByUser = "******", LastModifiedByUser = "******" }; // Act IFeatureBitDefinition result = await _it.AddAsync(item1); // Assert result.Name.Should().Be("item1"); result.Id.Should().NotBe(0); using (var context = new FeatureBitsEfDbContext(_options)) { context.FeatureBitDefinitions.Should().Contain(f => f.Name == "item1"); } }
public async Task ItCanUpdateIFeatureBitDefinitions() { // Arrange var entities = AddThreeDefinitions(); var defToUpdate = entities[1].Entity; defToUpdate.AllowedUsers = "Updated Value"; // Act await _it.UpdateAsync(defToUpdate); // Assert using (var context = new FeatureBitsEfDbContext(_options)) { context.FeatureBitDefinitions.Count().Should().Be(3); context.FeatureBitDefinitions.Should().Contain(f => f.AllowedUsers == "Updated Value"); } }
private static IFeatureBitsRepo GetCorrectRepository(CommonOptions opts) { IFeatureBitsRepo repo; bool useTable = string.IsNullOrEmpty(opts.DatabaseConnectionString); var dbConnStr = useTable ? opts.AzureTableConnectionString : opts.DatabaseConnectionString; if (!useTable) { DbContextOptionsBuilder <FeatureBitsEfDbContext> options = new DbContextOptionsBuilder <FeatureBitsEfDbContext>(); options.UseSqlServer(dbConnStr); var context = new FeatureBitsEfDbContext(options.Options); repo = new FeatureBitsEfRepo(context); } else { repo = new FeatureBitsTableStorageRepo(dbConnStr, opts.AzureTableName); } return(repo); }
public async Task ItCanUpsertIFeatureBitDefinitions() { // Arrange AddThreeDefinitions(); var defToUpsert = new FeatureBitEfDefinition { Name = "New feature bit", CreatedByUser = "******", LastModifiedByUser = "******" }; // Act await _it.UpdateAsync(defToUpsert); // Assert using (var context = new FeatureBitsEfDbContext(_options)) { context.FeatureBitDefinitions.Count().Should().Be(4); context.FeatureBitDefinitions.Should().Contain(f => f.Name == "New feature bit"); } }
public FeatureBitsEfDbContextTests() { _it = FeatureBitEfHelper.SetupDbContext().Item1; }
public FeatureBitDefinitionsController(FeatureBitsEfDbContext context) { _context = context; }