Skip to content

Commit

Permalink
Make sure it runs without the appsettings.json (on CI)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximn committed Oct 9, 2024
1 parent 080bd3c commit da78c8a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions GoogleMapsApi.Test/IntegrationTests/BaseTestIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(ApiKeyEnvironmentVariable) ?? throw new InvalidOperationException($"API key is not configured. Please set the {ApiKeyEnvironmentVariable} environment variable.");
protected string ApiKey => Configuration.GetValue<string>(ApiKeyEnvironmentVariable)
?? Environment.GetEnvironmentVariable(ApiKeyEnvironmentVariable)
?? throw new InvalidOperationException($"API key is not configured. Please set the {ApiKeyEnvironmentVariable} environment variable.");
}
}

0 comments on commit da78c8a

Please sign in to comment.