From 86f820ee75148729d350a3d5a5cd5276e798ca6c Mon Sep 17 00:00:00 2001 From: skwasjer <11424653+skwasjer@users.noreply.github.com> Date: Wed, 2 Oct 2024 01:31:16 +0200 Subject: [PATCH] feat!: remove .NET Core 3.1 support from MockHttpServer since it is EOL for a long time now. --- src/MockHttp.Server/MockHttp.Server.csproj | 2 +- .../Server/HttpResponseMessageExtensions.cs | 8 ++---- src/MockHttp.Server/Server/Log.cs | 15 ++++++----- .../Server/WrappedHttpRequest.cs | 2 +- .../Fixtures/LoggerFactoryFixture.cs | 2 -- .../MockHttp.Server.Tests.csproj | 2 +- .../MockHttpServerTests.cs | 2 +- .../PublicApi/.NET_Core_3.1.verified.txt | 25 ------------------- 8 files changed, 15 insertions(+), 43 deletions(-) delete mode 100644 test/MockHttp.Server.Tests/PublicApi/.NET_Core_3.1.verified.txt diff --git a/src/MockHttp.Server/MockHttp.Server.csproj b/src/MockHttp.Server/MockHttp.Server.csproj index 126fd4cd..b894030a 100644 --- a/src/MockHttp.Server/MockHttp.Server.csproj +++ b/src/MockHttp.Server/MockHttp.Server.csproj @@ -1,7 +1,7 @@  - net8.0;net6.0;netcoreapp3.1 + net8.0;net6.0 skwas.MockHttp.Server skwas.MockHttp.Server MockHttp diff --git a/src/MockHttp.Server/Server/HttpResponseMessageExtensions.cs b/src/MockHttp.Server/Server/HttpResponseMessageExtensions.cs index c91f9fa0..ce00a571 100644 --- a/src/MockHttp.Server/Server/HttpResponseMessageExtensions.cs +++ b/src/MockHttp.Server/Server/HttpResponseMessageExtensions.cs @@ -19,15 +19,11 @@ internal static async Task MapToFeatureAsync responseFeature.ReasonPhrase = response.ReasonPhrase; CopyHeaders(response.Headers, responseFeature.Headers); - // ReSharper disable once ConditionIsAlwaysTrueOrFalse + // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract if (response.Content is not null) { CopyHeaders(response.Content.Headers, responseFeature.Headers); - Stream contentStream = await response.Content.ReadAsStreamAsync( -#if NET6_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + Stream contentStream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false); await using ConfiguredAsyncDisposable _ = contentStream.ConfigureAwait(false); await contentStream.CopyToAsync(responseBodyFeature.Writer.AsStream(), 4096, cancellationToken).ConfigureAwait(false); } diff --git a/src/MockHttp.Server/Server/Log.cs b/src/MockHttp.Server/Server/Log.cs index cee35dc2..b4d48d79 100644 --- a/src/MockHttp.Server/Server/Log.cs +++ b/src/MockHttp.Server/Server/Log.cs @@ -7,15 +7,18 @@ internal static partial class Log { internal const string LogRequestMessageTemplate = "Connection id \"{ConnectionId}\", Request id \"{RequestId}\": {Message}"; -#if NET6_0_OR_GREATER [LoggerMessage( EventId = 0, Level = LogLevel.Debug, - Message = LogRequestMessageTemplate)] - private static partial void LogDebugRequestMessage(ILogger logger, string connectionId, string requestId, string message, Exception? exception); -#else - private static readonly Action LogDebugRequestMessage = LoggerMessage.Define(LogLevel.Debug, new EventId(0), LogRequestMessageTemplate); -#endif + Message = LogRequestMessageTemplate + )] + private static partial void LogDebugRequestMessage( + ILogger logger, + string connectionId, + string requestId, + string message, + Exception? exception + ); public static void LogRequestMessage(this ILogger logger, HttpContext httpContext, string message, Exception? exception = null) { diff --git a/src/MockHttp.Server/Server/WrappedHttpRequest.cs b/src/MockHttp.Server/Server/WrappedHttpRequest.cs index 4722505e..f44bb084 100644 --- a/src/MockHttp.Server/Server/WrappedHttpRequest.cs +++ b/src/MockHttp.Server/Server/WrappedHttpRequest.cs @@ -21,7 +21,7 @@ public WrappedHttpRequest(HttpRequest request) RequestUri = uriBuilder.Uri; - // ReSharper disable once ConditionIsAlwaysTrueOrFalse + // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract if (request.Body is not null) { Content = new StreamContent(request.Body) diff --git a/test/MockHttp.Server.Tests/Fixtures/LoggerFactoryFixture.cs b/test/MockHttp.Server.Tests/Fixtures/LoggerFactoryFixture.cs index 5b09f61f..1f4dccee 100644 --- a/test/MockHttp.Server.Tests/Fixtures/LoggerFactoryFixture.cs +++ b/test/MockHttp.Server.Tests/Fixtures/LoggerFactoryFixture.cs @@ -16,9 +16,7 @@ protected LoggerFactoryFixture(Action? configure = null) builder .AddDebug() -#if NET6_0_OR_GREATER .AddSimpleConsole(opts => opts.IncludeScopes = true) -#endif ; configure?.Invoke(builder); diff --git a/test/MockHttp.Server.Tests/MockHttp.Server.Tests.csproj b/test/MockHttp.Server.Tests/MockHttp.Server.Tests.csproj index 0c2e5b68..4e92a423 100644 --- a/test/MockHttp.Server.Tests/MockHttp.Server.Tests.csproj +++ b/test/MockHttp.Server.Tests/MockHttp.Server.Tests.csproj @@ -1,7 +1,7 @@  - net8.0;net6.0;netcoreapp3.1 + net8.0;net6.0 true diff --git a/test/MockHttp.Server.Tests/MockHttpServerTests.cs b/test/MockHttp.Server.Tests/MockHttpServerTests.cs index 77538956..ef6f59e7 100644 --- a/test/MockHttp.Server.Tests/MockHttpServerTests.cs +++ b/test/MockHttp.Server.Tests/MockHttpServerTests.cs @@ -177,7 +177,7 @@ public async Task When_using_other_API_like_webRequest_it_should_respond_correct request.ContentType = MediaTypes.PlainText; await using (Stream requestStream = await request.GetRequestStreamAsync()) { - requestStream.Write(Encoding.ASCII.GetBytes("request-content")); + await requestStream.WriteAsync(Encoding.ASCII.GetBytes("request-content")); } // Assert diff --git a/test/MockHttp.Server.Tests/PublicApi/.NET_Core_3.1.verified.txt b/test/MockHttp.Server.Tests/PublicApi/.NET_Core_3.1.verified.txt deleted file mode 100644 index 41f0a258..00000000 --- a/test/MockHttp.Server.Tests/PublicApi/.NET_Core_3.1.verified.txt +++ /dev/null @@ -1,25 +0,0 @@ -[assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/skwasjer/MockHttp")] -[assembly: System.Resources.NeutralResourcesLanguage("en")] -[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v3.1", FrameworkDisplayName=".NET Core 3.1")] -namespace MockHttp -{ - public sealed class MockHttpServer : System.IAsyncDisposable, System.IDisposable - { - [System.Obsolete("Use the overload accepting an System.Uri.")] - public MockHttpServer(MockHttp.MockHttpHandler mockHttpHandler, string hostUrl) { } - public MockHttpServer(MockHttp.MockHttpHandler mockHttpHandler, System.Uri hostUri) { } - [System.Obsolete("Use the overload accepting an System.Uri.")] - public MockHttpServer(MockHttp.MockHttpHandler mockHttpHandler, Microsoft.Extensions.Logging.ILoggerFactory? loggerFactory, string hostUrl) { } - public MockHttpServer(MockHttp.MockHttpHandler mockHttpHandler, Microsoft.Extensions.Logging.ILoggerFactory? loggerFactory, System.Uri hostUri) { } - public MockHttp.MockHttpHandler Handler { get; } - public System.Uri HostUri { get; } - [System.Obsolete("Use the HostUri instead.")] - public string HostUrl { get; } - public bool IsStarted { get; } - public System.Net.Http.HttpClient CreateClient() { } - public void Dispose() { } - public System.Threading.Tasks.ValueTask DisposeAsync() { } - public System.Threading.Tasks.Task StartAsync(System.Threading.CancellationToken cancellationToken = default) { } - public System.Threading.Tasks.Task StopAsync(System.Threading.CancellationToken cancellationToken = default) { } - } -} \ No newline at end of file