Add deployment
This commit is contained in:
@@ -8,6 +8,21 @@ using StackExchange.Redis;
|
||||
|
||||
public class ApiFixture : WebApplicationFactory<Program>, IAsyncLifetime
|
||||
{
|
||||
// Prefer CI/env overrides; fall back to local docker-compose.yml host ports.
|
||||
public static string PgConnection { get; } =
|
||||
Environment.GetEnvironmentVariable("ConnectionStrings__DefaultConnection")
|
||||
?? "Host=localhost;Port=5436;Database=vigilcare_test;Username=postgres;Password=password";
|
||||
|
||||
public static string RedisConnection { get; } =
|
||||
Environment.GetEnvironmentVariable("Redis__ConnectionString")
|
||||
?? "localhost:6382,defaultDatabase=1,allowAdmin=true";
|
||||
|
||||
public static string RabbitHost { get; } =
|
||||
Environment.GetEnvironmentVariable("RabbitMq__Host") ?? "localhost";
|
||||
|
||||
public static int RabbitPort { get; } =
|
||||
int.TryParse(Environment.GetEnvironmentVariable("RabbitMq__Port"), out var p) ? p : 5674;
|
||||
|
||||
// Override configuration to point at a test database — never run tests against
|
||||
// the development database; a botched rollback could corrupt seed data.
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
@@ -17,17 +32,24 @@ public class ApiFixture : WebApplicationFactory<Program>, IAsyncLifetime
|
||||
{
|
||||
config.AddInMemoryCollection(new Dictionary<string, string?>
|
||||
{
|
||||
["ConnectionStrings:DefaultConnection"] =
|
||||
"Host=localhost;Port=5436;Database=vigilcare_test;Username=postgres;Password=password",
|
||||
["Redis:ConnectionString"] = "localhost:6382,defaultDatabase=1,allowAdmin=true",
|
||||
["RabbitMq:Host"] = "localhost",
|
||||
["RabbitMq:Port"] = "5674",
|
||||
["RabbitMq:Username"] = "guest",
|
||||
["RabbitMq:Password"] = "guest",
|
||||
["ConnectionStrings:DefaultConnection"] = PgConnection,
|
||||
["Redis:ConnectionString"] = RedisConnection,
|
||||
["RabbitMq:Host"] = RabbitHost,
|
||||
["RabbitMq:Port"] = RabbitPort.ToString(),
|
||||
["RabbitMq:Username"] = Environment.GetEnvironmentVariable("RabbitMq__Username") ?? "guest",
|
||||
["RabbitMq:Password"] = Environment.GetEnvironmentVariable("RabbitMq__Password") ?? "guest",
|
||||
["RabbitMq:PagingAckTimeoutMs"] = "5000",
|
||||
["RabbitMq:VirtualHost"] = "vigilcare_test",
|
||||
["Kafka:BootstrapServers"] =
|
||||
Environment.GetEnvironmentVariable("Kafka__BootstrapServers") ?? "localhost:9092",
|
||||
["Kafka:ReplicationFactor"] =
|
||||
Environment.GetEnvironmentVariable("Kafka__ReplicationFactor") ?? "1",
|
||||
["Kafka:NotificationPublisherGroupId"] = "notification-publisher-integration-test",
|
||||
["Kafka:NotificationPublisherAutoOffsetReset"] = "Latest",
|
||||
["Elasticsearch:Uri"] =
|
||||
Environment.GetEnvironmentVariable("Elasticsearch__Uri") ?? "http://localhost:9200",
|
||||
["Minio:Endpoint"] =
|
||||
Environment.GetEnvironmentVariable("Minio__Endpoint") ?? "localhost:9005",
|
||||
["Fhir:ApiKey"] = "dev-integration-key-change-in-production",
|
||||
["ApiKey:Gateway"] = GatewayAuthHelper.DevGatewayKey,
|
||||
});
|
||||
@@ -52,9 +74,8 @@ public class ApiFixture : WebApplicationFactory<Program>, IAsyncLifetime
|
||||
// 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)
|
||||
.UseNpgsql(PgConnection)
|
||||
.Options;
|
||||
await using (var migrateDb = new AppDbContext(options))
|
||||
{
|
||||
@@ -64,10 +85,10 @@ public class ApiFixture : WebApplicationFactory<Program>, IAsyncLifetime
|
||||
|
||||
await RabbitMqTestHelper.EnsureVirtualHostAsync(new RabbitMqOptions
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = 5674,
|
||||
Username = "guest",
|
||||
Password = "guest",
|
||||
Host = RabbitHost,
|
||||
Port = RabbitPort,
|
||||
Username = Environment.GetEnvironmentVariable("RabbitMq__Username") ?? "guest",
|
||||
Password = Environment.GetEnvironmentVariable("RabbitMq__Password") ?? "guest",
|
||||
VirtualHost = "vigilcare_test",
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user