public async Task SeedAsync(AFFHADbContext context, IOptions <DatabaseSeedSettings> settings, ILogger <AFFHADatabaseSeed> logger) { var useCustomizationData = settings.Value.UseCustomizationData; using (context) { try { // Apply pending migrations if any var Database = context.GetInfrastructure().GetService <IMigrator>(); Database.Migrate(); context.Database.EnsureCreated(); if (useCustomizationData) { //seed work will go here } await context.SaveChangesAsync(); } catch (Exception ex) { logger.LogWarning(ex, "Exception {ExceptionType} with message {Message} detected on creating or migrating database", ex.GetType().Name, ex.Message); throw ex; } } }
public TestFixture() { connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); var httpContextAccessor = Substitute.For <IHttpContextAccessor>(); var options = new DbContextOptionsBuilder <AFFHADbContext>() .UseNpgsql(connection) .Options; context = new AFFHADbContext(options, httpContextAccessor); context.Database.EnsureCreated(); }
public async Task InvokeAsync(HttpContext context, AFFHADbContext db, IConfiguration config) { var routePrefix = config.GetValue("AppSettings:PublicPath", "") .TrimEnd('/'); if (context.Request.Path.StartsWithSegments(routePrefix + "/apps") || context.Request.Path.StartsWithSegments(routePrefix + "/swagger")) { await _next(context); } else { string appId = context.Request.Headers["x-app-id"]; string apiKey = context.Request.Headers["x-api-key"]; if (string.IsNullOrEmpty(appId) || string.IsNullOrEmpty(apiKey)) { await HandleChallengeAsync(context); return; } var application = await db.Applications.FirstOrDefaultAsync(a => a.AppId == appId); if (application == null) { await HandleChallengeAsync(context); return; } using (var hmac = new HMACSHA512(application.ApiKeySalt)) { var computedHash = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(apiKey)); if (!computedHash.SequenceEqual(application.ApiKeyHash)) { await HandleChallengeAsync(context); return; } else { await _next(context); } } } }
public ZoneRepository(AFFHADbContext context) { _context = context ?? throw new ArgumentNullException(nameof(context)); }