Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 1 addition & 8 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@
"version": 1,
"isRoot": true,
"tools": {
"dotnet-sonarscanner": {
"version": "9.0.2",
"commands": [
"dotnet-sonarscanner"
],
"rollForward": false
},
"nbgv": {
"version": "3.7.115",
"version": "3.9.50",
"commands": [
"nbgv"
],
Expand Down
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ dotnet_style_namespace_match_folder = true

# CA1303: Do not pass literals as localized parameters
dotnet_diagnostic.CA1303.severity = silent

# IDE0060: Remove unused parameter
dotnet_diagnostic.IDE0060.severity = silent
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ A clear and concise description of what you expected to happen.

**Background (please complete the following information):**
- Version of library: [e.g. 0.10]
- Version of .NET: [e.g. 8.0]
- Version of .NET: [e.g. 10.0]

**Additional context**
Add any other context about the problem here.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/vulnerability.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ A clear and concise description of what you expected to happen.

**Background (please complete the following information):**
- Version of library: [e.g. 0.10]
- Version of .NET: [e.g. 7.0]
- Version of .NET: [e.g. 10.0]

**Additional context**
Add any other context about the vulnerability here.
26 changes: 4 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,23 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Update Java SDK for SonarQube
uses: actions/setup-java@v4
with:
distribution: 'microsoft'
java-version: '21'
- name: Setup .NET versions
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x
- name: Dump .NET info
run: dotnet --info
- name: Restore dotnet tools
run: dotnet tool restore
- name: Prepare sonarqube
if: ${{ github.actor != 'dependabot[bot]' }}
env:
SONAR_TOKEN: ${{secrets.SONAR_TOKEN}}
run: dotnet sonarscanner begin -d:sonar.host.url=https://sonarcloud.io -organization:testablehttpclient -key:testablehttpclient_TestableHttpClient -version:`dotnet nbgv get-version --variable NuGetPackageVersion` -d:sonar.cs.opencover.reportsPaths=**/coverage.opencover.xml -d:sonar.token=${{env.SONAR_TOKEN}}
- name: Restore dependencies
run: dotnet restore
- name: Build source code
run: dotnet build --configuration Release --no-restore
- name: Test with dotnet
run: dotnet test --configuration Release --no-build --collect="Code Coverage" --framework="net8.0"
- name: Upload sonarqube results
if: ${{ github.actor != 'dependabot[bot]' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{secrets.SONAR_TOKEN}}
run: dotnet sonarscanner end -d:sonar.token=${{env.SONAR_TOKEN}}
run: dotnet test --configuration Release --no-build --framework="net8.0"
- name: Check source file format
run: dotnet format --no-restore --verify-no-changes
continue-on-error: true
Expand All @@ -59,10 +44,6 @@ jobs:
with:
name: artifacts
path: ./artifacts
- uses: actions/upload-artifact@v4
with:
name: coverage
path: ./**/TestResults/**/coverage.opencover.xml

testOnSupportedDotnetVersions:
strategy:
Expand All @@ -80,6 +61,7 @@ jobs:
dotnet-version: |
8.0.x
9.0.x
10.0.x
- name: Dump .NET info
run: dotnet --info
- name: Restore dependencies
Expand All @@ -100,7 +82,7 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
9.0.x
10.0.x
- uses: actions/download-artifact@v4
with:
name: artifacts
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
dotnet-version: |
8.0.x
9.0.x
10.0.x
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- .NET Framework 4.6.2, 4.7.0 and 4.7.2, since these can't be tested using xUnit v3
### Added
- Support for .NET 9.0
- support for .NET 10.0

## [0.11] - 2024-06-15
### Removed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ The following versions are being actively tested and thus supported:
- .NET Framework 4.7.2 and 4.8
- .NET 8.0
- .NET 9.0
- .NET 10.0

These versions are supported as long as Microsoft supports them, we do our best to test and support newer versions as soon as possible.

Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sdk": {
"version": "9.0.100",
"version": "10.0.100",
"allowPrerelease": false,
"rollForward": "latestMajor"
"rollForward": "latestMinor"
}
}
8 changes: 4 additions & 4 deletions src/TestableHttpClient/IHttpRequestMessagesCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ public interface IHttpRequestMessagesCheck
/// <summary>
/// Options that could be used by several asserters.
/// </summary>
TestableHttpMessageHandlerOptions Options { get; }
public TestableHttpMessageHandlerOptions Options { get; }

/// <summary>
/// Asserts whether requests comply with a specific filter.
/// </summary>
/// <param name="requestFilter">The filter to filter requests with before asserting.</param>
/// <param name="condition">The name of the condition, used in the exception message.</param>
/// <returns>The <seealso cref="IHttpRequestMessagesCheck"/> for further assertions.</returns>
IHttpRequestMessagesCheck WithFilter(Func<HttpRequestMessage, bool> requestFilter, string condition);
public IHttpRequestMessagesCheck WithFilter(Func<HttpRequestMessage, bool> requestFilter, string condition);

/// <summary>
/// Asserts whether requests comply with a specific filter.
Expand All @@ -25,7 +25,7 @@ public interface IHttpRequestMessagesCheck
/// <param name="expectedNumberOfRequests">The expected number of requests.</param>
/// <param name="condition">The name of the condition, used in the exception message.</param>
/// <returns>The <seealso cref="IHttpRequestMessagesCheck"/> for further assertions.</returns>
IHttpRequestMessagesCheck WithFilter(Func<HttpRequestMessage, bool> requestFilter, int expectedNumberOfRequests, string condition);
public IHttpRequestMessagesCheck WithFilter(Func<HttpRequestMessage, bool> requestFilter, int expectedNumberOfRequests, string condition);

/// <summary>
/// Asserts whether requests comply with a specific filter.
Expand All @@ -34,5 +34,5 @@ public interface IHttpRequestMessagesCheck
/// <param name="expectedNumberOfRequests">The expected number of requests, when null is passed "at least one" is presumed.</param>
/// <param name="condition">The name of the condition, used in the exception message.</param>
/// <returns>The <seealso cref="IHttpRequestMessagesCheck"/> for further assertions.</returns>
IHttpRequestMessagesCheck WithFilter(Func<HttpRequestMessage, bool> requestFilter, int? expectedNumberOfRequests, string condition);
public IHttpRequestMessagesCheck WithFilter(Func<HttpRequestMessage, bool> requestFilter, int? expectedNumberOfRequests, string condition);
}
2 changes: 1 addition & 1 deletion src/TestableHttpClient/IResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ public interface IResponse
/// <param name="context">The context for this request.</param>
/// <param name="cancellationToken">The cancellationToken.</param>
/// <returns></returns>
Task ExecuteAsync(HttpResponseContext context, CancellationToken cancellationToken);
public Task ExecuteAsync(HttpResponseContext context, CancellationToken cancellationToken);
}
4 changes: 2 additions & 2 deletions src/TestableHttpClient/IRoutingResponseBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public interface IRoutingResponseBuilder
/// <param name="route">The route pattern.</param>
/// <param name="response">The response the route should return.</param>
/// <example>x.Map("*", Responses.StatusCode(HttpStatusCode.OK))</example>
void Map(string route, IResponse response);
public void Map(string route, IResponse response);
/// <summary>
/// Maps a custom response for when a request didn't match any route. Defaults to Responses.StatusCode(HttpStatusCode.NotFound).
/// </summary>
/// <param name="fallBackResponse">The response that should be returned when no route matches.</param>
void MapFallBackResponse(IResponse fallBackResponse);
public void MapFallBackResponse(IResponse fallBackResponse);
}
1 change: 1 addition & 0 deletions src/TestableHttpClient/Response/RoutingResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using static TestableHttpClient.Responses;

namespace TestableHttpClient.Response;

internal sealed class RoutingResponse : IResponse
{
public Task ExecuteAsync(HttpResponseContext context, CancellationToken cancellationToken)
Expand Down
5 changes: 2 additions & 3 deletions src/TestableHttpClient/TestableHttpClient.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net8.0;net9.0;net10.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -32,7 +32,6 @@
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.Json" Version="4.7.2" />
<PackageReference Include="System.Text.Encodings.Web" Version="4.7.2" />
<PackageReference Include="Perfors.UnreachableException" Version="1.0.0" />
Expand All @@ -44,7 +43,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" PrivateAssets="All">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.7.115" PrivateAssets="All" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.9.50" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
<PropertyGroup>
<IsPackable>false</IsPackable>
<RunSettingsFilePath>$(MSBuildThisFileDirectory)/coverlet.runsettings</RunSettingsFilePath>
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
</PropertyGroup>

<ItemGroup>
Expand Down
11 changes: 1 addition & 10 deletions test/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<Project>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit.v3" Version="1.0.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.v3" Version="3.2.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ public async Task ByDefault_CamelCasing_is_used_for_json_serialization()
sut.RespondWith(Json(new { Name = "Charlie" }));
using HttpClient client = sut.CreateClient();

#if NETFRAMEWORK
string json = await client.GetStringAsync("http://localhost/myjson");
#else
string json = await client.GetStringAsync("http://localhost/myjson", TestContext.Current.CancellationToken);
#endif

Assert.Equal("{\"name\":\"Charlie\"}", json);
}
Expand All @@ -27,7 +31,11 @@ public async Task But_this_can_be_changed()
sut.RespondWith(Json(new { Name = "Charlie" }));
using HttpClient client = sut.CreateClient();

#if NETFRAMEWORK
string json = await client.GetStringAsync("http://localhost/myjson");
#else
string json = await client.GetStringAsync("http://localhost/myjson", TestContext.Current.CancellationToken);
#endif

Assert.Equal("{\"Name\":\"Charlie\"}", json);
}
Expand All @@ -39,7 +47,11 @@ public async Task But_Also_directly_on_the_response()
sut.RespondWith(Json(new { Name = "Charlie" }, jsonSerializerOptions: new JsonSerializerOptions()));
using HttpClient client = sut.CreateClient();

#if NETFRAMEWORK
string json = await client.GetStringAsync("http://localhost/myjson");
#else
string json = await client.GetStringAsync("http://localhost/myjson", TestContext.Current.CancellationToken);
#endif

Assert.Equal("{\"Name\":\"Charlie\"}", json);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net472;net48;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>net472;net48;net8.0;net9.0;net10.0</TargetFrameworks>
<OutputType>Exe</OutputType>
</PropertyGroup>

Expand All @@ -17,9 +17,15 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="[9.0.*,)" />
<PackageReference Include="Microsoft.Extensions.Http" Version="[9.0.*,)" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="[9.0.*,)" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="[9.0.*,10.0.0)" />
<PackageReference Include="Microsoft.Extensions.Http" Version="[9.0.*,10.0.0)" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="[9.0.*,10.0.0)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="[10.0.*,)" />
<PackageReference Include="Microsoft.Extensions.Http" Version="[10.0.*,)" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="[10.0.*,)" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions test/TestableHttpClient.Tests/Response/ResponseTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
internal static class ResponseTestHelpers
{
public static Task<HttpResponseMessage> TestAsync(this IResponse response) => TestAsync(response, "http://httpbin.org");
public static Task<HttpResponseMessage> TestAsync(this IResponse response, string url)
public static async Task<HttpResponseMessage> TestAsync(this IResponse response, string url)
{
using TestableHttpMessageHandler handler = new();
handler.RespondWith(response);
return handler.TestAsync(url);
return await handler.TestAsync(url);
}

public static Task<HttpResponseMessage> TestAsync(this TestableHttpMessageHandler handler) => TestAsync(handler, "http://httpbin.org");
public static Task<HttpResponseMessage> TestAsync(this TestableHttpMessageHandler handler, string url)
public static async Task<HttpResponseMessage> TestAsync(this TestableHttpMessageHandler handler, string url)
{
using HttpClient client = new(handler);
return client.GetAsync(url);
return await client.GetAsync(url);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net472;net48;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>net472;net48;net8.0;net9.0;net10.0</TargetFrameworks>
<OutputType>Exe</OutputType>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using TestableHttpClient.Utils;

namespace TestableHttpClient.Tests.Utils;

public class UriPatternParserTests
{
[Theory]
Expand Down
14 changes: 0 additions & 14 deletions test/coverlet.runsettings

This file was deleted.