Skip to content

Commit

Permalink
Merge pull request #402 from martincostello/DotNet-7
Browse files Browse the repository at this point in the history
Update to .NET 7
  • Loading branch information
martincostello authored Nov 15, 2022
2 parents 6bf66b0 + 9d4cb84 commit 77a6bb9
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- uses: codecov/codecov-action@v3
name: Upload coverage to Codecov
with:
file: ./artifacts/coverage.net6.0.cobertura.xml
file: ./artifacts/coverage.net7.0.cobertura.xml
flags: ${{ matrix.os_name }}

- name: Publish artifacts
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/net6.0/SampleApp.dll",
"program": "${workspaceFolder}/samples/SampleApp/bin/Debug/net7.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.6.0",
"Microsoft.NetCore.Component.Runtime.7.0",
"Microsoft.NetCore.Component.SDK",
"Microsoft.VisualStudio.Component.Roslyn.Compiler",
"Microsoft.VisualStudio.Component.Roslyn.LanguageServices"
Expand Down
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PackageVersion Include="GitHubActionsTestLogger" Version="2.0.1" />
<PackageVersion Include="MarkdownSnippets.MsBuild" Version="24.5.0" />
<PackageVersion Include="MartinCostello.Logging.XUnit" Version="0.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.10" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.3" />
<PackageVersion Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
Expand All @@ -29,7 +29,7 @@
<PackageVersion Update="System.Text.Json" Version="6.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(AssemblyName)' != 'JustEat.HttpClientInterception' ">
<PackageVersion Update="System.Text.Json" Version="6.0.6" />
<PackageVersion Update="System.Text.Json" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" PrivateAssets="All" />
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ The repository is hosted in [GitHub](https://github.com/justeat/httpclient-inter

## Building and Testing

Compiling the library yourself requires Git and the [.NET SDK](https://www.microsoft.com/net/download/core "Download the .NET SDK") to be installed (version 6.0.100 or later).
Compiling the library yourself requires Git and the [.NET SDK](https://www.microsoft.com/net/download/core "Download the .NET SDK") to be installed (version 7.0.100 or later).

To build and test the library locally from a terminal/command-line, run one of the following set of commands:

Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.403",
"version": "7.0.100",
"allowPrerelease": false,
"rollForward": "latestMajor"
}
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;CA2007;SA1600</NoWarn>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net7.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>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Refit" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Text;
using System.Text.Json;
Expand All @@ -25,7 +26,10 @@ public static class HttpClientInterceptorOptionsExtensions
/// <exception cref="ArgumentNullException">
/// <paramref name="options"/> is <see langword="null"/>.
/// </exception>
public static HttpClient CreateHttpClient(this HttpClientInterceptorOptions options, string baseAddress)
public static HttpClient CreateHttpClient(
this HttpClientInterceptorOptions options,
[StringSyntax(StringSyntaxAttribute.Uri)]
string baseAddress)
{
var baseAddressUri = new Uri(baseAddress, UriKind.RelativeOrAbsolute);
return options.CreateHttpClient(baseAddressUri);
Expand Down Expand Up @@ -186,6 +190,7 @@ public static HttpClientInterceptorOptions RegisterStream(
/// </exception>
public static HttpClientInterceptorOptions RegisterGetJson(
this HttpClientInterceptorOptions options,
[StringSyntax(StringSyntaxAttribute.Uri)]
string uriString,
object content,
HttpStatusCode statusCode = HttpStatusCode.OK)
Expand Down Expand Up @@ -225,6 +230,7 @@ byte[] ContentFactory()
/// </exception>
public static HttpClientInterceptorOptions RegisterGet(
this HttpClientInterceptorOptions options,
[StringSyntax(StringSyntaxAttribute.Uri)]
string uriString,
string content,
HttpStatusCode statusCode = HttpStatusCode.OK,
Expand Down Expand Up @@ -254,7 +260,10 @@ public static HttpClientInterceptorOptions RegisterGet(
/// <exception cref="ArgumentNullException">
/// <paramref name="options"/> is <see langword="null"/>.
/// </exception>
public static HttpClientInterceptorOptions DeregisterGet(this HttpClientInterceptorOptions options, string uriString)
public static HttpClientInterceptorOptions DeregisterGet(
this HttpClientInterceptorOptions options,
[StringSyntax(StringSyntaxAttribute.Uri)]
string uriString)
{
if (options is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Microsoft.AspNetCore.WebUtilities;

Expand Down Expand Up @@ -219,7 +220,10 @@ public static HttpRequestInterceptionBuilder WithJsonContent(
/// <exception cref="ArgumentNullException">
/// <paramref name="builder"/> is <see langword="null"/>.
/// </exception>
public static HttpRequestInterceptionBuilder ForUrl(this HttpRequestInterceptionBuilder builder, string uriString)
public static HttpRequestInterceptionBuilder ForUrl(
this HttpRequestInterceptionBuilder builder,
[StringSyntax(StringSyntaxAttribute.Uri)]
string uriString)
{
if (builder is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<RootNamespace>JustEat.HttpClientInterception</RootNamespace>
<SignAssembly>true</SignAssembly>
<Summary>A .NET library for intercepting server-side HTTP dependencies.</Summary>
<TargetFrameworks>netstandard2.0;net472;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net472;net6.0;net7.0</TargetFrameworks>
<!--
TODO Remove after 4.0.0 ships to NuGet.org
-->
Expand Down
30 changes: 30 additions & 0 deletions src/HttpClientInterception/StringSyntaxAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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.

//// Based on https://github.com/dotnet/runtime/blob/65067052e433eda400c5e7cc9f7b21c84640f901/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/StringSyntaxAttribute.cs

#if !NET7_0_OR_GREATER
namespace System.Diagnostics.CodeAnalysis;

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

public StringSyntaxAttribute(string syntax)
{
Syntax = syntax;
Arguments = Array.Empty<object?>();
}

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

public string Syntax { get; }

public object?[] Arguments { get; }
}
#endif
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>netcoreapp3.1;net472;net6.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net472;net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Content Include="organization.json" CopyToOutputDirectory="PreserveNewest" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public static async Task Builder_For_Raw_Bytes_Registers_Interception_Synchronou

var builder = new HttpRequestInterceptionBuilder()
.ForUrl(requestUri)
.WithContent(() => new byte[] { 46, 78, 69, 84 });
.WithContent(() => ".NET"u8.ToArray());

var options = new HttpClientInterceptorOptions().Register(builder);

Expand All @@ -248,7 +248,7 @@ public static async Task Builder_For_Raw_Bytes_Clears_Content()

var builder = new HttpRequestInterceptionBuilder()
.ForUrl(requestUri)
.WithContent(() => new byte[] { 46, 78, 69, 84 })
.WithContent(() => ".NET"u8.ToArray())
.WithContent((Func<byte[]>)null)
.WithContent((Func<Task<byte[]>>)null);

Expand All @@ -269,8 +269,8 @@ public static async Task Builder_For_Raw_Bytes_Registers_Interception_Asynchrono

var builder = new HttpRequestInterceptionBuilder()
.ForUrl(requestUri)
.WithContentStream(() => Task.FromResult<Stream>(new MemoryStream(new byte[] { 84, 69, 78, 46 })))
.WithContent(() => Task.FromResult(new byte[] { 46, 78, 69, 84 }));
.WithContentStream(() => Task.FromResult<Stream>(new MemoryStream(".NET"u8.ToArray())))
.WithContent(() => Task.FromResult(".NET"u8.ToArray()));

var options = new HttpClientInterceptorOptions().Register(builder);

Expand All @@ -289,7 +289,7 @@ public static async Task Builder_For_Stream_Registers_Interception_Synchronous()

var builder = new HttpRequestInterceptionBuilder()
.ForUrl(requestUri)
.WithContentStream(() => new MemoryStream(new byte[] { 46, 78, 69, 84 }));
.WithContentStream(() => new MemoryStream(".NET"u8.ToArray()));

var options = new HttpClientInterceptorOptions().Register(builder);

Expand All @@ -308,7 +308,7 @@ public static async Task Builder_For_Stream_Clears_Stream()

var builder = new HttpRequestInterceptionBuilder()
.ForUrl(requestUri)
.WithContentStream(() => new MemoryStream(new byte[] { 46, 78, 69, 84 }))
.WithContentStream(() => new MemoryStream(".NET"u8.ToArray()))
.WithContentStream((Func<Stream>)null)
.WithContentStream((Func<Task<Stream>>)null);

Expand All @@ -329,8 +329,8 @@ public static async Task Builder_For_Stream_Registers_Interception_Asynchronous(

var builder = new HttpRequestInterceptionBuilder()
.ForUrl(requestUri)
.WithContent(() => Task.FromResult(new byte[] { 84, 69, 78, 46 }))
.WithContentStream(() => Task.FromResult<Stream>(new MemoryStream(new byte[] { 46, 78, 69, 84 })));
.WithContent(() => Task.FromResult(".NET"u8.ToArray()))
.WithContentStream(() => Task.FromResult<Stream>(new MemoryStream(".NET"u8.ToArray())));

var options = new HttpClientInterceptorOptions().Register(builder);

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

0 comments on commit 77a6bb9

Please sign in to comment.