Add remain services and fixes

This commit is contained in:
voltsrage
2026-06-18 23:33:39 +08:00
parent 4b46c09f90
commit e2d40331b7
9 changed files with 291 additions and 40 deletions
@@ -32,17 +32,20 @@ public class ApiFixture : WebApplicationFactory<Program>, IAsyncLifetime
public async Task InitializeAsync()
{
// Apply migrations before the host starts — background services such as
// ThresholdCacheLoader query the database during StartAsync.
// Apply migrations and clean stale data before the host starts — background
// services such as ThresholdCacheLoader query the database during StartAsync,
// so the reset must happen while no hosted service holds a lock.
var connectionString = "Host=localhost;Port=5436;Database=vigilcare_test;Username=postgres;Password=password";
var options = new DbContextOptionsBuilder<AppDbContext>()
.UseNpgsql(connectionString)
.Options;
await using (var migrateDb = new AppDbContext(options))
{
await migrateDb.Database.MigrateAsync();
await DbResetHelper.ResetAsync(migrateDb);
}
using var scope = Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
var redis = scope.ServiceProvider.GetRequiredService<IConnectionMultiplexer>();
var server = redis.GetServer(redis.GetEndPoints().First());
await server.FlushDatabaseAsync(1);