Skip to content

Commit

Permalink
Merge pull request #122 from skwasjer/feature/remove_netcore31_from_s…
Browse files Browse the repository at this point in the history
…erver

feat: remove .NET Core 3.1 from skwas.MockHttp.Server (EOL)
  • Loading branch information
skwasjer authored Oct 2, 2024
2 parents ea2dfb7 + f5641d4 commit cbd8190
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 321 deletions.
2 changes: 1 addition & 1 deletion src/MockHttp.Server/MockHttp.Server.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net6.0;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
<PackageId>skwas.MockHttp.Server</PackageId>
<AssemblyName>skwas.MockHttp.Server</AssemblyName>
<RootNamespace>MockHttp</RootNamespace>
Expand Down
8 changes: 2 additions & 6 deletions src/MockHttp.Server/Server/HttpResponseMessageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
15 changes: 9 additions & 6 deletions src/MockHttp.Server/Server/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ILogger, string, string, string, Exception?> LogDebugRequestMessage = LoggerMessage.Define<string, string, string>(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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/MockHttp.Server/Server/WrappedHttpRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
230 changes: 0 additions & 230 deletions test/MockHttp.Server.Tests/Fixtures/CapturingLoggerFactoryFixture.cs

This file was deleted.

53 changes: 53 additions & 0 deletions test/MockHttp.Server.Tests/Fixtures/FakeLogRecordSerialization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.Text;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;

namespace MockHttp.Fixtures;

internal static class FakeLogRecordSerialization
{
internal static string Serialize(FakeLogRecord e)
{
var sb = new StringBuilder();
const int len = 4;
string indent = new(' ', len + 2);

sb.AppendLine($"{GetLogLevelString(e.Level)}: {e.Category}[{e.Id.Id}]");
foreach (IEnumerable<KeyValuePair<string, object?>> scope in e.Scopes.OfType<IEnumerable<KeyValuePair<string, object?>>>())
{
sb.Append(indent);
// ReSharper disable once UsageOfDefaultStructEquality
foreach (KeyValuePair<string, object?> kvp in scope)
{
sb.Append($"=> {kvp} ");
}

sb.AppendLine();
}

sb.Append(indent);
sb.AppendLine(e.Message);

if (e.Exception is not null)
{
sb.Append(indent);
sb.AppendLine(e.Exception.ToString());
}

return sb.ToString();
}

private static string GetLogLevelString(LogLevel logLevel)
{
return logLevel switch
{
LogLevel.Trace => "trce",
LogLevel.Debug => "dbug",
LogLevel.Information => "info",
LogLevel.Warning => "warn",
LogLevel.Error => "fail",
LogLevel.Critical => "crit",
_ => throw new ArgumentOutOfRangeException(nameof(logLevel))
};
}
}
Loading

0 comments on commit cbd8190

Please sign in to comment.