Skip to content

Commit

Permalink
Merge pull request #86 from ShipEngine/jpill/upgrade-framework-and-nu…
Browse files Browse the repository at this point in the history
…get-packages

feat: upgrade framework, nuget packages, remove Newtonsoft.Json
  • Loading branch information
jpill authored Jun 5, 2024
2 parents 59bc53f + 41dd6ef commit ec0c846
Show file tree
Hide file tree
Showing 55 changed files with 269 additions and 266 deletions.
34 changes: 9 additions & 25 deletions .github/workflows/ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: dotnet test ShipEngine.Tests/bin/Release/net462/ShipEngine.Tests.dll

dot_net_core_test:
name: .Net Core 2.1.x, 3.1.x, and .Net 5.0 on ${{ matrix.os }}
name: .Net 8.0 on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
Expand All @@ -48,40 +48,24 @@ jobs:
steps:
- name: Checkout source
uses: actions/checkout@v2

- name: Setup dotnet 2.1.x
- name: Setup dotnet 8.0.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.1.x

- name: Setup dotnet 3.1.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.x

- name: Setup dotnet 5.0.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 8.0.x

- name: Dotnet tool restore
run: dotnet tool restore

- name: Lint
if: ${{ matrix.os == 'ubuntu-latest'}}
run: dotnet format --check
run: dotnet format

- name: Dotnet Build
run: dotnet build --configuration Release

- name: Run 2.1.x Tests
run: dotnet test -f netcoreapp2.1

- name: Run 3.1.x Tests
run: dotnet test -f netcoreapp3.1

- name: Run 5.0 Tests
run: dotnet test -f net5.0 --settings ShipEngine.Tests/coverage.runsettings
- name: Run 8.0 Tests
run: dotnet test -f net8.0 --settings ShipEngine.Tests/coverage.runsettings

- name: Move generated lcov file to expected location
shell: bash
Expand Down Expand Up @@ -117,10 +101,10 @@ jobs:
- uses: actions/checkout@v2

# Setup Dotnet if release was created
- name: Setup dotnet 5.0.x
- name: Setup dotnet 8.0.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 8.0.x

- name: publish on version change
id: publish_nuget
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,10 @@ Added support LabelDownload to Package on CreateLabelFromShipment and CreateLabe

### Changed

Added custom converter to fallback to default unspecified error code if value cannot be found in the enumeration
Added custom converter to fallback to default unspecified error code if value cannot be found in the enumeration

## 2.0.0

### Changed

Updated to .NET 8.0, removed Newtonsoft.Json dependency, and updated to System.Text.Json
12 changes: 7 additions & 5 deletions ShipEngine.Tests/ConfigTest.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using Moq;
using Newtonsoft.Json;
using ShipEngineSDK;
using ShipEngineSDK.VoidLabelWithLabelId;
using System;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using Xunit;

namespace ShipEngineTest
{

public class ConfigTest
{
public TestUtils TestUtils;
Expand All @@ -20,7 +21,7 @@ public ConfigTest()
}

[Fact]
public async void ValidateDefaultTimeoutTest()
public async Task ValidateDefaultTimeoutTest()
{
var apiKeyString = "TEST_bTYAskEX6tD7vv6u/cZ/M4LaUSWBJ219+8S1jgFcnkk";
var config = new Config(apiKeyString);
Expand All @@ -30,7 +31,8 @@ public async void ValidateDefaultTimeoutTest()
var shipEngine = mockHandler.Object;
string json = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "../../../HttpResponseMocks/VoidLabelWithLabelId200Response.json"));

var voidLabelResult = JsonConvert.DeserializeObject<Result>(json, TestUtils.JsonSerializerSettings);
var voidLabelResult = System.Text.Json.JsonSerializer.Deserialize<Result>(json, TestUtils.JsonSerializerOptions);

var request = new HttpRequestMessage(HttpMethod.Put, $"v1/labels/se-1234/void");


Expand All @@ -55,7 +57,7 @@ public async void ValidateDefaultTimeoutTest()
}

[Fact]
public async void ValidateCustomTimeout()
public async Task ValidateCustomTimeout()
{
var apiKeyString = "TEST_bTYAskEX6tD7vv6u/cZ/M4LaUSWBJ219+8S1jgFcnkk";

Expand All @@ -66,7 +68,7 @@ public async void ValidateCustomTimeout()
var shipEngine = mockHandler.Object;
string json = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "../../../HttpResponseMocks/VoidLabelWithLabelId200Response.json"));

var voidLabelResult = JsonConvert.DeserializeObject<Result>(json, TestUtils.JsonSerializerSettings);
var voidLabelResult = JsonSerializer.Deserialize<Result>(json, TestUtils.JsonSerializerOptions);
var request = new HttpRequestMessage(HttpMethod.Put, $"v1/labels/se-1234/void");

// Verify that the client has a custom timeout of 1 second when called.
Expand Down
15 changes: 6 additions & 9 deletions ShipEngine.Tests/Helpers/MockShipEngineFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ namespace ShipEngineTest
{
using Moq;
using Moq.Protected;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using ShipEngineSDK;
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -25,13 +25,10 @@ public MockShipEngineFixture(Config config)
_client = ShipEngineClient.ConfigureHttpClient(config, HttpClient)
};

JsonSerializerSettings = new JsonSerializerSettings()
JsonSerializerOptions = new JsonSerializerOptions()
{
NullValueHandling = NullValueHandling.Include,
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
}
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
};
}

Expand All @@ -41,7 +38,7 @@ public MockShipEngineFixture(Config config)

public ShipEngine ShipEngine { get; }

public JsonSerializerSettings JsonSerializerSettings { get; set; }
public JsonSerializerOptions JsonSerializerOptions { get; set; }

/// <summary>
/// Resets the mock's state.
Expand Down
17 changes: 10 additions & 7 deletions ShipEngine.Tests/Helpers/TestUtils.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization;

public class TestUtils
{
public readonly JsonSerializerSettings JsonSerializerSettings;
public readonly JsonSerializerOptions JsonSerializerOptions;

public TestUtils()
{
JsonSerializerSettings = new JsonSerializerSettings()
JsonSerializerOptions = new JsonSerializerOptions()
{
NullValueHandling = NullValueHandling.Include,
ContractResolver = new DefaultContractResolver
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull,
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
PropertyNameCaseInsensitive = true,
WriteIndented = true,
Converters =
{
NamingStrategy = new SnakeCaseNamingStrategy()
new JsonStringEnumConverter(JsonNamingPolicy.SnakeCaseLower)
}
};
}
Expand Down
10 changes: 5 additions & 5 deletions ShipEngine.Tests/NetworkTimeoutsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public NetworkRetriesTest()
}

[Fact]
public async void RetryOnceByDefault()
public async Task RetryOnceByDefault()
{
var config = new Config(apiKey: "TEST_bTYAskEX6tD7vv6u/cZ/M4LaUSWBJ219+8S1jgFcnkk", timeout: TimeSpan.FromSeconds(2));
var mockShipEngineFixture = new MockShipEngineFixture(config);
Expand Down Expand Up @@ -58,7 +58,7 @@ public async void RetryOnceByDefault()
}

[Fact]
public async void CustomRetriesSetting()
public async Task CustomRetriesSetting()
{
var config = new Config(apiKey: "TEST_bTYAskEX6tD7vv6u/cZ/M4LaUSWBJ219+8S1jgFcnkk", timeout: TimeSpan.FromSeconds(2), retries: 2);
var mockShipEngineFixture = new MockShipEngineFixture(config);
Expand All @@ -85,7 +85,7 @@ public async void CustomRetriesSetting()
}

[Fact]
public async void RetriesDisabled()
public async Task RetriesDisabled()
{
var config = new Config(apiKey: "TEST_bTYAskEX6tD7vv6u/cZ/M4LaUSWBJ219+8S1jgFcnkk", timeout: TimeSpan.FromSeconds(2), retries: 0);
var mockShipEngineFixture = new MockShipEngineFixture(config);
Expand Down Expand Up @@ -117,7 +117,7 @@ public async void RetriesDisabled()

// Retry after is set to 2 seconds. Total elapsed time should be greater
[Fact]
public async void RetriesWaitTheCorrectAmountOfTime()
public async Task RetriesWaitTheCorrectAmountOfTime()
{
var config = new Config(apiKey: "TEST_bTYAskEX6tD7vv6u/cZ/M4LaUSWBJ219+8S1jgFcnkk", timeout: TimeSpan.FromSeconds(2));
var mockShipEngineFixture = new MockShipEngineFixture(config);
Expand Down Expand Up @@ -146,7 +146,7 @@ public async void RetriesWaitTheCorrectAmountOfTime()
}

[Fact]
public async void RetryAfterIsGreaterThanTimeoutSetting()
public async Task RetryAfterIsGreaterThanTimeoutSetting()
{
var config = new Config(apiKey: "TEST_bTYAskEX6tD7vv6u/cZ/M4LaUSWBJ219+8S1jgFcnkk", timeout: TimeSpan.FromSeconds(0.5));
var mockShipEngineFixture = new MockShipEngineFixture(config);
Expand Down
14 changes: 7 additions & 7 deletions ShipEngine.Tests/ShipEngine.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;netcoreapp3.1;netcoreapp2.1;net462</TargetFrameworks>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.0" />

<PackageReference Include="Moq" Version="4.14.7" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">

<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Moq;
using Newtonsoft.Json;
using ShipEngineSDK;
using ShipEngineSDK.Common.Enums;
using ShipEngineSDK.CreateLabelFromRate;
using System;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using Xunit;

Expand Down Expand Up @@ -34,7 +34,7 @@ public CreateLabelFromRateTest()
}

[Fact]
public async void ValidCreateLabelFromRateTest()
public async Task ValidCreateLabelFromRateTest()
{
var config = new Config("TEST_bTYAskEX6tD7vv6u/cZ/M4LaUSWBJ219+8S1jgFcnkk");
var mockShipEngineFixture = new MockShipEngineFixture(config);
Expand Down Expand Up @@ -112,7 +112,7 @@ public async void ValidCreateLabelFromRateTest()
}

[Fact]
public async void ValidateCustomSettingsAtMethodLevel()
public async Task ValidateCustomSettingsAtMethodLevel()
{
var apiKeyString = "TEST_bTYAskEX6tD7vv6u/cZ/M4LaUSWBJ219+8S1jgFcnkk";

Expand All @@ -123,7 +123,7 @@ public async void ValidateCustomSettingsAtMethodLevel()
var shipEngine = mockHandler.Object;
string json = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "../../../HttpResponseMocks/CreateLabelFromRate200Response.json"));

var voidLabelResult = JsonConvert.DeserializeObject<ShipEngineSDK.CreateLabelFromRate.Result>(json);
var voidLabelResult = JsonSerializer.Deserialize<ShipEngineSDK.CreateLabelFromRate.Result>(json);
var request = new HttpRequestMessage(HttpMethod.Post, "v1/labels/rates/se-1234");

// Verify that the client has a custom timeout of 1 second when called.
Expand All @@ -148,7 +148,7 @@ public async void ValidateCustomSettingsAtMethodLevel()
}

[Fact]
public async void InvalidRetriesInMethodCall()
public async Task InvalidRetriesInMethodCall()
{
var apiKeyString = "TEST_bTYAskEX6tD7vv6u/cZ/M4LaUSWBJ219+8S1jgFcnkk";

Expand Down
Loading

0 comments on commit ec0c846

Please sign in to comment.