Skip to content

Commit

Permalink
Updated dependencies and now compatible from netstandard2.0 to net8.0 (
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
energywave authored Nov 4, 2024
1 parent bb3bced commit 359626b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 25 deletions.
20 changes: 13 additions & 7 deletions GoogleMapsApi.Test/GoogleMapsApi.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;net4.8</TargetFrameworks>
<LangVersion>latest</LangVersion>
<OutputType>Library</OutputType>
<IsPackable>false</IsPackable>
Expand All @@ -9,12 +9,18 @@
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="4.0.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.10.0" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 2 additions & 14 deletions GoogleMapsApi.Test/IntegrationTests/BaseTestIntegration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Configuration;
using GoogleMapsApi.Test.Utils;
using System.IO;

namespace GoogleMapsApi.Test.IntegrationTests
Expand All @@ -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<string>(ApiKeyEnvironmentVariable)
protected string ApiKey => AppSettings.Load()?.GoogleApiKey
?? Environment.GetEnvironmentVariable(ApiKeyEnvironmentVariable)
?? throw new InvalidOperationException($"API key is not configured. Please set the {ApiKeyEnvironmentVariable} environment variable.");
}
Expand Down
4 changes: 1 addition & 3 deletions GoogleMapsApi.Test/IntegrationTests/DistanceMatrixTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions GoogleMapsApi.Test/Utils/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -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<AppSettings>(File.ReadAllText(path));
}
}
}
2 changes: 1 addition & 1 deletion GoogleMapsApi/GoogleMapsApi.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Version>0.0.0</Version>
<AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>
Expand Down

0 comments on commit 359626b

Please sign in to comment.