diff --git a/GoogleMapsApi.Test/GoogleMapsApi.Test.csproj b/GoogleMapsApi.Test/GoogleMapsApi.Test.csproj index 5dcfa70..16dad35 100644 --- a/GoogleMapsApi.Test/GoogleMapsApi.Test.csproj +++ b/GoogleMapsApi.Test/GoogleMapsApi.Test.csproj @@ -1,6 +1,6 @@  - net8.0;net6.0 + net8.0;net6.0;net4.8 latest Library false @@ -9,12 +9,18 @@ - - - - - - + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/GoogleMapsApi.Test/IntegrationTests/BaseTestIntegration.cs b/GoogleMapsApi.Test/IntegrationTests/BaseTestIntegration.cs index 2ce84c8..7ed106e 100644 --- a/GoogleMapsApi.Test/IntegrationTests/BaseTestIntegration.cs +++ b/GoogleMapsApi.Test/IntegrationTests/BaseTestIntegration.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.Configuration; +using GoogleMapsApi.Test.Utils; using System.IO; namespace GoogleMapsApi.Test.IntegrationTests @@ -12,24 +12,12 @@ namespace GoogleMapsApi.Test.IntegrationTests public class BaseTestIntegration { const string ApiKeyEnvironmentVariable = "GOOGLE_API_KEY"; - private readonly IConfigurationRoot Configuration; public BaseTestIntegration() { - var builder = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .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) + protected string ApiKey => AppSettings.Load()?.GoogleApiKey ?? Environment.GetEnvironmentVariable(ApiKeyEnvironmentVariable) ?? throw new InvalidOperationException($"API key is not configured. Please set the {ApiKeyEnvironmentVariable} environment variable."); } diff --git a/GoogleMapsApi.Test/IntegrationTests/DistanceMatrixTests.cs b/GoogleMapsApi.Test/IntegrationTests/DistanceMatrixTests.cs index 5858842..3e9ecc6 100644 --- a/GoogleMapsApi.Test/IntegrationTests/DistanceMatrixTests.cs +++ b/GoogleMapsApi.Test/IntegrationTests/DistanceMatrixTests.cs @@ -195,9 +195,7 @@ public async Task ShouldReplaceUriViaOnUriCreated() static Uri onUriCreated(Uri uri) { - var builder = new UriBuilder(uri); - builder.Query = builder.Query.Replace("placeholder", "1,2"); - return builder.Uri; + return new Uri(uri.ToString().Replace("placeholder", "1,2")); } GoogleMaps.DistanceMatrix.OnUriCreated += onUriCreated; diff --git a/GoogleMapsApi.Test/Utils/AppSettings.cs b/GoogleMapsApi.Test/Utils/AppSettings.cs new file mode 100644 index 0000000..9fc2373 --- /dev/null +++ b/GoogleMapsApi.Test/Utils/AppSettings.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GoogleMapsApi.Test.Utils +{ + internal class AppSettings + { + [JsonProperty(PropertyName ="GOOGLE_API_KEY")] + public string? GoogleApiKey { get; set; } + + public static AppSettings? Load() + { + var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json"); + if (!File.Exists(path)) return null; + return JsonConvert.DeserializeObject(File.ReadAllText(path)); + } + } +} diff --git a/GoogleMapsApi/GoogleMapsApi.csproj b/GoogleMapsApi/GoogleMapsApi.csproj index ecacfc8..f1e9086 100644 --- a/GoogleMapsApi/GoogleMapsApi.csproj +++ b/GoogleMapsApi/GoogleMapsApi.csproj @@ -1,6 +1,6 @@  - net8.0;net7.0;net6.0;netstandard2.1 + net8.0;net7.0;net6.0;netstandard2.0 latest 0.0.0 True