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.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', ''))
diff --git a/Directory.Packages.props b/Directory.Packages.props
index 4574e584..d9d7023f 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..e0f5e71e 100644
--- a/global.json
+++ b/global.json
@@ -1,6 +1,7 @@
{
"sdk": {
- "version": "3.1.403",
- "allowPrerelease": false
+ "version": "5.0.100",
+ "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