using HealthApp.Observations.Persistence; using Microsoft.EntityFrameworkCore; using Npgsql; namespace Observation.AcceptanceTests; public sealed class ObservationApiFixture : PatientProfile.AcceptanceTests.PatientApiFixture { private string? healthyConnection; public string ObservationConnectionString => ConnectionString; internal ObservationDbContext CreateObservationDbContext() => new(new DbContextOptionsBuilder().UseNpgsql(ConnectionString).Options); public async Task StopPatientServiceAsync() { healthyConnection = RuntimeConnectionString; RuntimeConnectionString = new NpgsqlConnectionStringBuilder(RuntimeConnectionString) { Host = "127.0.0.1", Port = 1, Timeout = 1 }.ConnectionString; await base.RestartHostsAsync(); } public Task StopObservationServiceAsync() => StopPatientServiceAsync(); public Task StopInsightsServiceAsync() => StopPatientServiceAsync(); public Task StopOverviewServiceAsync() => StopPatientServiceAsync(); public override async Task RestartHostsAsync() { if (healthyConnection is not null) { RuntimeConnectionString = healthyConnection; healthyConnection = null; } await base.RestartHostsAsync(); } public HttpClient CreateDirectPatientClient() => new() { BaseAddress = RawClient.BaseAddress }; public HttpClient CreateDirectObservationClient() => CreateDirectPatientClient(); public HttpClient CreateDirectInsightsClient() => CreateDirectPatientClient(); public HttpClient CreateDirectOverviewClient() => CreateDirectPatientClient(); }