Skip to content
Open
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 @@ -5,6 +5,7 @@
namespace Microsoft.Extensions.DependencyInjection;

using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;

public class IServiceCollectionExtensionsTest
Expand All @@ -25,4 +26,35 @@ public void add_api_versioning_should_not_allow_default_neutral_api_version()
// assert
options.Should().Throw<OptionsValidationException>();
}

// REF: https://github.com/dotnet/aspnet-api-versioning/issues/1191
[Fact]
public void add_api_versioning_should_not_displace_or_wrap_user_registered_problem_details_writers()
{
// arrange
var services = new ServiceCollection();
var customWriter = new TestProblemDetailsWriter();

services.AddProblemDetails();
services.AddSingleton<IProblemDetailsWriter>( customWriter );

var writersBefore = services.Where( s => s.ServiceType == typeof( IProblemDetailsWriter ) ).ToArray();

// act
services.AddApiVersioning();

// assert
var writersAfter = services.Where( s => s.ServiceType == typeof( IProblemDetailsWriter ) ).ToArray();
writersAfter.Should().Equal( writersBefore );

using var provider = services.BuildServiceProvider();
provider.GetServices<IProblemDetailsWriter>().Should().Contain( customWriter );
}

private sealed class TestProblemDetailsWriter : IProblemDetailsWriter
{
public bool CanWrite( ProblemDetailsContext context ) => true;

public ValueTask WriteAsync( ProblemDetailsContext context ) => ValueTask.CompletedTask;
}
}
Loading