Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public async Task then_get_should_return_400_for_an_unspecified_version()
// assert
response.StatusCode.Should().Be( BadRequest );
problem.Type.Should().Be( ProblemDetailsDefaults.Unspecified.Type );
problem.Extensions["code"].ToString().Should().Be( "ApiVersionUnspecified" );
}

public when_using_a_query_string( BasicFixture fixture, ITestOutputHelper console )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal static ProblemDetailsContext New( HttpContext context, ProblemDetailsIn
},
};

if ( string.IsNullOrEmpty( code ) )
if ( !string.IsNullOrEmpty( code ) )
{
newContext.ProblemDetails.Extensions[nameof( code )] = code;
}
Expand Down
10 changes: 10 additions & 0 deletions src/Common/test/Common.Acceptance.Tests/HttpContentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,30 @@ namespace Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
#endif
using System.Net.Http;
#if NETFRAMEWORK
using System.Net.Http.Formatting;
#else
using System.Net.Http.Json;
#endif

internal static class HttpContentExtensions
{
#if NETFRAMEWORK
private static readonly JsonMediaTypeFormatter ProblemDetailsMediaTypeFormatter = new()
{
SupportedMediaTypes = { new( ProblemDetailsDefaults.MediaType.Json ) },
};
private static readonly IEnumerable<MediaTypeFormatter> MediaTypeFormatters = new[] { ProblemDetailsMediaTypeFormatter };
#endif

public static Task<ProblemDetails> ReadAsProblemDetailsAsync(
this HttpContent content,
CancellationToken cancellationToken = default ) =>
#if NETFRAMEWORK
content.ReadAsAsync<ProblemDetails>( MediaTypeFormatters, cancellationToken );
#else
content.ReadFromJsonAsync<ProblemDetails>( cancellationToken );
#endif

#pragma warning disable IDE0060 // Remove unused parameter
#pragma warning disable IDE0079 // Remove unnecessary suppression
Expand Down
Loading