Skip to content

Commit

Permalink
Merge pull request #4 from skwasjer/feature/remove_netcore21
Browse files Browse the repository at this point in the history
Target .NET Core 3.1 for server and remove .NET Core 2.1 from test libs
  • Loading branch information
skwasjer committed Nov 18, 2021
2 parents 6756a57 + 52cb4d0 commit a36946a
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 28 deletions.
5 changes: 2 additions & 3 deletions src/MockHttp.Server/MockHttp.Server.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net5.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1</TargetFrameworks>
<PackageId>skwas.MockHttp.Server</PackageId>
<AssemblyName>skwas.MockHttp.Server</AssemblyName>
<RootNamespace>MockHttp</RootNamespace>
Expand All @@ -14,8 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
Expand Down
11 changes: 8 additions & 3 deletions src/MockHttp.Server/Server/HttpResponseMessageExtensions.cs
Expand Up @@ -13,7 +13,12 @@ namespace MockHttp.Server
{
internal static class HttpResponseMessageExtensions
{
internal static async Task MapToFeatureAsync(this HttpResponseMessage response, IHttpResponseFeature responseFeature, CancellationToken cancellationToken)
internal static async Task MapToFeatureAsync
(
this HttpResponseMessage response,
IHttpResponseFeature responseFeature,
IHttpResponseBodyFeature responseBodyFeature,
CancellationToken cancellationToken)
{
responseFeature.StatusCode = (int)response.StatusCode;
responseFeature.ReasonPhrase = response.ReasonPhrase;
Expand All @@ -25,9 +30,9 @@ internal static async Task MapToFeatureAsync(this HttpResponseMessage response,
#if NET5_0_OR_GREATER
await using Stream contentStream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
#else
using Stream contentStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
await using Stream contentStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
#endif
await contentStream.CopyToAsync(responseFeature.Body, 4096, cancellationToken).ConfigureAwait(false);
await contentStream.CopyToAsync(responseBodyFeature.Writer.AsStream(), 4096, cancellationToken).ConfigureAwait(false);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/MockHttp.Server/Server/ServerRequestHandler.cs
Expand Up @@ -37,7 +37,6 @@ public async Task HandleAsync(HttpContext httpContext, Func<Task> _)
cancellationToken.ThrowIfCancellationRequested();

HttpResponseMessage httpResponseMessage;
IHttpResponseFeature responseFeature = httpContext.Features.Get<IHttpResponseFeature>();
try
{
httpResponseMessage = await SendAsync(httpRequestMessage, cancellationToken).ConfigureAwait(false);
Expand All @@ -61,7 +60,9 @@ public async Task HandleAsync(HttpContext httpContext, Func<Task> _)
response.RegisterForDispose(httpResponseMessage);
cancellationToken.ThrowIfCancellationRequested();

await httpResponseMessage.MapToFeatureAsync(responseFeature, cancellationToken).ConfigureAwait(false);
IHttpResponseFeature responseFeature = httpContext.Features.Get<IHttpResponseFeature>();
IHttpResponseBodyFeature responseBodyFeature = httpContext.Features.Get<IHttpResponseBodyFeature>();
await httpResponseMessage.MapToFeatureAsync(responseFeature, responseBodyFeature, cancellationToken).ConfigureAwait(false);
}

private void LogRequestMessage(HttpContext httpContext, string message, LogLevel logLevel = LogLevel.Debug, Exception ex = null)
Expand Down
7 changes: 2 additions & 5 deletions test/MockHttp.Json.Tests/MockHttp.Json.Tests.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;net48</TargetFrameworks>

<IsTestProject>true</IsTestProject>

Expand All @@ -10,10 +10,7 @@

<ItemGroup>
<ProjectReference Include="..\MockHttp.Testing\MockHttp.Testing.csproj" />
<ProjectReference Include="..\..\src\MockHttp.Json\MockHttp.Json.csproj" AdditionalProperties="TargetFramework=net6.0" Condition="'$(TargetFramework)'=='net6.0'" />
<ProjectReference Include="..\..\src\MockHttp.Json\MockHttp.Json.csproj" AdditionalProperties="TargetFramework=net5.0" Condition="'$(TargetFramework)'=='net5.0'" />
<ProjectReference Include="..\..\src\MockHttp.Json\MockHttp.Json.csproj" AdditionalProperties="TargetFramework=netstandard2.1" Condition="'$(TargetFramework)'=='netcoreapp3.1'" />
<ProjectReference Include="..\..\src\MockHttp.Json\MockHttp.Json.csproj" AdditionalProperties="TargetFramework=netstandard2.0" Condition="'$(TargetFramework)'=='netcoreapp2.1'" />
<ProjectReference Include="..\..\src\MockHttp.Json\MockHttp.Json.csproj" />
</ItemGroup>

</Project>
7 changes: 2 additions & 5 deletions test/MockHttp.Server.Tests/MockHttp.Server.Tests.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1</TargetFrameworks>

<IsTestProject>true</IsTestProject>

Expand All @@ -17,10 +17,7 @@

<ItemGroup>
<ProjectReference Include="..\MockHttp.Testing\MockHttp.Testing.csproj" />
<ProjectReference Include="..\..\src\MockHttp.Server\MockHttp.Server.csproj" AdditionalProperties="TargetFramework=net6.0" Condition="'$(TargetFramework)'=='net6.0'" />
<ProjectReference Include="..\..\src\MockHttp.Server\MockHttp.Server.csproj" AdditionalProperties="TargetFramework=net5.0" Condition="'$(TargetFramework)'=='net5.0'" />
<ProjectReference Include="..\..\src\MockHttp.Server\MockHttp.Server.csproj" AdditionalProperties="TargetFramework=netstandard2.1" Condition="'$(TargetFramework)'=='netcoreapp3.1'" />
<ProjectReference Include="..\..\src\MockHttp.Server\MockHttp.Server.csproj" AdditionalProperties="TargetFramework=netstandard2.0" Condition="'$(TargetFramework)'=='netcoreapp2.1'" />
<ProjectReference Include="..\..\src\MockHttp.Server\MockHttp.Server.csproj" />
</ItemGroup>

</Project>
8 changes: 3 additions & 5 deletions test/MockHttp.Testing/MockHttp.Testing.csproj
@@ -1,22 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net5.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netstandard2.1;net48</TargetFrameworks>

<IsTestProject>false</IsTestProject>

<RootNamespace>MockHttp</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\MockHttp\MockHttp.csproj" AdditionalProperties="TargetFramework=net6.0" Condition="'$(TargetFramework)'=='net6.0'" />
<ProjectReference Include="..\..\src\MockHttp\MockHttp.csproj" AdditionalProperties="TargetFramework=net5.0" Condition="'$(TargetFramework)'=='net5.0'" />
<ProjectReference Include="..\..\src\MockHttp\MockHttp.csproj" AdditionalProperties="TargetFramework=netstandard2.1" Condition="'$(TargetFramework)'=='netstandard2.1'" />
<ProjectReference Include="..\..\src\MockHttp\MockHttp.csproj" AdditionalProperties="TargetFramework=netstandard2.0" Condition="'$(TargetFramework)'=='netstandard2.0'" />
<ProjectReference Include="..\..\src\MockHttp\MockHttp.csproj" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions test/MockHttp.Tests/Extensions/HttpContentExtensionsTests.cs
Expand Up @@ -83,7 +83,9 @@ static object[] CreateTestCase(HttpContent content, string expectedData)
};
yield return CreateTestCase(mpc, $"--boundary{Environment.NewLine}Content-Type: text/plain; charset=utf-8{Environment.NewLine}{Environment.NewLine}<b>data</b>{Environment.NewLine}--boundary--{Environment.NewLine}");
yield return CreateTestCase(new ObjectContent(typeof(string), data, new JsonMediaTypeFormatter()), $"\"{data}\"");
#if !NETFRAMEWORK
yield return CreateTestCase(new ReadOnlyMemoryContent(buffer.AsMemory()), data);
#endif
}
}
}
6 changes: 1 addition & 5 deletions test/MockHttp.Tests/MockHttp.Tests.csproj
@@ -1,17 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;net48</TargetFrameworks>

<IsTestProject>true</IsTestProject>

<RootNamespace>MockHttp</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MockHttp.Testing\MockHttp.Testing.csproj" />
</ItemGroup>
Expand Down
19 changes: 19 additions & 0 deletions test/MockHttp.Tests/MockHttpHandlerTests.cs
Expand Up @@ -411,7 +411,9 @@ public async Task Given_a_request_expectation_when_sending_requests_it_should_co

// Assert
_sut.Verify(matching => matching.RequestUri("**/controller/**"), IsSent.Exactly(2), "we sent it");
#if !NETFRAMEWORK
await _sut.VerifyAsync(matching => matching.Content(jsonPostContent), IsSent.Once, "we sent it");
#endif
_sut.Verify();
_sut.VerifyNoOtherRequests();

Expand Down Expand Up @@ -640,4 +642,21 @@ public async Task When_resetting_invoked_requests_it_should_reset_sequence()
}
}
}
#if NETFRAMEWORK
internal static class EnumerableExtensions
{
// Polyfill SkipLast
public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> enumerable, int count)
{
if (enumerable is null)
{
throw new ArgumentNullException(nameof(enumerable));
}

var list = new List<T>(enumerable);
list.RemoveRange(list.Count - count, count);
return list;
}
}
#endif
}

0 comments on commit a36946a

Please sign in to comment.