Merge pull request #8086 from dotnet-maestro-bot/merge/release/2.2-to-master
[automated] Merge branch 'release/2.2' => 'master'
This commit is contained in:
commit
16cea4073c
|
|
@ -101,28 +101,46 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
|
|||
protected ILogger Logger { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes and binds a model specified by <paramref name="parameter"/>.
|
||||
/// <para>
|
||||
/// This method overload is obsolete and will be removed in a future version. The recommended alternative is
|
||||
/// <see cref="BindModelAsync(ActionContext, IModelBinder, IValueProvider, ParameterDescriptor, ModelMetadata, object)" />.
|
||||
/// </para>
|
||||
/// <para>Initializes and binds a model specified by <paramref name="parameter"/>.</para>
|
||||
/// </summary>
|
||||
/// <param name="actionContext">The <see cref="ActionContext"/>.</param>
|
||||
/// <param name="valueProvider">The <see cref="IValueProvider"/>.</param>
|
||||
/// <param name="parameter">The <see cref="ParameterDescriptor"/></param>
|
||||
/// <returns>The result of model binding.</returns>
|
||||
[Obsolete("This method overload is obsolete and will be removed in a future version. The recommended " +
|
||||
"alternative is the overload that also takes " + nameof(IModelBinder) + ", " + nameof(ModelMetadata) +
|
||||
" and " + nameof(Object) + " parameters.")]
|
||||
public Task<ModelBindingResult> BindModelAsync(
|
||||
ActionContext actionContext,
|
||||
IValueProvider valueProvider,
|
||||
ParameterDescriptor parameter)
|
||||
{
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
return BindModelAsync(actionContext, valueProvider, parameter, value: null);
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// This method overload is obsolete and will be removed in a future version. The recommended alternative is
|
||||
/// <see cref="BindModelAsync(ActionContext, IModelBinder, IValueProvider, ParameterDescriptor, ModelMetadata, object)" />.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Binds a model specified by <paramref name="parameter"/> using <paramref name="value"/> as the initial value.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="actionContext">The <see cref="ActionContext"/>.</param>
|
||||
/// <param name="valueProvider">The <see cref="IValueProvider"/>.</param>
|
||||
/// <param name="parameter">The <see cref="ParameterDescriptor"/></param>
|
||||
/// <param name="value">The initial model value.</param>
|
||||
/// <returns>The result of model binding.</returns>
|
||||
[Obsolete("This method overload is obsolete and will be removed in a future version. The recommended " +
|
||||
"alternative is the overload that also takes " + nameof(IModelBinder) + " and " + nameof(ModelMetadata) +
|
||||
" parameters.")]
|
||||
public virtual Task<ModelBindingResult> BindModelAsync(
|
||||
ActionContext actionContext,
|
||||
IValueProvider valueProvider,
|
||||
|
|
|
|||
|
|
@ -30,7 +30,9 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
|||
ParameterType = type,
|
||||
};
|
||||
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
return await _parameterBinder.BindModelAsync(pageContext, valueProvider, parameterDescriptor, value);
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
}
|
||||
|
||||
private static async Task<CompositeValueProvider> GetCompositeValueProvider(PageContext pageContext)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ using Microsoft.AspNetCore.Mvc.Controllers;
|
|||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Internal;
|
||||
|
|
@ -450,57 +449,10 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
}
|
||||
}
|
||||
|
||||
private class TestParameterBinder : ParameterBinder
|
||||
{
|
||||
private readonly IDictionary<string, object> _actionParameters;
|
||||
|
||||
public TestParameterBinder(IDictionary<string, object> actionParameters)
|
||||
: base(
|
||||
new EmptyModelMetadataProvider(),
|
||||
TestModelBinderFactory.CreateDefault(),
|
||||
Mock.Of<IObjectModelValidator>(),
|
||||
Options.Create(new MvcOptions
|
||||
{
|
||||
AllowValidatingTopLevelNodes = true,
|
||||
}),
|
||||
NullLoggerFactory.Instance)
|
||||
{
|
||||
_actionParameters = actionParameters;
|
||||
}
|
||||
|
||||
public override Task<ModelBindingResult> BindModelAsync(
|
||||
ActionContext actionContext,
|
||||
IValueProvider valueProvider,
|
||||
ParameterDescriptor parameter,
|
||||
object value)
|
||||
{
|
||||
if (_actionParameters.TryGetValue(parameter.Name, out var result))
|
||||
{
|
||||
return Task.FromResult(ModelBindingResult.Success(result));
|
||||
}
|
||||
|
||||
return Task.FromResult(ModelBindingResult.Failed());
|
||||
}
|
||||
|
||||
public Task BindArgumentsAsync(
|
||||
ControllerContext controllerContext,
|
||||
object controller,
|
||||
IDictionary<string, object> arguments)
|
||||
{
|
||||
foreach (var entry in _actionParameters)
|
||||
{
|
||||
arguments.Add(entry.Key, entry.Value);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class TestController
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
private enum TestResourceFilterAction
|
||||
{
|
||||
ShortCircuit,
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
|
|||
|
||||
[Theory]
|
||||
[MemberData(nameof(BindModelAsyncData))]
|
||||
public async Task BindModelAsync_PassesExpectedBindingInfoAndMetadata_IfPrefixDoesNotMatch(
|
||||
public async Task ObsoleteBindModelAsync_PassesExpectedBindingInfoAndMetadata_IfPrefixDoesNotMatch(
|
||||
BindingInfo parameterBindingInfo,
|
||||
string metadataBinderModelName,
|
||||
string parameterName,
|
||||
|
|
@ -116,13 +116,15 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
|
|||
var controllerContext = GetControllerContext();
|
||||
|
||||
// Act & Assert
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
await parameterBinder.BindModelAsync(controllerContext, new SimpleValueProvider(), parameterDescriptor);
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
Assert.True(binderExecuted);
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BindModelAsync_PassesExpectedBindingInfoAndMetadata_IfPrefixMatches()
|
||||
public async Task ObsoleteBindModelAsync_PassesExpectedBindingInfoAndMetadata_IfPrefixMatches()
|
||||
{
|
||||
// Arrange
|
||||
var expectedModelName = "expectedName";
|
||||
|
|
@ -174,7 +176,9 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
|
|||
var controllerContext = GetControllerContext();
|
||||
|
||||
// Act & Assert
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
await argumentBinder.BindModelAsync(controllerContext, valueProvider, parameterDescriptor);
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
Assert.True(binderExecuted);
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -64,6 +64,11 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests
|
|||
}
|
||||
}
|
||||
|
||||
public static ParameterBinder GetParameterBinder(ModelBindingTestContext testContext)
|
||||
{
|
||||
return GetParameterBinder(testContext.HttpContext.RequestServices);
|
||||
}
|
||||
|
||||
public static ParameterBinder GetParameterBinder(IServiceProvider serviceProvider)
|
||||
{
|
||||
var metadataProvider = serviceProvider.GetRequiredService<IModelMetadataProvider>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue