Merge pull request #8641 from dotnet-maestro-bot/merge/release/2.2-to-master
[automated] Merge branch 'release/2.2' => 'master'
This commit is contained in:
commit
ce11eb9b71
|
|
@ -151,5 +151,30 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
builder.Services.Configure<MvcCompatibilityOptions>(o => o.CompatibilityVersion = version);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures <see cref="ApiBehaviorOptions"/>.
|
||||
/// </summary>
|
||||
/// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
|
||||
/// <param name="setupAction">The configure action.</param>
|
||||
/// <returns>The <see cref="IMvcBuilder"/>.</returns>
|
||||
public static IMvcBuilder ConfigureApiBehaviorOptions(
|
||||
this IMvcBuilder builder,
|
||||
Action<ApiBehaviorOptions> setupAction)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
if (setupAction == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(setupAction));
|
||||
}
|
||||
|
||||
builder.Services.Configure(setupAction);
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,6 +169,31 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures <see cref="ApiBehaviorOptions"/>.
|
||||
/// </summary>
|
||||
/// <param name="builder">The <see cref="IMvcCoreBuilder"/>.</param>
|
||||
/// <param name="setupAction">The configure action.</param>
|
||||
/// <returns>The <see cref="IMvcCoreBuilder"/>.</returns>
|
||||
public static IMvcCoreBuilder ConfigureApiBehaviorOptions(
|
||||
this IMvcCoreBuilder builder,
|
||||
Action<ApiBehaviorOptions> setupAction)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
if (setupAction == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(setupAction));
|
||||
}
|
||||
|
||||
builder.Services.Configure(setupAction);
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="CompatibilityVersion"/> for ASP.NET Core MVC for the application.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc.Controllers;
|
|||
using Microsoft.AspNetCore.Mvc.Internal;
|
||||
using Microsoft.AspNetCore.Mvc.MvcServiceCollectionExtensionsTestControllers;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -110,6 +111,33 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
Assert.Single(collection, d => d.ServiceType.Equals(typeof(ControllerTwo)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConfigureApiBehaviorOptions_InvokesSetupAction()
|
||||
{
|
||||
// Arrange
|
||||
var serviceCollection = new ServiceCollection()
|
||||
.AddOptions();
|
||||
|
||||
var builder = new MvcBuilder(
|
||||
serviceCollection,
|
||||
new ApplicationPartManager());
|
||||
|
||||
var part = new TestApplicationPart();
|
||||
|
||||
// Act
|
||||
var result = builder.ConfigureApiBehaviorOptions(o =>
|
||||
{
|
||||
o.SuppressMapClientErrors = true;
|
||||
});
|
||||
|
||||
// Assert
|
||||
var options = serviceCollection.
|
||||
BuildServiceProvider()
|
||||
.GetRequiredService<IOptions<ApiBehaviorOptions>>()
|
||||
.Value;
|
||||
Assert.True(options.SuppressMapClientErrors);
|
||||
}
|
||||
|
||||
private class ControllerOne
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Reflection;
|
|||
using Microsoft.AspNetCore.Mvc.ApplicationParts;
|
||||
using Microsoft.AspNetCore.Mvc.Internal;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -51,5 +52,32 @@ namespace Microsoft.AspNetCore.Mvc.DependencyInjection
|
|||
Assert.Same(result, builder);
|
||||
Assert.Equal(new ApplicationPart[] { part }, builder.PartManager.ApplicationParts.ToArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConfigureApiBehaviorOptions_InvokesSetupAction()
|
||||
{
|
||||
// Arrange
|
||||
var serviceCollection = new ServiceCollection()
|
||||
.AddOptions();
|
||||
|
||||
var builder = new MvcCoreBuilder(
|
||||
serviceCollection,
|
||||
new ApplicationPartManager());
|
||||
|
||||
var part = new TestApplicationPart();
|
||||
|
||||
// Act
|
||||
var result = builder.ConfigureApiBehaviorOptions(o =>
|
||||
{
|
||||
o.SuppressMapClientErrors = true;
|
||||
});
|
||||
|
||||
// Assert
|
||||
var options = serviceCollection.
|
||||
BuildServiceProvider()
|
||||
.GetRequiredService<IOptions<ApiBehaviorOptions>>()
|
||||
.Value;
|
||||
Assert.True(options.SuppressMapClientErrors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue