Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to .NET 8 #558

Merged
merged 23 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5c6dc0c
Update to .NET 8 preview 3
martincostello May 4, 2023
473a193
Update .NET SDK to 8.0.100-preview.4.23260.5 (#562)
jet-codeflow-maintainer[bot] May 16, 2023
bf09e3a
Use UseArtifactsOutput
martincostello May 17, 2023
6da7ee8
Set executable bit
martincostello May 18, 2023
3f145ea
Update .NET SDK to 8.0.100-preview.5.23303.2 (#594)
jet-codeflow-maintainer[bot] Jun 14, 2023
c1b4955
Bump System.Text.Json for .NET 8 preview 5
martincostello Jun 14, 2023
dd55b0a
Remove Microsoft.SourceLink.GitHub
martincostello Jun 22, 2023
8b73518
Update .NET SDK to 8.0.100-preview.6.23330.14 (#608)
jet-codeflow-maintainer[bot] Jul 11, 2023
a6c10ed
Bump System.Text.Json
martincostello Jul 12, 2023
e8a59da
Update .NET SDK to 8.0.100-preview.7.23376.3 (#619)
jet-codeflow-maintainer[bot] Aug 8, 2023
a0d7c7b
Bump System.Text.Json
martincostello Aug 10, 2023
d83debe
Update .NET SDK (#643)
jet-codeflow-maintainer[bot] Sep 12, 2023
a0c6798
Update .NET SDK (#644)
jet-codeflow-maintainer[bot] Sep 25, 2023
0179a4e
Update NuGet packages
martincostello Sep 25, 2023
94ff683
Fix typo
martincostello Sep 30, 2023
7b8520d
Remove CommonAssemblyInfo
martincostello Sep 30, 2023
f90aed2
Use C# 12 features
martincostello Sep 30, 2023
bb5d04f
Suppress CA2000 warning
martincostello Sep 30, 2023
0d19d73
Update .NET SDK to 8.0.100-rc.2.23502.2 (#657)
jet-codeflow-maintainer[bot] Oct 10, 2023
4300f91
Update NuGet package
martincostello Oct 10, 2023
ff3a891
Use terminal logger
martincostello Nov 5, 2023
cefc7f0
Update .NET SDK to 8.0.100 (#680)
jet-codeflow-maintainer[bot] Nov 14, 2023
b6917f4
Update NuGet package
martincostello Nov 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
name: Upload coverage to Codecov
with:
file: ./artifacts/coverage/coverage.net7.0.cobertura.xml
file: ./artifacts/coverage/coverage.net8.0.cobertura.xml
flags: ${{ matrix.os_name }}

- name: Publish artifacts
Expand All @@ -74,7 +74,7 @@ jobs:
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: packages-${{ matrix.os_name }}
path: ./artifacts/packages
path: ./artifacts/package/release
if-no-files-found: error

validate-packages:
Expand Down
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": "${workspaceFolder}/samples/SampleApp/bin/Debug/net7.0/SampleApp.dll",
"program": "${workspaceFolder}/samples/SampleApp/bin/Debug/net8.0/SampleApp.dll",
"args": [],
"cwd": "${workspaceFolder}/samples/SampleApp",
"stopAtEntry": false,
Expand Down
2 changes: 1 addition & 1 deletion .vsconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"components": [
"Microsoft.VisualStudio.Component.CoreEditor",
"Microsoft.VisualStudio.Workload.CoreEditor",
"Microsoft.NetCore.Component.Runtime.7.0",
"Microsoft.NetCore.Component.Runtime.8.0",
"Microsoft.NetCore.Component.SDK",
"Microsoft.VisualStudio.Component.Roslyn.Compiler",
"Microsoft.VisualStudio.Component.Roslyn.LanguageServices"
Expand Down
10 changes: 0 additions & 10 deletions CommonAssemblyInfo.cs

This file was deleted.

11 changes: 10 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<Project>
<ItemGroup>
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" />
<Compile Include="$(MSBuildThisFileDirectory)CommonAssemblyInfo.cs" />
<AssemblyAttribute Include="System.CLSCompliant">
<_Parameter1>false</_Parameter1>
<_Parameter1_IsLiteral>true</_Parameter1_IsLiteral>
</AssemblyAttribute>
</ItemGroup>
<PropertyGroup>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
Expand All @@ -24,6 +27,8 @@
<NeutralLanguage>en-US</NeutralLanguage>
<NoWarn>$(NoWarn);CA1054;CA2234</NoWarn>
<NoWarn Condition=" '$(GenerateDocumentationFile)' != 'true' ">$(NoWarn);SA0001</NoWarn>
<!-- HACK Workaround for https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3687 -->
<NoWarn>$(NoWarn);SA1010</NoWarn>
<PackageIcon>package-icon.png</PackageIcon>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/justeattakeaway/httpclient-interception</PackageProjectUrl>
Expand All @@ -36,6 +41,7 @@
<RepositoryUrl>$(PackageProjectUrl).git</RepositoryUrl>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<UseArtifactsOutput>true</UseArtifactsOutput>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<VersionPrefix>4.1.0</VersionPrefix>
<VersionSuffix Condition=" '$(VersionSuffix)' == '' AND '$(GITHUB_ACTIONS)' != '' AND '$(GITHUB_HEAD_REF)' != '' ">beta.$(GITHUB_RUN_NUMBER)</VersionSuffix>
Expand All @@ -51,6 +57,9 @@
<Using Include="System.Globalization" />
<Using Include="System.Net.Http" Condition=" '$(TargetFramework)' == 'net472' " />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
<Using Include="System.Net.Http" />
</ItemGroup>
<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">
<Using Include="Shouldly" />
<Using Include="Xunit" />
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
</ItemGroup>
</Target>
<PropertyGroup Condition=" '$(CollectCoverage)' == 'true' ">
<CoverletOutput>$([System.IO.Path]::Combine($(OutputPath), 'coverage', 'coverage'))</CoverletOutput>
<CoverletOutput>$([System.IO.Path]::Combine($(ArtifactsPath), 'coverage', 'coverage'))</CoverletOutput>
<ReportGeneratorOutputMarkdown Condition=" '$(ReportGeneratorOutputMarkdown)' == '' AND '$(GITHUB_SHA)' != '' ">true</ReportGeneratorOutputMarkdown>
<ReportGeneratorReportTypes>HTML</ReportGeneratorReportTypes>
<ReportGeneratorReportTypes Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' ">$(ReportGeneratorReportTypes);MarkdownSummaryGitHub</ReportGeneratorReportTypes>
<ReportGeneratorTargetDirectory>$([System.IO.Path]::Combine($(OutputPath), 'coverage'))</ReportGeneratorTargetDirectory>
<ReportGeneratorTargetDirectory>$([System.IO.Path]::Combine($(ArtifactsPath), 'coverage'))</ReportGeneratorTargetDirectory>
<MergeWith>$([System.IO.Path]::Combine($(ReportGeneratorTargetDirectory), 'coverage.$(TargetFramework).json'))</MergeWith>
<_MarkdownSummaryPrefix>&lt;details&gt;&lt;summary&gt;:chart_with_upwards_trend: &lt;b&gt;$(AssemblyName) Code Coverage report&lt;/b&gt;&lt;/summary&gt;</_MarkdownSummaryPrefix>
<_MarkdownSummarySuffix>&lt;/details&gt;</_MarkdownSummarySuffix>
Expand Down
6 changes: 2 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
<PackageVersion Include="GitHubActionsTestLogger" Version="2.3.3" />
<PackageVersion Include="MarkdownSnippets.MsBuild" Version="25.1.0" />
<PackageVersion Include="MartinCostello.Logging.XUnit" Version="0.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.13" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="Newtonsoft.Json.Schema" Version="3.0.15" />
<PackageVersion Include="NSubstitute" Version="5.1.0" />
<PackageVersion Include="Polly" Version="8.1.0" />
Expand All @@ -27,11 +26,10 @@
<PackageVersion Update="System.Text.Json" Version="6.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(AssemblyName)' != 'JustEat.HttpClientInterception' ">
<PackageVersion Update="System.Text.Json" Version="7.0.3" />
<PackageVersion Update="System.Text.Json" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">
Expand Down
1 change: 0 additions & 1 deletion HttpClientInterception.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.gitignore = .gitignore
.vsconfig = .vsconfig
build.ps1 = build.ps1
CommonAssemblyInfo.cs = CommonAssemblyInfo.cs
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
Directory.Packages.props = Directory.Packages.props
Expand Down
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,8 @@ A working example of this approach can be found in the [sample application](http
/// A class that registers an intercepting HTTP message handler at the end of
/// the message handler pipeline when an <see cref="HttpClient"/> is created.
/// </summary>
public sealed class HttpClientInterceptionFilter : IHttpMessageHandlerBuilderFilter
public sealed class HttpClientInterceptionFilter(HttpClientInterceptorOptions options) : IHttpMessageHandlerBuilderFilter
{
private readonly HttpClientInterceptorOptions _options;

public HttpClientInterceptionFilter(HttpClientInterceptorOptions options)
{
_options = options;
}

/// <inheritdoc/>
public Action<HttpMessageHandlerBuilder> Configure(Action<HttpMessageHandlerBuilder> next)
{
Expand All @@ -177,12 +170,12 @@ public sealed class HttpClientInterceptionFilter : IHttpMessageHandlerBuilderFil
next(builder);

// Add the interceptor as the last message handler
builder.AdditionalHandlers.Add(_options.CreateHttpMessageHandler());
builder.AdditionalHandlers.Add(options.CreateHttpMessageHandler());
};
}
}
```
<sup><a href='/samples/SampleApp.Tests/HttpClientInterceptionFilter.cs#L9-L38' title='Snippet source file'>snippet source</a> | <a href='#snippet-interception-filter' title='Start of snippet'>anchor</a></sup>
<sup><a href='/samples/SampleApp.Tests/HttpClientInterceptionFilter.cs#L9-L31' title='Snippet source file'>snippet source</a> | <a href='#snippet-interception-filter' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

#### Setting Up HttpClient for Dependency Injection Manually
Expand Down
20 changes: 3 additions & 17 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#Requires -Version 7

param(
[Parameter(Mandatory = $false)][string] $Configuration = "Release",
[Parameter(Mandatory = $false)][string] $OutputPath = "",
[Parameter(Mandatory = $false)][switch] $SkipTests
)

Expand All @@ -24,10 +22,6 @@ $testProjects = @(

$dotnetVersion = (Get-Content $sdkFile | Out-String | ConvertFrom-Json).sdk.version

if ($OutputPath -eq "") {
$OutputPath = Join-Path "$(Convert-Path "$PSScriptRoot")" "artifacts"
}

$installDotNetSdk = $false;

if (($null -eq (Get-Command "dotnet" -ErrorAction SilentlyContinue)) -and ($null -eq (Get-Command "dotnet.exe" -ErrorAction SilentlyContinue))) {
Expand Down Expand Up @@ -85,22 +79,14 @@ if ($installDotNetSdk -eq $true) {
function DotNetPack {
param([string]$Project)

$PackageOutputPath = (Join-Path $OutputPath "packages")

$additionalArgs = @()

if ($VersionSuffix) {
$additionalArgs += "--version-suffix"
$additionalArgs += $VersionSuffix
}

& $dotnet `
pack $Project `
--output $PackageOutputPath `
--configuration $Configuration `
--include-symbols `
--include-source `
$additionalArgs
& $dotnet pack $Project --include-symbols --include-source --tl $additionalArgs

if ($LASTEXITCODE -ne 0) {
throw "dotnet pack failed with exit code $LASTEXITCODE"
Expand All @@ -117,7 +103,7 @@ function DotNetTest {
$additionalArgs += "GitHubActions;report-warnings=false"
}

& $dotnet test $Project --output $OutputPath --configuration $Configuration $additionalArgs
& $dotnet test $Project --configuration "Release" --tl $additionalArgs

if ($LASTEXITCODE -ne 0) {
throw "dotnet test failed with exit code $LASTEXITCODE"
Expand All @@ -129,7 +115,7 @@ Write-Host "Packaging library..." -ForegroundColor Green
DotNetPack $libraryProject

Write-Host "Running tests..." -ForegroundColor Green
Remove-Item -Path (Join-Path $OutputPath "coverage" "coverage.*.json") -Force -ErrorAction SilentlyContinue | Out-Null
Remove-Item -Path (Join-Path $solutionPath "artifacts" "coverage" "coverage.*.json") -Force -ErrorAction SilentlyContinue | Out-Null
ForEach ($testProject in $testProjects) {
DotNetTest $testProject
}
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.403",
"version": "8.0.100",
"allowPrerelease": false,
"rollForward": "latestMajor"
}
Expand Down
11 changes: 2 additions & 9 deletions samples/SampleApp.Tests/HttpClientInterceptionFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@ namespace SampleApp.Tests;
/// A class that registers an intercepting HTTP message handler at the end of
/// the message handler pipeline when an <see cref="HttpClient"/> is created.
/// </summary>
public sealed class HttpClientInterceptionFilter : IHttpMessageHandlerBuilderFilter
public sealed class HttpClientInterceptionFilter(HttpClientInterceptorOptions options) : IHttpMessageHandlerBuilderFilter
{
private readonly HttpClientInterceptorOptions _options;

public HttpClientInterceptionFilter(HttpClientInterceptorOptions options)
{
_options = options;
}

/// <inheritdoc/>
public Action<HttpMessageHandlerBuilder> Configure(Action<HttpMessageHandlerBuilder> next)
{
Expand All @@ -30,7 +23,7 @@ public Action<HttpMessageHandlerBuilder> Configure(Action<HttpMessageHandlerBuil
next(builder);

// Add the interceptor as the last message handler
builder.AdditionalHandlers.Add(_options.CreateHttpMessageHandler());
builder.AdditionalHandlers.Add(options.CreateHttpMessageHandler());
};
}
}
Expand Down
10 changes: 5 additions & 5 deletions samples/SampleApp.Tests/ReposTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public async Task Can_Get_Organization_Repositories()
{
// Add a callback to log any HTTP requests made
Fixture.Interceptor.OnSend = (request) =>
{
OutputHelper.WriteLine($"HTTP {request.Method} {request.RequestUri}");
return Task.CompletedTask;
};
{
OutputHelper.WriteLine($"HTTP {request.Method} {request.RequestUri}");
return Task.CompletedTask;
};

// Arrange - use a scope to clean-up registrations
using (Fixture.Interceptor.BeginScope())
Expand Down Expand Up @@ -59,7 +59,7 @@ public async Task Can_Get_Organization_Repositories()
}

// Assert - Our application should have parsed the stub-names
actual.ShouldBe(new[] { "bar", "foo" });
actual.ShouldBe(["bar", "foo"]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion samples/SampleApp.Tests/SampleApp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<IsTestProject>true</IsTestProject>
<NoWarn>$(NoWarn);CA1056;CA1062;CA1707;CA1711;CA1861;CA2007;SA1600</NoWarn>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Content Include="testsettings.json;xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
Expand Down
2 changes: 2 additions & 0 deletions samples/SampleApp/Extensions/HttpClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public static class HttpClientExtensions
{
public static IHttpClientBuilder AddHttpClients(this IServiceCollection services)
{
services.ConfigureHttpJsonOptions((options) => options.SerializerOptions.WriteIndented = true);

// Register a Refit-based typed client for use in the controller, which
// configures the HttpClient with the appropriate base URL and HTTP request
// headers. It also adds two custom delegating handlers.
Expand Down
7 changes: 2 additions & 5 deletions samples/SampleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright (c) Just Eat, 2017. All rights reserved.
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

#pragma warning disable CA1852

using System.Text.Json;
using SampleApp.Extensions;
using SampleApp.Services;

Expand All @@ -21,7 +18,7 @@
ICollection<Repository> repositories = await github.GetRepositoriesAsync(organization, count ?? 100);

// Return the repositories' names
var names = new List<string>();
List<string> names = [];

foreach (var repository in repositories)
{
Expand All @@ -30,7 +27,7 @@

names.Sort();

return Results.Json(names, new JsonSerializerOptions() { WriteIndented = true });
return Results.Json(names);
});

app.Run();
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>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Refit" />
Expand Down
4 changes: 2 additions & 2 deletions src/HttpClientInterception/HttpClientInterceptorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ private static async Task<HttpResponseMessage> BuildResponseAsync(HttpRequestMes
}
else
{
byte[] content = await response.ContentFactory!().ConfigureAwait(false) ?? Array.Empty<byte>();
byte[] content = await response.ContentFactory!().ConfigureAwait(false) ?? [];
result.Content = new ByteArrayContent(content);
}

Expand Down Expand Up @@ -542,7 +542,7 @@ private sealed class OptionsScope : IDisposable
{
private readonly HttpClientInterceptorOptions _parent;
private readonly IDictionary<string, HttpInterceptionResponse> _old;
private readonly IDictionary<string, HttpInterceptionResponse> _new;
private readonly ConcurrentDictionary<string, HttpInterceptionResponse> _new;

internal OptionsScope(HttpClientInterceptorOptions parent)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace JustEat.HttpClientInterception;

/// <summary>
/// A class containing extention methods for the <see cref="HttpClientInterceptorOptions"/> class. This class cannot be inherited.
/// A class containing extension methods for the <see cref="HttpClientInterceptorOptions"/> class. This class cannot be inherited.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class HttpClientInterceptorOptionsExtensions
Expand Down
15 changes: 4 additions & 11 deletions src/HttpClientInterception/StringSyntaxAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,17 @@
namespace System.Diagnostics.CodeAnalysis;

[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
internal sealed class StringSyntaxAttribute : Attribute
internal sealed class StringSyntaxAttribute(string syntax, params object?[] arguments) : Attribute
{
public const string Uri = nameof(Uri);

public StringSyntaxAttribute(string syntax)
: this(syntax, [])
{
Syntax = syntax;
Arguments = Array.Empty<object?>();
}

public StringSyntaxAttribute(string syntax, params object?[] arguments)
{
Syntax = syntax;
Arguments = arguments;
}

public string Syntax { get; }
public string Syntax { get; } = syntax;

public object?[] Arguments { get; }
public object?[] Arguments { get; } = arguments;
}
#endif
Loading