Skip to content

Commit 359626b

Browse files
authored
Updated dependencies and now compatible from netstandard2.0 to net8.0 (#166)
I've updated all dependencies and reverded the base target from netstandard2.1 (introduced in ver 1.2.7) to netstandard2.0 as this keeps it compatible with the widely used Net Framework 4.8. Added net4.8 to tests and adapted appsettings.json code to work on every platform. All tests passed on all targets.
1 parent bb3bced commit 359626b

5 files changed

Lines changed: 39 additions & 25 deletions

File tree

GoogleMapsApi.Test/GoogleMapsApi.Test.csproj

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
3+
<TargetFrameworks>net8.0;net6.0;net4.8</TargetFrameworks>
44
<LangVersion>latest</LangVersion>
55
<OutputType>Library</OutputType>
66
<IsPackable>false</IsPackable>
@@ -9,12 +9,18 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<FrameworkReference Include="Microsoft.AspNetCore.App" />
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
14-
<PackageReference Include="NUnit" Version="4.0.1" />
15-
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
16-
<PackageReference Include="NUnit.Analyzers" Version="3.10.0" />
17-
<PackageReference Include="coverlet.collector" Version="6.0.0" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
13+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
14+
<PackageReference Include="NUnit" Version="4.2.2" />
15+
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
16+
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">
17+
<PrivateAssets>all</PrivateAssets>
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
</PackageReference>
20+
<PackageReference Include="coverlet.collector" Version="6.0.2">
21+
<PrivateAssets>all</PrivateAssets>
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23+
</PackageReference>
1824
</ItemGroup>
1925

2026
<ItemGroup>

GoogleMapsApi.Test/IntegrationTests/BaseTestIntegration.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.Extensions.Configuration;
1+
using GoogleMapsApi.Test.Utils;
22
using System.IO;
33

44
namespace GoogleMapsApi.Test.IntegrationTests
@@ -12,24 +12,12 @@ namespace GoogleMapsApi.Test.IntegrationTests
1212
public class BaseTestIntegration
1313
{
1414
const string ApiKeyEnvironmentVariable = "GOOGLE_API_KEY";
15-
private readonly IConfigurationRoot Configuration;
1615

1716
public BaseTestIntegration()
1817
{
19-
var builder = new ConfigurationBuilder()
20-
.SetBasePath(Directory.GetCurrentDirectory())
21-
.AddEnvironmentVariables();
22-
23-
string appsettingsPath = Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json");
24-
if (File.Exists(appsettingsPath))
25-
{
26-
builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
27-
}
28-
29-
Configuration = builder.Build();
3018
}
3119

32-
protected string ApiKey => Configuration.GetValue<string>(ApiKeyEnvironmentVariable)
20+
protected string ApiKey => AppSettings.Load()?.GoogleApiKey
3321
?? Environment.GetEnvironmentVariable(ApiKeyEnvironmentVariable)
3422
?? throw new InvalidOperationException($"API key is not configured. Please set the {ApiKeyEnvironmentVariable} environment variable.");
3523
}

GoogleMapsApi.Test/IntegrationTests/DistanceMatrixTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,7 @@ public async Task ShouldReplaceUriViaOnUriCreated()
195195

196196
static Uri onUriCreated(Uri uri)
197197
{
198-
var builder = new UriBuilder(uri);
199-
builder.Query = builder.Query.Replace("placeholder", "1,2");
200-
return builder.Uri;
198+
return new Uri(uri.ToString().Replace("placeholder", "1,2"));
201199
}
202200

203201
GoogleMaps.DistanceMatrix.OnUriCreated += onUriCreated;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace GoogleMapsApi.Test.Utils
9+
{
10+
internal class AppSettings
11+
{
12+
[JsonProperty(PropertyName ="GOOGLE_API_KEY")]
13+
public string? GoogleApiKey { get; set; }
14+
15+
public static AppSettings? Load()
16+
{
17+
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json");
18+
if (!File.Exists(path)) return null;
19+
return JsonConvert.DeserializeObject<AppSettings>(File.ReadAllText(path));
20+
}
21+
}
22+
}

GoogleMapsApi/GoogleMapsApi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.1</TargetFrameworks>
3+
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.0</TargetFrameworks>
44
<LangVersion>latest</LangVersion>
55
<Version>0.0.0</Version>
66
<AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>

0 commit comments

Comments
 (0)