Skip to content

Commit

Permalink
Merge pull request #124 from skwasjer/chore/remove_netcore2_1_and_net5
Browse files Browse the repository at this point in the history
Removes .NET Core 2.1 and .NET 5.0 from test libraries
  • Loading branch information
skwasjer authored Oct 6, 2024
2 parents d218ae0 + 3322e2e commit 2f52127
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 622 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ env:
DOTNET_NOLOGO: true
dotnet-version: |
8.0.x
7.0.x
6.0.x
5.0.x
3.1.x
2.1.x
jobs:
analyze:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ env:
DOTNET_NOLOGO: true
dotnet-version: |
8.0.x
7.0.x
6.0.x
5.0.x
3.1.x
2.1.x
jobs:
determine-version:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ env:
DOTNET_NOLOGO: true
dotnet-version: |
8.0.x
7.0.x
6.0.x
5.0.x
3.1.x
2.1.x
jobs:
# Blog https://iterative.ai/blog/testing-external-contributions-using-github-actions-secrets
Expand Down
2 changes: 2 additions & 0 deletions test/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<NetTestSdkVersion>17.11.1</NetTestSdkVersion>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>

<TestNetStandard20 Condition="'$(TargetFramework)'=='net481'">true</TestNetStandard20>
<DefineConstants Condition="'$(TestNetStandard20)'=='true'">$(DefineConstants);TEST_NETSTANDARD2_0</DefineConstants>
<TestNetStandard21 Condition="'$(TargetFramework)'=='net7.0'">true</TestNetStandard21>
<DefineConstants Condition="'$(TestNetStandard21)'=='true'">$(DefineConstants);TEST_NETSTANDARD2_1</DefineConstants>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions test/MockHttp.Json.Tests/MockHttp.Json.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0;net5.0;netcoreapp2.1;net48;net472;net462</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0;net481;net48;net472;net462</TargetFrameworks>

<IsTestProject>true</IsTestProject>

Expand All @@ -15,9 +15,9 @@
<ItemGroup>
<ProjectReference Include="..\MockHttp.Testing\MockHttp.Testing.csproj" />
<!-- For coverage purposes, override default dependency resolution and instead target specific frameworks. -->
<ProjectReference Include="..\..\src\MockHttp.Json\MockHttp.Json.csproj" Condition="'$(TestNetStandard21)'==''" />
<ProjectReference Include="..\..\src\MockHttp.Json\MockHttp.Json.csproj" Condition="'$(TestNetStandard20)'=='' And '$(TestNetStandard21)'==''" />
<ProjectReference Include="..\..\src\MockHttp.Json\MockHttp.Json.csproj" Condition="'$(TestNetStandard20)'=='true'" AdditionalProperties="TargetFramework=netstandard2.0" />
<ProjectReference Include="..\..\src\MockHttp.Json\MockHttp.Json.csproj" Condition="'$(TestNetStandard21)'=='true'" AdditionalProperties="TargetFramework=netstandard2.1" />

</ItemGroup>

</Project>

This file was deleted.

8 changes: 4 additions & 4 deletions test/MockHttp.Testing/MockHttp.Testing.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0;net5.0;netcoreapp2.1;net48;net472;net462</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0;net481;;net48;net472;net462</TargetFrameworks>

<IsTestProject>false</IsTestProject>

<RootNamespace>MockHttp</RootNamespace>

<VerifyVersion>26.6.0</VerifyVersion>
<VerifyVersion Condition="'$(TargetFramework)'=='net5.0' Or '$(TargetFramework)'=='net462'">20.8.2</VerifyVersion>
<VerifyVersion Condition="'$(TargetFramework)'=='netcoreapp2.1'">18.1.0</VerifyVersion>
<VerifyVersion Condition="'$(TargetFramework)'=='net462'">20.8.2</VerifyVersion>
<VerifyPublicApi Condition="'$(VerifyPublicApi)'==''">true</VerifyPublicApi>
<DefineConstants Condition="'$(VerifyPublicApi)'=='true'">$(DefineConstants);VERIFY_PUBLIC_API</DefineConstants>
</PropertyGroup>
Expand All @@ -26,7 +25,8 @@

<ItemGroup>
<!-- For coverage purposes, override default dependency resolution and instead target specific frameworks. -->
<ProjectReference Include="..\..\src\MockHttp\MockHttp.csproj" Condition="'$(TestNetStandard21)'==''" />
<ProjectReference Include="..\..\src\MockHttp\MockHttp.csproj" Condition="'$(TestNetStandard20)'=='' And '$(TestNetStandard21)'==''" />
<ProjectReference Include="..\..\src\MockHttp\MockHttp.csproj" Condition="'$(TestNetStandard20)'=='true'" AdditionalProperties="TargetFramework=netstandard2.0" />
<ProjectReference Include="..\..\src\MockHttp\MockHttp.csproj" Condition="'$(TestNetStandard21)'=='true'" AdditionalProperties="TargetFramework=netstandard2.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ public async Task Given_that_timeout_is_not_zero_when_sending_it_should_timeout_
ResponseHandlerDelegate nextStub = Substitute.For<ResponseHandlerDelegate>();

// Act
Func<Task> act = () => sut.HandleAsync(new MockHttpRequestContext(new HttpRequestMessage()), new HttpResponseMessage(), nextStub, CancellationToken.None);
Func<Task> act = () => sut.HandleAsync(
new MockHttpRequestContext(new HttpRequestMessage()),
new HttpResponseMessage(),
nextStub,
CancellationToken.None
);

// Assert
sw.Start();

#if NET5_0_OR_GREATER
#if TEST_NETSTANDARD2_1 || NET6_0_OR_GREATER
await act.Should().ThrowAsync<TaskCanceledException>().WithInnerException(typeof(TimeoutException), "the timeout expired");
#else
await act.Should().ThrowAsync<TaskCanceledException>("the timeout expired");
Expand Down
5 changes: 3 additions & 2 deletions test/MockHttp.Tests/MockHttp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0;net5.0;netcoreapp2.1;net48;net472;net462</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0;net481;net48;net472;net462</TargetFrameworks>

<IsTestProject>true</IsTestProject>

Expand All @@ -15,7 +15,8 @@
<ItemGroup>
<ProjectReference Include="..\MockHttp.Testing\MockHttp.Testing.csproj" />
<!-- For coverage purposes, override default dependency resolution and instead target specific frameworks. -->
<ProjectReference Include="..\..\src\MockHttp\MockHttp.csproj" Condition="'$(TestNetStandard21)'==''" />
<ProjectReference Include="..\..\src\MockHttp\MockHttp.csproj" Condition="'$(TestNetStandard20)'=='' And '$(TestNetStandard21)'==''" />
<ProjectReference Include="..\..\src\MockHttp\MockHttp.csproj" Condition="'$(TestNetStandard20)'=='true'" AdditionalProperties="TargetFramework=netstandard2.0" />
<ProjectReference Include="..\..\src\MockHttp\MockHttp.csproj" Condition="'$(TestNetStandard21)'=='true'" AdditionalProperties="TargetFramework=netstandard2.1" />
</ItemGroup>

Expand Down
100 changes: 68 additions & 32 deletions test/MockHttp.Tests/MockHttpHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,56 +336,86 @@ public async Task Given_a_request_expectation_when_sending_requests_it_should_co
Field3 = DateTime.UtcNow
};
string jsonPostContent = JsonConvert.SerializeObject(postObject);
var lastModified = new DateTime(2018, 4, 12, 7, 22, 43, DateTimeKind.Local);
var postContent = new StringContent(jsonPostContent, Encoding.UTF8, MediaTypes.Json) { Headers = { LastModified = lastModified } };
var lastModified = new DateTime(
2018,
4,
12,
7,
22,
43,
DateTimeKind.Local
);
var postContent = new StringContent(jsonPostContent, Encoding.UTF8, MediaTypes.Json)
{
Headers =
{
LastModified = lastModified
}
};

// ReSharper disable once JoinDeclarationAndInitializer
Version version;
#if NETCOREAPP3_1 || NET6_0_OR_GREATER
#if NET6_0_OR_GREATER
version = _httpClient.DefaultRequestVersion;
#else
#if NET5_0_OR_GREATER
#if TEST_NETSTANDARD2_1 || NET6_0_OR_GREATER
version = new Version(2, 0);
#else
version = new Version(1, 1);
#endif
#endif

_sut
.When(matching => matching
.RequestUri("http://0.0.0.1/*/action*")
.QueryString("test", "$%^&*")
.QueryString("test2=value")
.Method("POST")
.Body(jsonPostContent)
.PartialBody(jsonPostContent.Substring(10))
.ContentType($"{MediaTypes.Json}; charset=utf-8")
.BearerToken()
.Header("Content-Length", jsonPostContent.Length)
.Header("Last-Modified", lastModified)
.Version(version)
.Any(any => any
.RequestUri("not-matching")
.RequestUri("**controller**")
)
.Where(r => 0 < r.Version.Major)
.When(
matching => matching
.RequestUri("http://0.0.0.1/*/action*")
.QueryString("test", "$%^&*")
.QueryString("test2=value")
.Method("POST")
.Body(jsonPostContent)
.PartialBody(jsonPostContent.Substring(10))
.ContentType($"{MediaTypes.Json}; charset=utf-8")
.BearerToken()
.Header("Content-Length", jsonPostContent.Length)
.Header("Last-Modified", lastModified)
.Version(version)
.Any(
any => any
.RequestUri("not-matching")
.RequestUri("**controller**")
)
.Where(r => 0 < r.Version.Major)
)
.Callback(() =>
{
})
.Respond(with => with
.StatusCode(HttpStatusCode.Accepted)
.Body(JsonConvert.SerializeObject(new { firstName = "John", lastName = "Doe" }))
.TransferRate(BitRate.TwoG)
.Latency(NetworkLatency.TwoG)
.Callback(
() =>
{
}
)
.Respond(
with => with
.StatusCode(HttpStatusCode.Accepted)
.Body(
JsonConvert.SerializeObject(
new
{
firstName = "John",
lastName = "Doe"
}
)
)
.TransferRate(BitRate.TwoG)
.Latency(NetworkLatency.TwoG)
)
.Verifiable();

// Act
await _httpClient.GetAsync("http://0.0.0.1/controller/action?test=1");
var req = new HttpRequestMessage(HttpMethod.Post, "http://0.0.0.1/controller/action?test=%24%25^%26*&test2=value")
{
Headers = { Authorization = new AuthenticationHeaderValue("Bearer", "some-token") },
Headers =
{
Authorization = new AuthenticationHeaderValue("Bearer", "some-token")
},
Content = postContent,
Version = version
};
Expand All @@ -401,8 +431,14 @@ public async Task Given_a_request_expectation_when_sending_requests_it_should_co

await response.Should()
.HaveStatusCode(HttpStatusCode.Accepted)
.And.HaveContentAsync(JsonConvert.SerializeObject(
new { firstName = "John", lastName = "Doe" })
.And.HaveContentAsync(
JsonConvert.SerializeObject(
new
{
firstName = "John",
lastName = "Doe"
}
)
);
}

Expand Down
Loading

0 comments on commit 2f52127

Please sign in to comment.