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

Commit

Permalink
Array or List in query string does not get parsed #7712
Browse files Browse the repository at this point in the history
#7712
Test case added
  • Loading branch information
kishan.anem committed Jun 26, 2018
1 parent 7c00844 commit c2d8123
Showing 1 changed file with 25 additions and 28 deletions.
Expand Up @@ -483,31 +483,6 @@ public void OnProvidersExecuting_PreservesBindingInfo_WhenInferringFor_Parameter
Assert.Equal("top", bindingInfo.BinderModelName);
}

[Fact]
public void OnProvidersExecuting_PreservesBindingInfo_WhenInferringFor_ParameterWithModelBinder_WithoutExplicitName_OnCollection()
{
// Arrange
var modelMetadataProvider = TestModelMetadataProvider.CreateDefaultProvider();
var actionName = nameof(ModelBinderOnParameterController.ModelBinderAttributeWithOutExplicitModelNameOnCollection);
var context = GetContext(typeof(ModelBinderOnParameterController), modelMetadataProvider);
var provider = GetProvider();

// Act
provider.OnProvidersExecuting(context);

// Assert
var controller = Assert.Single(context.Result.Controllers);
var action = Assert.Single(controller.Actions, a => a.ActionName == actionName);
var parameter = Assert.Single(action.Parameters);

var bindingInfo = parameter.BindingInfo;

Assert.NotNull(bindingInfo);
Assert.Same(BindingSource.Query, bindingInfo.BindingSource);
Assert.Null(bindingInfo.BinderModelName);

}

[Fact]
public void OnProvidersExecuting_PreservesBindingInfo_WhenInferringFor_ParameterWithModelBinderType()
{
Expand Down Expand Up @@ -890,6 +865,22 @@ public void InferBoundPropertyModelPrefixes_SetsModelPrefix_ForComplexTypeFromVa
Assert.Equal(string.Empty, property.BindingInfo.BinderModelName);
}

[Fact]
public void InferBoundPropertyModelPrefixes_SetsModelPrefix_ForCollectionTypeFromValueProvider()
{
// Arrange
var controller = GetControllerModel(typeof(ControllerWithBoundCollectionProperty));

var provider = GetProvider();

// Act
provider.InferBoundPropertyModelPrefixes(controller);

// Assert
var property = Assert.Single(controller.ControllerProperties);
Assert.Null(property.BindingInfo.BinderModelName);
}

[Fact]
public void InferParameterModelPrefixes_SetsModelPrefix_ForComplexTypeFromValueProvider()
{
Expand Down Expand Up @@ -1212,9 +1203,6 @@ private class ModelBinderOnParameterController
[HttpGet]
public IActionResult ModelBinderAttributeWithExplicitModelName([ModelBinder(Name = "top")] int value) => null;

[HttpGet]
public IActionResult ModelBinderAttributeWithOutExplicitModelNameOnCollection([ModelBinder] int[] value) => null;

[HttpGet]
public IActionResult ModelBinderType([ModelBinder(typeof(TestModelBinder))] string name) => null;

Expand Down Expand Up @@ -1279,6 +1267,15 @@ private class ControllerWithBoundProperty
public IActionResult SomeAction([FromQuery] TestModel test) => null;
}

[ApiController]
private class ControllerWithBoundCollectionProperty
{
[FromQuery]
public List<int> TestProperty { get; set; }

public IActionResult SomeAction([FromQuery] List<int> test) => null;
}

private class Car { }

[ApiController]
Expand Down

0 comments on commit c2d8123

Please sign in to comment.