Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
Respect SuppressInferBindingSourcesForParameters
Browse files Browse the repository at this point in the history
Fixes #8657
  • Loading branch information
pranavkm committed Oct 30, 2018
1 parent 35d2ab3 commit 4e286fe
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
Expand Up @@ -59,7 +59,10 @@ public void Apply(ControllerModel controller)

internal void InferParameterBindingSources(ActionModel action)
{
var inferredBindingSources = new BindingSource[action.Parameters.Count];
if (SuppressInferBindingSourcesForParameters)
{
return;
}

for (var i = 0; i < action.Parameters.Count; i++)
{
Expand Down
Expand Up @@ -93,6 +93,68 @@ public void InferParameterBindingSources_Throws_IfMultipleParametersAreFromBody(
Assert.Equal(expected, ex.Message);
}

[Fact]
public void InferParameterBindingSources_InfersSources()
{
// Arrange
var actionName = nameof(ParameterBindingController.ComplexTypeModelWithCancellationToken);
var convention = GetConvention();
var action = GetActionModel(typeof(ParameterBindingController), actionName);

// Act
convention.InferParameterBindingSources(action);

// Assert
Assert.Collection(
action.Parameters,
parameter =>
{
Assert.Equal("model", parameter.Name);
var bindingInfo = parameter.BindingInfo;
Assert.NotNull(bindingInfo);
Assert.Same(BindingSource.Body, bindingInfo.BindingSource);
},
parameter =>
{
Assert.Equal("cancellationToken", parameter.Name);
var bindingInfo = parameter.BindingInfo;
Assert.NotNull(bindingInfo);
Assert.Equal(BindingSource.Special, bindingInfo.BindingSource);
});
}

[Fact]
public void InferParameterBindingSources_DoesNotInferSources_IfSuppressInferBindingSourcesForParametersIsSet()
{
// Arrange
var actionName = nameof(ParameterBindingController.ComplexTypeModelWithCancellationToken);
var convention = GetConvention();
convention.SuppressInferBindingSourcesForParameters = true;
var action = GetActionModel(typeof(ParameterBindingController), actionName);

// Act
convention.InferParameterBindingSources(action);

// Assert
Assert.Collection(
action.Parameters,
parameter =>
{
Assert.Equal("model", parameter.Name);
Assert.Null(parameter.BindingInfo);
},
parameter =>
{
Assert.Equal("cancellationToken", parameter.Name);
var bindingInfo = parameter.BindingInfo;
Assert.NotNull(bindingInfo);
Assert.Equal(BindingSource.Special, bindingInfo.BindingSource);
});
}

[Fact]
public void Apply_PreservesBindingInfo_WhenInferringFor_ParameterWithModelBinder_AndExplicitName()
{
Expand Down

0 comments on commit 4e286fe

Please sign in to comment.