From da78c8a92dec0df52ae312f378d90870bdf0f105 Mon Sep 17 00:00:00 2001 From: Max Novak Date: Wed, 9 Oct 2024 16:32:39 +0300 Subject: [PATCH] Make sure it runs without the appsettings.json (on CI) --- .../IntegrationTests/BaseTestIntegration.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/GoogleMapsApi.Test/IntegrationTests/BaseTestIntegration.cs b/GoogleMapsApi.Test/IntegrationTests/BaseTestIntegration.cs index 208e8c7..2ce84c8 100644 --- a/GoogleMapsApi.Test/IntegrationTests/BaseTestIntegration.cs +++ b/GoogleMapsApi.Test/IntegrationTests/BaseTestIntegration.cs @@ -16,13 +16,21 @@ public class BaseTestIntegration public BaseTestIntegration() { - Configuration = new ConfigurationBuilder() + var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json", false, true) - .AddEnvironmentVariables() - .Build(); + .AddEnvironmentVariables(); + + string appsettingsPath = Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"); + if (File.Exists(appsettingsPath)) + { + builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); + } + + Configuration = builder.Build(); } - protected string ApiKey => Configuration.GetValue(ApiKeyEnvironmentVariable) ?? throw new InvalidOperationException($"API key is not configured. Please set the {ApiKeyEnvironmentVariable} environment variable."); + protected string ApiKey => Configuration.GetValue(ApiKeyEnvironmentVariable) + ?? Environment.GetEnvironmentVariable(ApiKeyEnvironmentVariable) + ?? throw new InvalidOperationException($"API key is not configured. Please set the {ApiKeyEnvironmentVariable} environment variable."); } }