Skip to content

Commit 145016a

Browse files
authored
Add support for .NET Framework (#165)
Run the tests on .NET Framework versions 4.6.2, 4.7 and 4.8. Other Framework versions are either no longer supported, or basically considered covered by the minor version.
1 parent 5d9348c commit 145016a

File tree

19 files changed

+77
-23
lines changed

19 files changed

+77
-23
lines changed

.config/dotnet-tools.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"isRoot": true,
44
"tools": {
55
"dotnet-sonarscanner": {
6-
"version": "5.5.3",
6+
"version": "5.8.0",
77
"commands": [
88
"dotnet-sonarscanner"
99
]
1010
},
1111
"nbgv": {
12-
"version": "3.5.104",
12+
"version": "3.5.113",
1313
"commands": [
1414
"nbgv"
1515
]

.github/workflows/ci.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ jobs:
2828
dotnet-version: |
2929
3.1.x
3030
6.0.x
31+
- name: Dump .NET info
32+
run: dotnet --info
3133
- name: Restore dotnet tools
3234
run: dotnet tool restore
3335
- name: Prepare sonarqube
@@ -60,8 +62,11 @@ jobs:
6062
name: coverage
6163
path: ./**/TestResults/**/coverage.opencover.xml
6264

63-
testFrameworkVersions:
64-
runs-on: ubuntu-latest
65+
testOnSupportedDotnetVersions:
66+
strategy:
67+
matrix:
68+
os: [ubuntu-latest, windows-latest]
69+
runs-on: ${{ matrix.os }}
6570
steps:
6671
- name: Checkout
6772
uses: actions/checkout@v2
@@ -71,8 +76,10 @@ jobs:
7176
uses: actions/setup-dotnet@v1
7277
with:
7378
dotnet-version: |
74-
3.1.x
75-
6.0.x
79+
3.1
80+
6.0
81+
- name: Dump .NET info
82+
run: dotnet --info
7683
- name: Restore dependencies
7784
run: dotnet restore
7885
- name: Build source code
@@ -87,10 +94,11 @@ jobs:
8794
steps:
8895
- name: Checkout
8996
uses: actions/checkout@v2
90-
- name: Setup .NET 6.0
97+
- name: Setup .NET versions
9198
uses: actions/setup-dotnet@v1
9299
with:
93-
dotnet-version: '6.0'
100+
dotnet-version: |
101+
6.0
94102
- uses: actions/download-artifact@v2
95103
with:
96104
name: artifacts

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
88

99
### Added
1010
- `CreateClient` now accepts `DelegateHandlers` in order to chain Handlers. The InnerHandler property of each handler is set automatically and the `TestableHttpMessageHandler` is automatically set as the last handler. This is showcased with Polly in the integration tests.
11+
- Added support for .NET Framework 4.6.2, .NET Framework 4.7 and .NET Framework 4.8 by running the tests against these versions.
1112

1213
## [0.7] - 2022-09-22
1314
### Changed

src/TestableHttpClient/HttpRequestMessagesCheckExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ private static IHttpRequestMessagesCheck WithHeader(this IHttpRequestMessagesChe
370370
/// <param name="check">The implementation that hold all the request messages.</param>
371371
/// <param name="pattern">The expected content, supports wildcards.</param>
372372
/// <returns>The <seealso cref="IHttpRequestMessagesCheck"/> for further assertions.</returns>
373+
/// <remarks>Note that on .NET Framework, the HttpClient might dispose the content after sending the request.</remarks>
373374
public static IHttpRequestMessagesCheck WithContent(this IHttpRequestMessagesCheck check, string pattern) => WithContent(check, pattern, null);
374375

375376
/// <summary>
@@ -379,6 +380,7 @@ private static IHttpRequestMessagesCheck WithHeader(this IHttpRequestMessagesChe
379380
/// <param name="pattern">The expected content, supports wildcards.</param>
380381
/// <param name="expectedNumberOfRequests">The expected number of requests.</param>
381382
/// <returns>The <seealso cref="IHttpRequestMessagesCheck"/> for further assertions.</returns>
383+
/// <remarks>Note that on .NET Framework, the HttpClient might dispose the content after sending the request.</remarks>
382384
public static IHttpRequestMessagesCheck WithContent(this IHttpRequestMessagesCheck check, string pattern, int expectedNumberOfRequests) => WithContent(check, pattern, (int?)expectedNumberOfRequests);
383385

384386
private static IHttpRequestMessagesCheck WithContent(this IHttpRequestMessagesCheck check, string pattern, int? expectedNumberOfRequests)
@@ -402,6 +404,7 @@ private static IHttpRequestMessagesCheck WithContent(this IHttpRequestMessagesCh
402404
/// <param name="check">The implementation that hold all the request messages.</param>
403405
/// <param name="jsonObject">The object representation of the expected request content.</param>
404406
/// <returns>The <seealso cref="IHttpRequestMessagesCheck"/> for further assertions.</returns>
407+
/// <remarks>Note that on .NET Framework, the HttpClient might dispose the content after sending the request.</remarks>
405408
public static IHttpRequestMessagesCheck WithJsonContent(this IHttpRequestMessagesCheck check, object? jsonObject) => WithJsonContent(check, jsonObject, null);
406409

407410
/// <summary>
@@ -411,6 +414,7 @@ private static IHttpRequestMessagesCheck WithContent(this IHttpRequestMessagesCh
411414
/// <param name="jsonObject">The object representation of the expected request content.</param>
412415
/// <param name="expectedNumberOfRequests">The expected number of requests.</param>
413416
/// <returns>The <seealso cref="IHttpRequestMessagesCheck"/> for further assertions.</returns>
417+
/// <remarks>Note that on .NET Framework, the HttpClient might dispose the content after sending the request.</remarks>
414418
public static IHttpRequestMessagesCheck WithJsonContent(this IHttpRequestMessagesCheck check, object? jsonObject, int expectedNumberOfRequests) => WithJsonContent(check, jsonObject, (int?)expectedNumberOfRequests);
415419

416420
private static IHttpRequestMessagesCheck WithJsonContent(this IHttpRequestMessagesCheck check, object? jsonObject, int? expectedNumberOfRequests)
@@ -430,6 +434,7 @@ private static IHttpRequestMessagesCheck WithJsonContent(this IHttpRequestMessag
430434
/// <param name="check">The implementation that hold all the request messages.</param>
431435
/// <param name="nameValueCollection">The collection of key/value pairs that should be url encoded.</param>
432436
/// <returns>The <seealso cref="IHttpRequestMessagesCheck"/> for further assertions.</returns>
437+
/// <remarks>Note that on .NET Framework, the HttpClient might dispose the content after sending the request.</remarks>
433438
public static IHttpRequestMessagesCheck WithFormUrlEncodedContent(this IHttpRequestMessagesCheck check, IEnumerable<KeyValuePair<string?, string?>> nameValueCollection) => WithFormUrlEncodedContent(check, nameValueCollection, null);
434439

435440
/// <summary>
@@ -439,6 +444,7 @@ private static IHttpRequestMessagesCheck WithJsonContent(this IHttpRequestMessag
439444
/// <param name="nameValueCollection">The collection of key/value pairs that should be url encoded.</param>
440445
/// <param name="expectedNumberOfRequests">The expected number of requests.</param>
441446
/// <returns>The <seealso cref="IHttpRequestMessagesCheck"/> for further assertions.</returns>
447+
/// <remarks>Note that on .NET Framework, the HttpClient might dispose the content after sending the request.</remarks>
442448
public static IHttpRequestMessagesCheck WithFormUrlEncodedContent(this IHttpRequestMessagesCheck check, IEnumerable<KeyValuePair<string?, string?>> nameValueCollection, int expectedNumberOfRequests) => WithFormUrlEncodedContent(check, nameValueCollection, (int?)expectedNumberOfRequests);
443449

444450
private static IHttpRequestMessagesCheck WithFormUrlEncodedContent(this IHttpRequestMessagesCheck check, IEnumerable<KeyValuePair<string?, string?>> nameValueCollection, int? expectedNumberOfRequests)

src/TestableHttpClient/TestableHttpClient.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
11+
<PackageReference Include="System.Net.Http" Version="4.3.4" />
1112
<PackageReference Include="System.Text.Json" Version="4.6.0" />
1213
</ItemGroup>
1314

test/Directory.Build.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<Project>
22
<ItemGroup>
3+
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="17.3.2" />
34
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
45
<PackageReference Include="xunit" Version="2.4.2" />
56
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">

test/TestableHttpClient.IntegrationTests/AssertingRequests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,17 @@ public async Task AssertingContent()
163163
using var content = new StringContent("my special content");
164164
_ = await client.PostAsync("https://httpbin.org/post", content);
165165

166+
#if NETFRAMEWORK
167+
// On .NET Framework the HttpClient disposes the content automatically. So we can't perform the same test.
168+
testHandler.ShouldHaveMadeRequests();
169+
#else
166170
testHandler.ShouldHaveMadeRequests().WithContent("my special content");
167171
testHandler.ShouldHaveMadeRequests().WithContent("my*content");
168172
testHandler.ShouldHaveMadeRequests().WithContent("*");
169173

170174
Assert.Throws<HttpRequestMessageAssertionException>(() => testHandler.ShouldHaveMadeRequests().WithContent(""));
171175
Assert.Throws<HttpRequestMessageAssertionException>(() => testHandler.ShouldHaveMadeRequests().WithContent("my"));
176+
#endif
172177
}
173178

174179
[Fact]
@@ -180,7 +185,12 @@ public async Task AssertJsonContent()
180185
using var content = new StringContent("{}", Encoding.UTF8, "application/json");
181186
_ = await client.PostAsync("https://httpbin.org/post", content);
182187

188+
#if NETFRAMEWORK
189+
// On .NET Framework the HttpClient disposes the content automatically. So we can't perform the same test.
190+
testHandler.ShouldHaveMadeRequests();
191+
#else
183192
testHandler.ShouldHaveMadeRequests().WithJsonContent(new { });
193+
#endif
184194
}
185195

186196
[Fact]

test/TestableHttpClient.IntegrationTests/AssertingRequestsWithNFluent.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,17 @@ public async Task AssertingContent()
161161
using var content = new StringContent("my special content");
162162
_ = await client.PostAsync("https://httpbin.org/post", content);
163163

164+
#if NETFRAMEWORK
165+
// On .NET Framework the HttpClient disposes the content automatically. So we can't perform the same test.
166+
Check.That(testHandler).HasMadeRequests();
167+
#else
164168
Check.That(testHandler).HasMadeRequests().WithContent("my special content");
165169
Check.That(testHandler).HasMadeRequests().WithContent("my*content");
166170
Check.That(testHandler).HasMadeRequests().WithContent("*");
167171

168172
Check.ThatCode(() => Check.That(testHandler).HasMadeRequests().WithContent("")).IsAFailingCheck();
169173
Check.ThatCode(() => Check.That(testHandler).HasMadeRequests().WithContent("my")).IsAFailingCheck();
174+
#endif
170175
}
171176

172177
[Fact]
@@ -178,7 +183,12 @@ public async Task AssertJsonContent()
178183
using var content = new StringContent("{}", Encoding.UTF8, "application/json");
179184
_ = await client.PostAsync("https://httpbin.org/post", content);
180185

186+
#if NETFRAMEWORK
187+
// On .NET Framework the HttpClient disposes the content automatically. So we can't perform the same test.
188+
Check.That(testHandler).HasMadeRequests();
189+
#else
181190
Check.That(testHandler).HasMadeRequests().WithJsonContent(new { });
191+
#endif
182192
}
183193

184194
[Fact]

test/TestableHttpClient.IntegrationTests/CreatingClients.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public async Task CreateASimpleHttpClient()
1010

1111
await client.GetAsync("https://httpbin.org/get");
1212

13-
testableHttpMessageHandler.ShouldHaveMadeRequests().WithHttpVersion(HttpVersion.Version11);
13+
testableHttpMessageHandler.ShouldHaveMadeRequestsTo("https://httpbin.org/get");
1414
}
1515

1616
[Fact]

test/TestableHttpClient.IntegrationTests/TestableHttpClient.IntegrationTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
4+
<TargetFrameworks>net462;net47;net48;netcoreapp3.1;net6.0</TargetFrameworks>
55
</PropertyGroup>
66

77
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">

0 commit comments

Comments
 (0)