From 83242f928364f9905fa5663fdacce90782caf2c9 Mon Sep 17 00:00:00 2001 From: martincostello Date: Tue, 15 Sep 2020 17:57:29 +0100 Subject: [PATCH 1/4] Add .NET 5 TFM Add a net5.0 TFM. --- .github/workflows/build.yml | 2 +- .github/workflows/update-dotnet-sdk.yml | 2 +- .vscode/launch.json | 2 +- Directory.Packages.props | 10 ++++++++-- global.json | 5 +++-- samples/SampleApp.Tests/SampleApp.Tests.csproj | 2 +- samples/SampleApp/SampleApp.csproj | 2 +- src/HttpClientInterception/Bundles/BundleFactory.cs | 2 +- .../Bundles/BundleItemConverter.cs | 9 +++++---- .../HttpClientInterceptorOptions.cs | 4 ++-- .../HttpRequestInterceptionBuilder.cs | 4 ++-- .../HttpRequestInterceptionBuilderExtensions.cs | 4 +++- .../JustEat.HttpClientInterception.csproj | 2 +- .../Matching/RegistrationMatcher.cs | 6 +++--- src/HttpClientInterception/NewtonsoftJsonExtensions.cs | 2 +- .../JustEat.HttpClientInterception.Benchmarks.csproj | 2 +- tests/HttpClientInterception.Tests/Examples.cs | 3 ++- .../JustEat.HttpClientInterception.Tests.csproj | 2 +- 18 files changed, 38 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f4b82076..cf886564 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,7 +44,7 @@ jobs: - uses: codecov/codecov-action@v1 name: Upload coverage to Codecov with: - file: ./artifacts/coverage.netcoreapp3.1.cobertura.xml + file: ./artifacts/coverage.net5.0.cobertura.xml flags: ${{ matrix.os_name }} - name: Publish artifacts diff --git a/.github/workflows/update-dotnet-sdk.yml b/.github/workflows/update-dotnet-sdk.yml index 5537f020..b23e781a 100644 --- a/.github/workflows/update-dotnet-sdk.yml +++ b/.github/workflows/update-dotnet-sdk.yml @@ -17,4 +17,4 @@ jobs: - name: Update .NET SDK shell: pwsh - run: ./update-dotnet-sdk.ps1 -Channel "3.1" -GitHubToken ${{ secrets.GITHUB_TOKEN }} -UserName "github-actions[bot]" -UserEmail "github-actions[bot]@users.noreply.github.com" + run: ./update-dotnet-sdk.ps1 -Channel "5.0" -GitHubToken ${{ secrets.GITHUB_TOKEN }} -UserName "github-actions[bot]" -UserEmail "github-actions[bot]@users.noreply.github.com" diff --git a/.vscode/launch.json b/.vscode/launch.json index ba7b4013..2132c333 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,7 +6,7 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "build", - "program": "${workspaceRoot}/samples/SampleApp/bin/Debug/netcoreapp3.1/SampleApp.dll", + "program": "${workspaceRoot}/samples/SampleApp/bin/Debug/net5.0/SampleApp.dll", "args": [], "cwd": "${workspaceRoot}/samples/SampleApp", "stopAtEntry": false, diff --git a/Directory.Packages.props b/Directory.Packages.props index 4574e584..b5469acb 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,7 +3,7 @@ - + @@ -25,9 +25,15 @@ + + + + + + - + diff --git a/global.json b/global.json index 56609741..ef6ca776 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,7 @@ { "sdk": { - "version": "3.1.403", - "allowPrerelease": false + "version": "5.0.100-rc.1.20452.10", + "allowPrerelease": false, + "rollForward": "latestMajor" } } diff --git a/samples/SampleApp.Tests/SampleApp.Tests.csproj b/samples/SampleApp.Tests/SampleApp.Tests.csproj index 22e7f7bd..09d39ffc 100644 --- a/samples/SampleApp.Tests/SampleApp.Tests.csproj +++ b/samples/SampleApp.Tests/SampleApp.Tests.csproj @@ -1,7 +1,7 @@ $(NoWarn);CA1056;CA1062;CA1707;CA2007;SA1600 - netcoreapp3.1 + net5.0 diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index 50f44f8a..9b0ae6c0 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -2,7 +2,7 @@ inprocess $(NoWarn);CA1062;CA2007;SA1600 - netcoreapp3.1 + net5.0 diff --git a/src/HttpClientInterception/Bundles/BundleFactory.cs b/src/HttpClientInterception/Bundles/BundleFactory.cs index adf4d68a..7465e464 100644 --- a/src/HttpClientInterception/Bundles/BundleFactory.cs +++ b/src/HttpClientInterception/Bundles/BundleFactory.cs @@ -26,7 +26,7 @@ internal static class BundleFactory public static Bundle Create(string path) { string json = File.ReadAllText(path); - return JsonConvert.DeserializeObject(json, Settings); + return JsonConvert.DeserializeObject(json, Settings) !; } } } diff --git a/src/HttpClientInterception/Bundles/BundleItemConverter.cs b/src/HttpClientInterception/Bundles/BundleItemConverter.cs index 97bbd89b..8747bf04 100644 --- a/src/HttpClientInterception/Bundles/BundleItemConverter.cs +++ b/src/HttpClientInterception/Bundles/BundleItemConverter.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Net; using System.Text; @@ -26,9 +27,9 @@ public static HttpRequestInterceptionBuilder FromItem( } } - ValidateItem(item, out Uri uri, out Version? version); + ValidateItem(item, out Uri? uri, out Version? version); - var builder = new HttpRequestInterceptionBuilder().ForUri(uri); + var builder = new HttpRequestInterceptionBuilder().ForUri(uri!); if (item.Method != null) { @@ -100,7 +101,7 @@ private static HttpRequestInterceptionBuilder SetContent(this HttpRequestInterce switch (item.ContentFormat?.ToUpperInvariant()) { case "BASE64": - byte[] decoded = Convert.FromBase64String(item.ContentString); + byte[] decoded = Convert.FromBase64String(item.ContentString ?? string.Empty); return Encoding.UTF8.GetString(decoded); case "JSON": @@ -116,7 +117,7 @@ private static HttpRequestInterceptionBuilder SetContent(this HttpRequestInterce } } - private static void ValidateItem(BundleItem item, out Uri uri, out Version? version) + private static void ValidateItem(BundleItem item, out Uri? uri, out Version? version) { version = null; diff --git a/src/HttpClientInterception/HttpClientInterceptorOptions.cs b/src/HttpClientInterception/HttpClientInterceptorOptions.cs index 92875ca0..893dca6f 100644 --- a/src/HttpClientInterception/HttpClientInterceptorOptions.cs +++ b/src/HttpClientInterception/HttpClientInterceptorOptions.cs @@ -405,7 +405,7 @@ private static string BuildKey(HttpInterceptionResponse interceptor) return $"CUSTOM:{interceptor.InternalMatcher!.GetHashCode().ToString(CultureInfo.InvariantCulture)}"; } - var builderForKey = new UriBuilder(interceptor.RequestUri); + var builderForKey = new UriBuilder(interceptor.RequestUri!); string keyPrefix = string.Empty; if (interceptor.IgnoreHost) @@ -478,7 +478,7 @@ private static async Task BuildResponseAsync(HttpRequestMes // Do not overwrite a custom Content-Type header if already set if (!result.Content.Headers.TryGetValues("content-type", out var contentType)) { - result.Content.Headers.ContentType = new MediaTypeHeaderValue(response.ContentMediaType); + result.Content.Headers.ContentType = new MediaTypeHeaderValue(response.ContentMediaType!); } PopulateHeaders(result.Headers, response.ResponseHeaders); diff --git a/src/HttpClientInterception/HttpRequestInterceptionBuilder.cs b/src/HttpClientInterception/HttpRequestInterceptionBuilder.cs index 20b1d72b..825ba7b0 100644 --- a/src/HttpClientInterception/HttpRequestInterceptionBuilder.cs +++ b/src/HttpClientInterception/HttpRequestInterceptionBuilder.cs @@ -515,7 +515,7 @@ public HttpRequestInterceptionBuilder WithResponseHeader(string name, IEnumerabl _responseHeaders = new Dictionary>(StringComparer.OrdinalIgnoreCase); } - if (!_responseHeaders.TryGetValue(name, out ICollection current)) + if (!_responseHeaders.TryGetValue(name, out ICollection? current)) { _responseHeaders[name] = current = new List(); } @@ -818,7 +818,7 @@ public HttpRequestInterceptionBuilder ForRequestHeader(string name, IEnumerable< _requestHeaders = new Dictionary>(StringComparer.OrdinalIgnoreCase); } - if (!_requestHeaders.TryGetValue(name, out ICollection current)) + if (!_requestHeaders.TryGetValue(name, out ICollection? current)) { _requestHeaders[name] = current = new List(); } diff --git a/src/HttpClientInterception/HttpRequestInterceptionBuilderExtensions.cs b/src/HttpClientInterception/HttpRequestInterceptionBuilderExtensions.cs index 7464b280..98d00372 100644 --- a/src/HttpClientInterception/HttpRequestInterceptionBuilderExtensions.cs +++ b/src/HttpClientInterception/HttpRequestInterceptionBuilderExtensions.cs @@ -186,7 +186,9 @@ public static HttpRequestInterceptionBuilder WithFormContent( async Task ContentFactoryAsync() { - using var content = new FormUrlEncodedContent(parameters); + // The cast is to make nullability match for .NET 5.0. + // See https://github.com/dotnet/runtime/issues/38494. + using var content = new FormUrlEncodedContent((IEnumerable>)parameters); return await content.ReadAsByteArrayAsync().ConfigureAwait(false); } diff --git a/src/HttpClientInterception/JustEat.HttpClientInterception.csproj b/src/HttpClientInterception/JustEat.HttpClientInterception.csproj index 60de41a8..402f1cdc 100644 --- a/src/HttpClientInterception/JustEat.HttpClientInterception.csproj +++ b/src/HttpClientInterception/JustEat.HttpClientInterception.csproj @@ -10,7 +10,7 @@ JustEat.HttpClientInterception true A .NET library for intercepting server-side HTTP dependencies. - netstandard2.0;netstandard2.1;net461;net472 + netstandard2.0;netstandard2.1;net5.0;net461;net472 diff --git a/src/HttpClientInterception/Matching/RegistrationMatcher.cs b/src/HttpClientInterception/Matching/RegistrationMatcher.cs index 084d8a5c..0d4dc8b6 100644 --- a/src/HttpClientInterception/Matching/RegistrationMatcher.cs +++ b/src/HttpClientInterception/Matching/RegistrationMatcher.cs @@ -66,7 +66,7 @@ public override async Task IsMatchAsync(HttpRequestMessage request) if (isMatch && _registration.ContentMatcher != null) { - isMatch = await _registration.ContentMatcher(request.Content).ConfigureAwait(false); + isMatch = await _registration.ContentMatcher(request.Content!).ConfigureAwait(false); } return isMatch; @@ -82,7 +82,7 @@ public override async Task IsMatchAsync(HttpRequestMessage request) /// private static string GetUriStringForMatch(HttpInterceptionResponse registration, Uri? uri = null) { - var builder = new UriBuilder(uri ?? registration.RequestUri); + var builder = new UriBuilder(uri ?? registration.RequestUri!); if (!registration.HasCustomPort) { @@ -111,7 +111,7 @@ private bool IsMatchForHeaders(HttpHeaders requestHeaders) { foreach (var headerToMatch in _registration.RequestHeaders!) { - if (!requestHeaders.TryGetValues(headerToMatch.Key, out IEnumerable values)) + if (!requestHeaders.TryGetValues(headerToMatch.Key, out IEnumerable? values)) { return false; } diff --git a/src/HttpClientInterception/NewtonsoftJsonExtensions.cs b/src/HttpClientInterception/NewtonsoftJsonExtensions.cs index dd44df7d..29c76356 100644 --- a/src/HttpClientInterception/NewtonsoftJsonExtensions.cs +++ b/src/HttpClientInterception/NewtonsoftJsonExtensions.cs @@ -44,7 +44,7 @@ public static HttpRequestInterceptionBuilder WithNewtonsoftJsonContent( byte[] ContentFactory() { - string json = JsonConvert.SerializeObject(content, settings); + string json = JsonConvert.SerializeObject(content, settings!); return Encoding.UTF8.GetBytes(json); } diff --git a/tests/HttpClientInterception.Benchmarks/JustEat.HttpClientInterception.Benchmarks.csproj b/tests/HttpClientInterception.Benchmarks/JustEat.HttpClientInterception.Benchmarks.csproj index 10ce345e..074883f8 100644 --- a/tests/HttpClientInterception.Benchmarks/JustEat.HttpClientInterception.Benchmarks.csproj +++ b/tests/HttpClientInterception.Benchmarks/JustEat.HttpClientInterception.Benchmarks.csproj @@ -5,7 +5,7 @@ Exe JustEat.HttpClientInterception Benchmarks for JustEat.HttpClientInterception - netcoreapp2.2;netcoreapp3.1;net472 + netcoreapp3.1;net472;net5.0 8.0 diff --git a/tests/HttpClientInterception.Tests/Examples.cs b/tests/HttpClientInterception.Tests/Examples.cs index 20242af9..e62db8ff 100644 --- a/tests/HttpClientInterception.Tests/Examples.cs +++ b/tests/HttpClientInterception.Tests/Examples.cs @@ -663,7 +663,8 @@ public static async Task Inject_Latency_For_Http_Get_With_Cancellation() using var client = options.CreateHttpClient(); // Act - await client.GetAsync("http://www.google.co.uk", cts.Token); + await Assert.ThrowsAsync( + () => client.GetAsync("http://www.google.co.uk", cts.Token)); // Assert cts.IsCancellationRequested.ShouldBeTrue(); diff --git a/tests/HttpClientInterception.Tests/JustEat.HttpClientInterception.Tests.csproj b/tests/HttpClientInterception.Tests/JustEat.HttpClientInterception.Tests.csproj index 709db016..fc42f138 100644 --- a/tests/HttpClientInterception.Tests/JustEat.HttpClientInterception.Tests.csproj +++ b/tests/HttpClientInterception.Tests/JustEat.HttpClientInterception.Tests.csproj @@ -4,7 +4,7 @@ $(NoWarn);CA1303;CA1600;CA1707;CA1812;CA2000;CA2007;SA1600 JustEat.HttpClientInterception Tests for JustEat.HttpClientInterception - netcoreapp3.1 + net5.0 From 8888474d9cda93175c1a78db9544a7eded0b194a Mon Sep 17 00:00:00 2001 From: martincostello Date: Tue, 13 Oct 2020 22:42:22 +0100 Subject: [PATCH 2/4] Update to .NET 5 RC2 Update to RC2 of .NET 5. --- Directory.Build.props | 1 + Directory.Packages.props | 6 +++--- global.json | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index ca3666ac..988dc17c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -23,6 +23,7 @@ en-US $(NoWarn);CA1054;CA2234 $(NoWarn);SA0001 + $(NoWarn);NU5104 package-icon.png Apache-2.0 https://github.com/justeat/httpclient-interception diff --git a/Directory.Packages.props b/Directory.Packages.props index b5469acb..a5b175ee 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,7 +3,7 @@ - + @@ -28,12 +28,12 @@ - + - + diff --git a/global.json b/global.json index ef6ca776..9ee61147 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "5.0.100-rc.1.20452.10", + "version": "5.0.100-rc.2.20479.15", "allowPrerelease": false, "rollForward": "latestMajor" } From 326e896a94670f106f750f49871ff7090b78ccdb Mon Sep 17 00:00:00 2001 From: martincostello Date: Tue, 10 Nov 2020 09:23:54 +0000 Subject: [PATCH 3/4] Update to .NET 5 Update to the final release of .NET 5. --- Directory.Build.props | 1 - Directory.Packages.props | 6 +++--- global.json | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 988dc17c..ca3666ac 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -23,7 +23,6 @@ en-US $(NoWarn);CA1054;CA2234 $(NoWarn);SA0001 - $(NoWarn);NU5104 package-icon.png Apache-2.0 https://github.com/justeat/httpclient-interception diff --git a/Directory.Packages.props b/Directory.Packages.props index a5b175ee..d9d7023f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,7 +3,7 @@ - + @@ -28,12 +28,12 @@ - + - + diff --git a/global.json b/global.json index 9ee61147..e0f5e71e 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "5.0.100-rc.2.20479.15", + "version": "5.0.100", "allowPrerelease": false, "rollForward": "latestMajor" } From d444657d0108be4048c5e7b974fa20ab20e96154 Mon Sep 17 00:00:00 2001 From: martincostello Date: Tue, 10 Nov 2020 16:57:43 +0000 Subject: [PATCH 4/4] Bump version to 3.1.0 Update the version to 3.1.0 instead of 3.0.1. --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index ca3666ac..5d3f79a1 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -35,7 +35,7 @@ snupkg true 3.0.0.0 - 3.0.1 + 3.1.0 beta$([System.Convert]::ToInt32(`$(GITHUB_RUN_NUMBER)`).ToString(`0000`)) $(GITHUB_REF.Replace('refs/tags/v', ''))