Skip to content

Commit

Permalink
Merge pull request #246 from martincostello/Support-DotNet-5
Browse files Browse the repository at this point in the history
Add .NET 5 TFM
  • Loading branch information
martincostello authored Nov 10, 2020
2 parents 32f6778 + d444657 commit 67e7615
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-dotnet-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<VersionPrefix>3.0.1</VersionPrefix>
<VersionPrefix>3.1.0</VersionPrefix>
<VersionSuffix Condition=" '$(VersionSuffix)' == '' AND '$(GITHUB_ACTIONS)' != '' ">beta$([System.Convert]::ToInt32(`$(GITHUB_RUN_NUMBER)`).ToString(`0000`))</VersionSuffix>
<VersionPrefix Condition=" $(GITHUB_REF.StartsWith(`refs/tags/v`)) ">$(GITHUB_REF.Replace('refs/tags/v', ''))</VersionPrefix>
<VersionSuffix Condition=" $(GITHUB_REF.StartsWith(`refs/tags/v`)) "></VersionSuffix>
Expand Down
10 changes: 8 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PackageVersion Include="BenchmarkDotNet" Version="0.12.1" />
<PackageVersion Include="coverlet.msbuild" Version="2.9.0" />
<PackageVersion Include="MartinCostello.Logging.XUnit" Version="0.1.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.9" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.WebUtilities" Version="1.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.1" />
Expand All @@ -25,9 +25,15 @@
<ItemGroup Condition=" '$(AssemblyName)' == 'JustEat.HttpClientInterception' ">
<PackageVersion Include="System.Net.Http" Version="4.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(AssemblyName)' == 'JustEat.HttpClientInterception' and '$(TargetFramework)' == 'net5.0' ">
<PackageVersion Update="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageVersion Update="Newtonsoft.Json" Version="12.0.3" />
<PackageVersion Update="System.Text.Json" Version="5.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(AssemblyName)' != 'JustEat.HttpClientInterception' ">
<PackageVersion Update="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageVersion Update="Newtonsoft.Json" Version="12.0.3" />
<PackageVersion Update="System.Text.Json" Version="4.7.2" />
<PackageVersion Update="System.Text.Json" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="coverlet.msbuild" PrivateAssets="All" />
Expand Down
5 changes: 3 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"sdk": {
"version": "3.1.403",
"allowPrerelease": false
"version": "5.0.100",
"allowPrerelease": false,
"rollForward": "latestMajor"
}
}
2 changes: 1 addition & 1 deletion samples/SampleApp.Tests/SampleApp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<NoWarn>$(NoWarn);CA1056;CA1062;CA1707;CA2007;SA1600</NoWarn>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Content Include="testsettings.json;xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
Expand Down
2 changes: 1 addition & 1 deletion samples/SampleApp/SampleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<AspNetCoreHostingModel>inprocess</AspNetCoreHostingModel>
<NoWarn>$(NoWarn);CA1062;CA2007;SA1600</NoWarn>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" />
Expand Down
2 changes: 1 addition & 1 deletion src/HttpClientInterception/Bundles/BundleFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal static class BundleFactory
public static Bundle Create(string path)
{
string json = File.ReadAllText(path);
return JsonConvert.DeserializeObject<Bundle>(json, Settings);
return JsonConvert.DeserializeObject<Bundle>(json, Settings) !;
}
}
}
9 changes: 5 additions & 4 deletions src/HttpClientInterception/Bundles/BundleItemConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Text;

Expand All @@ -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)
{
Expand Down Expand Up @@ -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":
Expand All @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/HttpClientInterception/HttpClientInterceptorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -478,7 +478,7 @@ private static async Task<HttpResponseMessage> 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);
Expand Down
4 changes: 2 additions & 2 deletions src/HttpClientInterception/HttpRequestInterceptionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ public HttpRequestInterceptionBuilder WithResponseHeader(string name, IEnumerabl
_responseHeaders = new Dictionary<string, ICollection<string>>(StringComparer.OrdinalIgnoreCase);
}

if (!_responseHeaders.TryGetValue(name, out ICollection<string> current))
if (!_responseHeaders.TryGetValue(name, out ICollection<string>? current))
{
_responseHeaders[name] = current = new List<string>();
}
Expand Down Expand Up @@ -818,7 +818,7 @@ public HttpRequestInterceptionBuilder ForRequestHeader(string name, IEnumerable<
_requestHeaders = new Dictionary<string, ICollection<string>>(StringComparer.OrdinalIgnoreCase);
}

if (!_requestHeaders.TryGetValue(name, out ICollection<string> current))
if (!_requestHeaders.TryGetValue(name, out ICollection<string>? current))
{
_requestHeaders[name] = current = new List<string>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ public static HttpRequestInterceptionBuilder WithFormContent(

async Task<byte[]> 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<KeyValuePair<string?, string?>>)parameters);
return await content.ReadAsByteArrayAsync().ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<RootNamespace>JustEat.HttpClientInterception</RootNamespace>
<SignAssembly>true</SignAssembly>
<Summary>A .NET library for intercepting server-side HTTP dependencies.</Summary>
<TargetFrameworks>netstandard2.0;netstandard2.1;net461;net472</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0;net461;net472</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" PrivateAssets="All" />
Expand Down
6 changes: 3 additions & 3 deletions src/HttpClientInterception/Matching/RegistrationMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public override async Task<bool> 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;
Expand All @@ -82,7 +82,7 @@ public override async Task<bool> IsMatchAsync(HttpRequestMessage request)
/// </returns>
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)
{
Expand Down Expand Up @@ -111,7 +111,7 @@ private bool IsMatchForHeaders(HttpHeaders requestHeaders)
{
foreach (var headerToMatch in _registration.RequestHeaders!)
{
if (!requestHeaders.TryGetValues(headerToMatch.Key, out IEnumerable<string> values))
if (!requestHeaders.TryGetValues(headerToMatch.Key, out IEnumerable<string>? values))
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/HttpClientInterception/NewtonsoftJsonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<OutputType>Exe</OutputType>
<RootNamespace>JustEat.HttpClientInterception</RootNamespace>
<Summary>Benchmarks for JustEat.HttpClientInterception</Summary>
<TargetFrameworks>netcoreapp2.2;netcoreapp3.1;net472</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net472;net5.0</TargetFrameworks>
<!-- Workaround for https://github.com/dotnet/BenchmarkDotNet/pull/1420 -->
<LangVersion>8.0</LangVersion>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion tests/HttpClientInterception.Tests/Examples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TaskCanceledException>(
() => client.GetAsync("http://www.google.co.uk", cts.Token));

// Assert
cts.IsCancellationRequested.ShouldBeTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<NoWarn>$(NoWarn);CA1303;CA1600;CA1707;CA1812;CA2000;CA2007;SA1600</NoWarn>
<RootNamespace>JustEat.HttpClientInterception</RootNamespace>
<Summary>Tests for JustEat.HttpClientInterception</Summary>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Content Include="example-bundle.json;xunit.runner.json;Bundles\*.json" CopyToOutputDirectory="PreserveNewest" />
Expand Down

0 comments on commit 67e7615

Please sign in to comment.