From 88ac4b94e451441da2a03c9f2f5a3c54b73f45cf Mon Sep 17 00:00:00 2001 From: Harsh Gupta Date: Tue, 12 May 2015 16:46:24 -0700 Subject: [PATCH] Fixing #2466, #2446. The assumption is ModelState should have entries if 1. An error is explicitly added by a model binder. 2. There is validation error reported while validating the model. 3. There is value bound by the model binder. With this change there should be no extra entry other than for the cases mentioned above. Also enabling the integration test cases. --- .../Validation/DefaultObjectValidator.cs | 4 +- .../ActionParametersIntegrationTest.cs | 39 ++--- .../ArrayModelBinderIntegrationTest.cs | 26 +-- ...nderTypeBasedModelBinderIntegrationTest.cs | 50 ++++-- .../BodyValidationIntegrationTests.cs | 64 ++++++- .../ByteArrayModelBinderIntegrationTest.cs | 6 +- ...ellationTokenModelBinderIntegrationTest.cs | 2 +- .../CollectionModelBinderIntegrationTest.cs | 28 +-- .../DictionaryModelBinderIntegrationTest.cs | 24 +-- ...rmCollectionModelBindingIntegrationTest.cs | 13 +- .../FormFileModelBindingIntegrationTest.cs | 10 +- .../GenericModelBinderIntegrationTest.cs | 36 ++-- .../HeaderModelBinderIntegrationTest.cs | 6 +- .../KeyValuePairModelBinderIntegrationTest.cs | 26 +-- ...MutableObjectModelBinderIntegrationTest.cs | 161 +++++++++--------- .../ServicesModelBinderIntegrationTest.cs | 13 +- .../TryUpdateModelIntegrationTest.cs | 32 ++-- ...TypeConverterModelBinderIntegrationTest.cs | 10 +- .../ValidationIntegrationTests.cs | 76 ++++----- 19 files changed, 352 insertions(+), 274 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/DefaultObjectValidator.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/DefaultObjectValidator.cs index 4a3c5ed0a0..f2b534625b 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/DefaultObjectValidator.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/DefaultObjectValidator.cs @@ -257,7 +257,9 @@ private static bool ShallowValidate( } } - if (isValid) + // Add an entry only if there was an entry which was added by a model binder. + // This prevents adding spurious entries. + if (modelState.ContainsKey(modelKey) && isValid) { validationContext.ModelValidationContext.ModelState.MarkFieldValid(modelKey); } diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/ActionParametersIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/ActionParametersIntegrationTest.cs index f9dfc27bcd..007fe6eb7c 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/ActionParametersIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/ActionParametersIntegrationTest.cs @@ -28,20 +28,20 @@ public Person3() public List
Address { get; } } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task ActionParameter_NonSettableCollectionModel_EmptyPrefix_GetsBound() { // Arrange var argumentBinder = ModelBindingTestHelper.GetArgumentBinder(); var parameter = new ParameterDescriptor() { - Name = "Address", + Name = "prefix", ParameterType = typeof(Person3) }; var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => { - request.QueryString = QueryString.Create("[0].Street", "SomeStreet"); + request.QueryString = QueryString.Create("Address[0].Street", "SomeStreet"); }); var modelState = new ModelStateDictionary(); @@ -64,7 +64,7 @@ public async Task ActionParameter_NonSettableCollectionModel_EmptyPrefix_GetsBou Assert.True(modelState.IsValid); Assert.Equal(1, modelState.Keys.Count); - var key = Assert.Single(modelState.Keys, k => k == "[0].Street"); + var key = Assert.Single(modelState.Keys, k => k == "Address[0].Street"); Assert.NotNull(modelState[key].Value); Assert.Equal("SomeStreet", modelState[key].Value.AttemptedValue); Assert.Equal("SomeStreet", modelState[key].Value.RawValue); @@ -77,19 +77,19 @@ private class Person6 public CustomReadOnlyCollection
Address { get; set; } } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task ActionParameter_ReadOnlyCollectionModel_EmptyPrefix_DoesNotGetBound() { // Arrange var argumentBinder = ModelBindingTestHelper.GetArgumentBinder(); var parameter = new ParameterDescriptor() { - Name = "Address", + Name = "prefix", ParameterType = typeof(Person6) }; var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => { - request.QueryString = QueryString.Create("[0].Street", "SomeStreet"); + request.QueryString = QueryString.Create("Address[0].Street", "SomeStreet"); }); var modelState = new ModelStateDictionary(); @@ -119,20 +119,20 @@ private class Person4 public Address[] Address { get; set; } } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task ActionParameter_SettableArrayModel_EmptyPrefix_GetsBound() { // Arrange var argumentBinder = ModelBindingTestHelper.GetArgumentBinder(); var parameter = new ParameterDescriptor() { - Name = "Address", + Name = "prefix", ParameterType = typeof(Person4) }; var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => { - request.QueryString = QueryString.Create("[0].Street", "SomeStreet"); + request.QueryString = QueryString.Create("Address[0].Street", "SomeStreet"); }); var modelState = new ModelStateDictionary(); @@ -147,6 +147,7 @@ public async Task ActionParameter_SettableArrayModel_EmptyPrefix_GetsBound() // Model Assert.NotNull(modelBindingResult.Model); var boundModel = Assert.IsType(modelBindingResult.Model); + Assert.NotNull(boundModel.Address); Assert.Equal(1, boundModel.Address.Count()); Assert.Equal("SomeStreet", boundModel.Address[0].Street); @@ -154,7 +155,7 @@ public async Task ActionParameter_SettableArrayModel_EmptyPrefix_GetsBound() Assert.True(modelState.IsValid); Assert.Equal(1, modelState.Keys.Count); - var key = Assert.Single(modelState.Keys, k => k == "[0].Street"); + var key = Assert.Single(modelState.Keys, k => k == "Address[0].Street"); Assert.NotNull(modelState[key].Value); Assert.Equal("SomeStreet", modelState[key].Value.AttemptedValue); Assert.Equal("SomeStreet", modelState[key].Value.RawValue); @@ -167,20 +168,20 @@ private class Person5 public Address[] Address { get; } = new Address[] { }; } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task ActionParameter_NonSettableArrayModel_EmptyPrefix_DoesNotGetBound() { // Arrange var argumentBinder = ModelBindingTestHelper.GetArgumentBinder(); var parameter = new ParameterDescriptor() { - Name = "Address", + Name = "prefix", ParameterType = typeof(Person5) }; var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => { - request.QueryString = QueryString.Create("[0].Street", "SomeStreet"); + request.QueryString = QueryString.Create("Address[0].Street", "SomeStreet"); }); var modelState = new ModelStateDictionary(); @@ -204,7 +205,7 @@ public async Task ActionParameter_NonSettableArrayModel_EmptyPrefix_DoesNotGetBo Assert.Empty(modelState.Keys); } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task ActionParameter_NonSettableCollectionModel_WithPrefix_GetsBound() { // Arrange @@ -251,7 +252,7 @@ public async Task ActionParameter_NonSettableCollectionModel_WithPrefix_GetsBoun Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState); } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task ActionParameter_ReadOnlyCollectionModel_WithPrefix_DoesNotGetBound() { // Arrange @@ -292,7 +293,7 @@ public async Task ActionParameter_ReadOnlyCollectionModel_WithPrefix_DoesNotGetB Assert.Empty(modelState.Keys); } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task ActionParameter_SettableArrayModel_WithPrefix_GetsBound() { // Arrange @@ -339,7 +340,7 @@ public async Task ActionParameter_SettableArrayModel_WithPrefix_GetsBound() Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState); } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task ActionParameter_NonSettableArrayModel_WithPrefix_DoesNotGetBound() { // Arrange @@ -369,7 +370,7 @@ public async Task ActionParameter_NonSettableArrayModel_WithPrefix_DoesNotGetBou // Model Assert.NotNull(modelBindingResult.Model); - var boundModel = Assert.IsType(modelBindingResult.Model); + var boundModel = Assert.IsType(modelBindingResult.Model); // Arrays should not be updated. Assert.Equal(0, boundModel.Address.Count()); diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/ArrayModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/ArrayModelBinderIntegrationTest.cs index a9b30377d9..94e59a69ff 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/ArrayModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/ArrayModelBinderIntegrationTest.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Integration tests targeting the behavior of the ArrayModelBinder with other model binders. public class ArrayModelBinderIntegrationTest { - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task ArrayModelBinder_BindsArrayOfSimpleType_WithPrefix_Success() { // Arrange @@ -39,7 +39,7 @@ public async Task ArrayModelBinder_BindsArrayOfSimpleType_WithPrefix_Success() var model = Assert.IsType(modelBindingResult.Model); Assert.Equal(new int[] { 10, 11 }, model); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -52,7 +52,7 @@ public async Task ArrayModelBinder_BindsArrayOfSimpleType_WithPrefix_Success() Assert.Equal("11", entry.Value.RawValue); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task ArrayModelBinder_BindsArrayOfSimpleType_WithExplicitPrefix_Success() { // Arrange @@ -84,7 +84,7 @@ public async Task ArrayModelBinder_BindsArrayOfSimpleType_WithExplicitPrefix_Suc var model = Assert.IsType(modelBindingResult.Model); Assert.Equal(new int[] { 10, 11 }, model); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -97,7 +97,7 @@ public async Task ArrayModelBinder_BindsArrayOfSimpleType_WithExplicitPrefix_Suc Assert.Equal("11", entry.Value.RawValue); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task ArrayModelBinder_BindsArrayOfSimpleType_EmptyPrefix_Success() { // Arrange @@ -125,7 +125,7 @@ public async Task ArrayModelBinder_BindsArrayOfSimpleType_EmptyPrefix_Success() var model = Assert.IsType(modelBindingResult.Model); Assert.Equal(new int[] { 10, 11 }, model); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -174,7 +174,7 @@ private class Person public string Name { get; set; } } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task ArrayModelBinder_BindsArrayOfComplexType_WithPrefix_Success() { // Arrange @@ -203,7 +203,7 @@ public async Task ArrayModelBinder_BindsArrayOfComplexType_WithPrefix_Success() Assert.Equal("bill", model[0].Name); Assert.Equal("lang", model[1].Name); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -216,7 +216,7 @@ public async Task ArrayModelBinder_BindsArrayOfComplexType_WithPrefix_Success() Assert.Equal("lang", entry.Value.RawValue); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task ArrayModelBinder_BindsArrayOfComplexType_WithExplicitPrefix_Success() { // Arrange @@ -233,7 +233,7 @@ public async Task ArrayModelBinder_BindsArrayOfComplexType_WithExplicitPrefix_Su var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => { - request.QueryString = new QueryString("?prefix[0].Name=bill&prefix[1]=lang"); + request.QueryString = new QueryString("?prefix[0].Name=bill&prefix[1].Name=lang"); }); var modelState = new ModelStateDictionary(); @@ -249,7 +249,7 @@ public async Task ArrayModelBinder_BindsArrayOfComplexType_WithExplicitPrefix_Su Assert.Equal("bill", model[0].Name); Assert.Equal("lang", model[1].Name); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -262,7 +262,7 @@ public async Task ArrayModelBinder_BindsArrayOfComplexType_WithExplicitPrefix_Su Assert.Equal("lang", entry.Value.RawValue); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task ArrayModelBinder_BindsArrayOfComplexType_EmptyPrefix_Success() { // Arrange @@ -291,7 +291,7 @@ public async Task ArrayModelBinder_BindsArrayOfComplexType_EmptyPrefix_Success() Assert.Equal("bill", model[0].Name); Assert.Equal("lang", model[1].Name); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/BinderTypeBasedModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/BinderTypeBasedModelBinderIntegrationTest.cs index 19fd5fac9a..f38f7a749a 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/BinderTypeBasedModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/BinderTypeBasedModelBinderIntegrationTest.cs @@ -2,8 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Globalization; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.ModelBinding; +using Microsoft.AspNet.Testing; using Xunit; namespace Microsoft.AspNet.Mvc.IntegrationTests @@ -130,6 +132,7 @@ public async Task BindParameter_WithOutModelBinderType_NoData() // Ensures that prefix is part of the result returned back. [Fact] + [ReplaceCulture] public async Task BindParameter_WithData_WithPrefix_GetsBound() { // Arrange @@ -163,7 +166,8 @@ public async Task BindParameter_WithData_WithPrefix_GetsBound() Assert.True(modelState.IsValid); var key = Assert.Single(modelState.Keys); Assert.Equal("CustomParameter", key); - Assert.Null(modelState[key].Value); // value is only set if the custom model binder sets it. + Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState); + Assert.NotNull(modelState[key].Value); // Value is set by test model binder, no need to validate it. } private class Person @@ -177,7 +181,7 @@ private class Address public string Street { get; set; } } - [Fact(Skip = "Extra entries in model state #2446")] + [Fact] public async Task BindProperty_WithData_EmptyPrefix_GetsBound() { // Arrange @@ -209,16 +213,13 @@ public async Task BindProperty_WithData_EmptyPrefix_GetsBound() // ModelState Assert.True(modelState.IsValid); - // Should there be another key for what is there in the complex object ? - // This should probably behave like body binder, where even the body gets validated by default. - Assert.Equal(2, modelState.Keys.Count); + Assert.Equal(1, modelState.Keys.Count); var key = Assert.Single(modelState.Keys, k => k == "Parameter1.Address.Street"); - Assert.Null(modelState[key].Value); // value is only set if the custom model binder sets it. - key = Assert.Single(modelState.Keys, k => k == "Parameter1.Address"); - Assert.Null(modelState[key].Value); // value is only set if the custom model binder sets it. + Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState); + Assert.NotNull(modelState[key].Value); // Value is set by test model binder, no need to validate it. } - [Fact(Skip = "Extra entries in model state #2446")] + [Fact] public async Task BindProperty_WithData_WithPrefix_GetsBound() { // Arrange @@ -252,14 +253,10 @@ public async Task BindProperty_WithData_WithPrefix_GetsBound() // ModelState Assert.True(modelState.IsValid); - - // Should there be another key for what is there in the complex object ? - // This should probably behave like body binder, where even the body gets validated by default. - Assert.Equal(2, modelState.Keys.Count); + Assert.Equal(1, modelState.Keys.Count); var key = Assert.Single(modelState.Keys, k => k == "CustomParameter.Address.Street"); - Assert.Null(modelState[key].Value); // value is only set if the custom model binder sets it. - key = Assert.Single(modelState.Keys, k => k == "CustomParameter.Address"); - Assert.Null(modelState[key].Value); // value is only set if the custom model binder sets it. + Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState); + Assert.NotNull(modelState[key].Value); // Value is set by test model binder, no need to validate it. } private class AddressModelBinder : IModelBinder @@ -273,7 +270,22 @@ public Task BindModelAsync(ModelBindingContext bindingContex var address = new Address() { Street = "SomeStreet" }; - return Task.FromResult(new ModelBindingResult(address, bindingContext.ModelName, true)); + bindingContext.ModelState.SetModelValue( + ModelNames.CreatePropertyModelName(bindingContext.ModelName, "Street"), + new ValueProviderResult( + address.Street, + address.Street, + CultureInfo.CurrentCulture)); + + var validationNode = new ModelValidationNode( + bindingContext.ModelName, + bindingContext.ModelMetadata, + address) + { + ValidateAllProperties = true + }; + + return Task.FromResult(new ModelBindingResult(address, bindingContext.ModelName, true, validationNode)); } } @@ -282,6 +294,10 @@ private class SuccessModelBinder : IModelBinder public Task BindModelAsync(ModelBindingContext bindingContext) { var model = "Success"; + bindingContext.ModelState.SetModelValue( + bindingContext.ModelName, + new ValueProviderResult(model, model, CultureInfo.CurrentCulture)); + var modelValidationNode = new ModelValidationNode( bindingContext.ModelName, bindingContext.ModelMetadata, diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/BodyValidationIntegrationTests.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/BodyValidationIntegrationTests.cs index e02a7120e0..23f7c529aa 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/BodyValidationIntegrationTests.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/BodyValidationIntegrationTests.cs @@ -27,7 +27,7 @@ private class Address public string Street { get; set; } } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task FromBodyAndRequiredOnProperty_EmptyBody_AddsModelStateError() { // Arrange @@ -171,7 +171,7 @@ private class Address2 public int Zip { get; set; } } - [Theory] + [Theory(Skip = "There should be entries for all model properties which are bound. #2445")] [InlineData("{ \"Zip\" : 123 }")] [InlineData("{}")] public async Task FromBodyOnTopLevelProperty_RequiredOnSubProperty_AddsModelStateError(string inputText) @@ -214,5 +214,65 @@ public async Task FromBodyOnTopLevelProperty_RequiredOnSubProperty_AddsModelStat var error = Assert.Single(modelState[street].Errors); Assert.Equal("The Street field is required.", error.ErrorMessage); } + + private class Person3 + { + [FromBody] + public Address3 Address { get; set; } + } + + private class Address3 + { + public string Street { get; set; } + + [Required] + public int Zip { get; set; } + } + + [Theory(Skip = "There should be entries for all model properties which are bound. #2445")] + [InlineData("{ \"Street\" : \"someStreet\" }")] + [InlineData("{}")] + public async Task FromBodyOnProperty_RequiredOnValueTypeSubProperty_AddsModelStateError(string inputText) + { + // Arrange + var argumentBinder = ModelBindingTestHelper.GetArgumentBinder(); + var parameter = new ParameterDescriptor() + { + BindingInfo = new BindingInfo() + { + BinderModelName = "CustomParameter", + }, + ParameterType = typeof(Person3) + }; + + var operationContext = ModelBindingTestHelper.GetOperationBindingContext( + request => + { + request.Body = new MemoryStream(Encoding.UTF8.GetBytes(inputText)); + request.ContentType = "application/json"; + }); + var modelState = new ModelStateDictionary(); + + // Act + var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); + + // Assert + Assert.NotNull(modelBindingResult); + Assert.True(modelBindingResult.IsModelSet); + var boundPerson = Assert.IsType(modelBindingResult.Model); + Assert.NotNull(boundPerson); + Assert.False(modelState.IsValid); + var street = Assert.Single(modelState.Keys, k => k == "CustomParameter.Address.Street"); + Assert.Equal(ModelValidationState.Valid, modelState[street].ValidationState); + + // The error with an empty key is a bug(#2416) in our implementation which does not append the prefix and + // use that along with the path. The expected key here would be Address. + var zip = Assert.Single(modelState.Keys, k => k == "CustomParameter.Address.Zip"); + Assert.Equal(ModelValidationState.Valid, modelState[zip].ValidationState); + var error = Assert.Single(modelState[""].Errors); + Assert.StartsWith( + "Required property 'Zip' not found in JSON. Path ''", + error.Exception.Message); + } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/ByteArrayModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/ByteArrayModelBinderIntegrationTest.cs index 18ba1be4cd..4203930dea 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/ByteArrayModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/ByteArrayModelBinderIntegrationTest.cs @@ -16,7 +16,7 @@ private class Person public byte[] Token { get; set; } } - [Theory(Skip = "Extra entries in model state #2446, ModelState.Value not set due to #2445, #2447")] + [Theory(Skip = "ModelState.Value not set due to #2445, #2447")] [InlineData(true)] [InlineData(false)] public async Task BindProperty_WithData_GetsBound(bool fallBackScenario) @@ -61,7 +61,7 @@ public async Task BindProperty_WithData_GetsBound(bool fallBackScenario) // ModelState Assert.True(modelState.IsValid); - Assert.Equal(2, modelState.Keys.Count); // Should be only two keys. bug #2446 + Assert.Equal(2, modelState.Keys.Count); Assert.Single(modelState.Keys, k => k == prefix); Assert.Single(modelState.Keys, k => k == queryStringKey); @@ -109,7 +109,7 @@ public async Task BindParameter_NoData_DoesNotGetBound() Assert.Empty(modelState.Keys); } - [Fact(Skip = "ModelState.Value not set due to #2445, #2446")] + [Fact(Skip = "ModelState.Value not set due to #2445")] public async Task BindParameter_WithData_GetsBound() { // Arrange diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/CancellationTokenModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/CancellationTokenModelBinderIntegrationTest.cs index 9e6b76886c..88b0773ddb 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/CancellationTokenModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/CancellationTokenModelBinderIntegrationTest.cs @@ -66,7 +66,7 @@ public async Task BindProperty_WithData__WithPrefix_GetsBound() Assert.Equal(ModelValidationState.Skipped, modelState[key].ValidationState); } - [Fact(Skip = "CancellationToken should not be validated #2447,Extra entries in model state dictionary. #2466")] + [Fact(Skip = "CancellationToken should not be validated #2447")] public async Task BindProperty_WithData__WithEmptyPrefix_GetsBound() { // Arrange diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/CollectionModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/CollectionModelBinderIntegrationTest.cs index 74b4a2a27a..167cea94eb 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/CollectionModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/CollectionModelBinderIntegrationTest.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Note that CollectionModelBinder handles both ICollection{T} and IList{T} public class CollectionModelBinderIntegrationTest { - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task CollectionModelBinder_BindsListOfSimpleType_WithPrefix_Success() { // Arrange @@ -45,7 +45,7 @@ public async Task CollectionModelBinder_BindsListOfSimpleType_WithPrefix_Success var model = Assert.IsType>(modelBindingResult.Model); Assert.Equal(new List() { 10, 11 }, model); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -58,7 +58,7 @@ public async Task CollectionModelBinder_BindsListOfSimpleType_WithPrefix_Success Assert.Equal("11", entry.Value.RawValue); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task CollectionModelBinder_BindsListOfSimpleType_WithExplicitPrefix_Success() { // Arrange @@ -90,7 +90,7 @@ public async Task CollectionModelBinder_BindsListOfSimpleType_WithExplicitPrefix var model = Assert.IsType>(modelBindingResult.Model); Assert.Equal(new List() { 10, 11 }, model); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -103,7 +103,7 @@ public async Task CollectionModelBinder_BindsListOfSimpleType_WithExplicitPrefix Assert.Equal("11", entry.Value.RawValue); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task CollectionModelBinder_BindsCollectionOfSimpleType_EmptyPrefix_Success() { // Arrange @@ -131,7 +131,7 @@ public async Task CollectionModelBinder_BindsCollectionOfSimpleType_EmptyPrefix_ var model = Assert.IsType>(modelBindingResult.Model); Assert.Equal(new List { 10, 11 }, model); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -180,7 +180,7 @@ private class Person public int Id { get; set; } } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task CollectionModelBinder_BindsListOfComplexType_WithPrefix_Success() { // Arrange @@ -209,7 +209,7 @@ public async Task CollectionModelBinder_BindsListOfComplexType_WithPrefix_Succes Assert.Equal(10, model[0].Id); Assert.Equal(11, model[1].Id); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -222,7 +222,7 @@ public async Task CollectionModelBinder_BindsListOfComplexType_WithPrefix_Succes Assert.Equal("11", entry.Value.RawValue); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task CollectionModelBinder_BindsListOfComplexType_WithExplicitPrefix_Success() { // Arrange @@ -255,7 +255,7 @@ public async Task CollectionModelBinder_BindsListOfComplexType_WithExplicitPrefi Assert.Equal(10, model[0].Id); Assert.Equal(11, model[1].Id); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -268,7 +268,7 @@ public async Task CollectionModelBinder_BindsListOfComplexType_WithExplicitPrefi Assert.Equal("11", entry.Value.RawValue); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task CollectionModelBinder_BindsCollectionOfComplexType_EmptyPrefix_Success() { // Arrange @@ -276,7 +276,7 @@ public async Task CollectionModelBinder_BindsCollectionOfComplexType_EmptyPrefix var parameter = new ParameterDescriptor() { Name = "parameter", - ParameterType = typeof(ICollection) + ParameterType = typeof(List) }; var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => @@ -297,7 +297,7 @@ public async Task CollectionModelBinder_BindsCollectionOfComplexType_EmptyPrefix Assert.Equal(10, model[0].Id); Assert.Equal(11, model[1].Id); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -552,7 +552,7 @@ private class Address4 public string Street { get; set; } } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task CollectionModelBinder_UsesCustomIndexes() { // Arrange diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/DictionaryModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/DictionaryModelBinderIntegrationTest.cs index 63bc04b49c..792e0b7157 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/DictionaryModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/DictionaryModelBinderIntegrationTest.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Integration tests targeting the behavior of the DictionaryModelBinder with other model binders. public class DictionaryModelBinderIntegrationTest { - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task DictionaryModelBinder_BindsDictionaryOfSimpleType_WithPrefix_Success() { // Arrange @@ -41,7 +41,7 @@ public async Task DictionaryModelBinder_BindsDictionaryOfSimpleType_WithPrefix_S var model = Assert.IsType>(modelBindingResult.Model); Assert.Equal(new Dictionary() { { "key0", 10 } }, model); - Assert.Equal(2, modelState.Count); // Fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -54,7 +54,7 @@ public async Task DictionaryModelBinder_BindsDictionaryOfSimpleType_WithPrefix_S Assert.Equal("10", entry.Value.RawValue); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task DictionaryModelBinder_BindsDictionaryOfSimpleType_WithExplicitPrefix_Success() { // Arrange @@ -86,7 +86,7 @@ public async Task DictionaryModelBinder_BindsDictionaryOfSimpleType_WithExplicit var model = Assert.IsType>(modelBindingResult.Model); Assert.Equal(new Dictionary() { { "key0", 10 }, }, model); - Assert.Equal(2, modelState.Count); // Fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -99,7 +99,7 @@ public async Task DictionaryModelBinder_BindsDictionaryOfSimpleType_WithExplicit Assert.Equal("10", entry.Value.RawValue); } - [Fact(Skip = "Extra ModelState key because of #2446, IsValue == false because of #2470")] + [Fact(Skip = "IsValid == false because of #2470")] public async Task DictionaryModelBinder_BindsDictionaryOfSimpleType_EmptyPrefix_Success() { // Arrange @@ -127,7 +127,7 @@ public async Task DictionaryModelBinder_BindsDictionaryOfSimpleType_EmptyPrefix_ var model = Assert.IsType>(modelBindingResult.Model); Assert.Equal(new Dictionary() { { "key0", 10 }, }, model); - Assert.Equal(2, modelState.Count); // Fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); // Fails due to #2470 @@ -176,7 +176,7 @@ private class Person public int Id { get; set; } } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task DictionaryModelBinder_BindsDictionaryOfComplexType_WithPrefix_Success() { // Arrange @@ -206,7 +206,7 @@ public async Task DictionaryModelBinder_BindsDictionaryOfComplexType_WithPrefix_ Assert.Equal("key0", model.Keys.First()); Assert.Equal(model.Values, model.Values); - Assert.Equal(2, modelState.Count); // Fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -219,7 +219,7 @@ public async Task DictionaryModelBinder_BindsDictionaryOfComplexType_WithPrefix_ Assert.Equal("10", entry.Value.RawValue); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task DictionaryModelBinder_BindsDictionaryOfComplexType_WithExplicitPrefix_Success() { // Arrange @@ -253,7 +253,7 @@ public async Task DictionaryModelBinder_BindsDictionaryOfComplexType_WithExplici Assert.Equal("key0", model.Keys.First()); Assert.Equal(model.Values, model.Values); - Assert.Equal(2, modelState.Count); // Fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -266,7 +266,7 @@ public async Task DictionaryModelBinder_BindsDictionaryOfComplexType_WithExplici Assert.Equal("10", entry.Value.RawValue); } - [Fact(Skip = "Extra ModelState key because of #2446, IsValue == false because of #2470")] + [Fact(Skip = "IsValid == false because of #2470")] public async Task DictionaryModelBinder_BindsDictionaryOfComplexType_EmptyPrefix_Success() { // Arrange @@ -296,7 +296,7 @@ public async Task DictionaryModelBinder_BindsDictionaryOfComplexType_EmptyPrefix Assert.Equal("key0", model.Keys.First()); Assert.Equal(model.Values, model.Values); - Assert.Equal(2, modelState.Count); // Fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); // Fails due to #2470 diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/FormCollectionModelBindingIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/FormCollectionModelBindingIntegrationTest.cs index c9a1b075e8..d5b7e7afeb 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/FormCollectionModelBindingIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/FormCollectionModelBindingIntegrationTest.cs @@ -27,7 +27,7 @@ private class Address public FormCollection FileCollection { get; set; } } - [Fact(Skip = "ModelState.Value not set due to #2445, Extra entries in model state #2446.")] + [Fact(Skip = "ModelState.Value not set due to #2445")] public async Task BindProperty_WithData_WithEmptyPrefix_GetsBound() { // Arrange @@ -71,13 +71,13 @@ public async Task BindProperty_WithData_WithEmptyPrefix_GetsBound() Assert.True(modelState.IsValid); Assert.Equal(2, modelState.Count); Assert.Single(modelState.Keys, k => k == "Address.Zip"); - var key = Assert.Single(modelState.Keys, k => k == "Address.File"); // Should be only one key. bug #2446 + var key = Assert.Single(modelState.Keys, k => k == "Address.File"); Assert.NotNull(modelState[key].Value); // should be non null bug #2445. Assert.Empty(modelState[key].Errors); Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task BindParameter_WithData_GetsBound() { // Arrange @@ -125,10 +125,10 @@ public async Task BindParameter_WithData_GetsBound() // Validation should be skipped because we do not validate any parameters and since IFormFile is not // IValidatableObject, we should have no entries in the model state dictionary. - Assert.Empty(modelState.Keys); // Enable when we fix #2446. + Assert.Empty(modelState.Keys); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact(Skip = "FormCollection should not return null modelBindingResult for a type that matches. #2456")] public async Task BindParameter_NoData_DoesNotGetBound() { // Arrange @@ -147,7 +147,6 @@ public async Task BindParameter_NoData_DoesNotGetBound() // No data is passed. var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => { - request.ContentType = "multipart/form-data"; }); var modelState = new ModelStateDictionary(); @@ -158,7 +157,7 @@ public async Task BindParameter_NoData_DoesNotGetBound() // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); // Fails due to bug #2456 + Assert.NotNull(modelBindingResult); Assert.Null(modelBindingResult.Model); // ModelState diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/FormFileModelBindingIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/FormFileModelBindingIntegrationTest.cs index cf58601063..561ebe0c1b 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/FormFileModelBindingIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/FormFileModelBindingIntegrationTest.cs @@ -27,7 +27,7 @@ private class Address public IFormFile File { get; set; } } - [Fact(Skip = "ModelState.Value not set due to #2445, Extra entries in model state #2446.")] + [Fact(Skip = "ModelState.Value not set due to #2445")] public async Task BindProperty_WithData_WithEmptyPrefix_GetsBound() { // Arrange @@ -70,13 +70,13 @@ public async Task BindProperty_WithData_WithEmptyPrefix_GetsBound() Assert.True(modelState.IsValid); Assert.Equal(2, modelState.Count); Assert.Single(modelState.Keys, k => k == "Address.Zip"); - var key = Assert.Single(modelState.Keys, k => k == "Address.File"); // Should be only one key. bug #2446 + var key = Assert.Single(modelState.Keys, k => k == "Address.File"); Assert.NotNull(modelState[key].Value); // should be non null bug #2445. Assert.Empty(modelState[key].Errors); Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task BindParameter_WithData_GetsBound() { // Arrange @@ -122,10 +122,10 @@ public async Task BindParameter_WithData_GetsBound() // Validation should be skipped because we do not validate any parameters and since IFormFile is not // IValidatableObject, we should have no entries in the model state dictionary. - Assert.Empty(modelState.Keys); // Enable when we fix #2446. + Assert.Empty(modelState.Keys); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact(Skip = "FormFile Should not return null modelBindingResult for a type that matches. #2456")] public async Task BindParameter_NoData_DoesNotGetBound() { // Arrange diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/GenericModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/GenericModelBinderIntegrationTest.cs index 2f757b2cd3..4a32af6ddc 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/GenericModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/GenericModelBinderIntegrationTest.cs @@ -20,7 +20,7 @@ public class GenericModelBinderIntegrationTest // // In this example we choose IFormCollection - because IFormCollection has a dedicated // model binder. - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task GenericModelBinder_BindsCollection_ElementTypeFromGreedyModelBinder_WithPrefix_Success() { // Arrange @@ -50,7 +50,7 @@ public async Task GenericModelBinder_BindsCollection_ElementTypeFromGreedyModelB Assert.Equal(1, model.Count); Assert.NotNull(model[0]); - Assert.Equal(0, modelState.Count); // This fails due to #2446 + Assert.Equal(0, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); } @@ -60,7 +60,7 @@ public async Task GenericModelBinder_BindsCollection_ElementTypeFromGreedyModelB // // In this example we choose IFormCollection - because IFormCollection has a dedicated // model binder. - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task GenericModelBinder_BindsCollection_ElementTypeFromGreedyModelBinder_EmptyPrefix_Success() { // Arrange @@ -89,7 +89,7 @@ public async Task GenericModelBinder_BindsCollection_ElementTypeFromGreedyModelB Assert.Equal(1, model.Count); Assert.NotNull(model[0]); - Assert.Equal(0, modelState.Count); // This fails due to #2446 + Assert.Equal(0, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); } @@ -169,7 +169,7 @@ protected override Task BindModelCoreAsync(ModelBindingConte // This isn't an especially useful scenario - but it exercises what happens when you // try to use a Collection of something that is bound greedily by binding source. - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task GenericModelBinder_BindsCollection_ElementTypeUsesGreedyModelBinder_WithPrefix_Success() { // Arrange @@ -199,14 +199,14 @@ public async Task GenericModelBinder_BindsCollection_ElementTypeUsesGreedyModelB Assert.Equal(1, model.Length); Assert.NotNull(model[0]); - Assert.Equal(0, modelState.Count); // This fails due to #2446 + Assert.Equal(0, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); } // This is part of a random sampling of scenarios where a GenericModelBinder is used // recursively. - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task GenericModelBinder_BindsArrayOfDictionary_WithPrefix_Success() { // Arrange @@ -237,7 +237,7 @@ public async Task GenericModelBinder_BindsArrayOfDictionary_WithPrefix_Success() Assert.Equal("key0", kvp.Key); Assert.Equal(10, kvp.Value); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -252,7 +252,7 @@ public async Task GenericModelBinder_BindsArrayOfDictionary_WithPrefix_Success() // This is part of a random sampling of scenarios where a GenericModelBinder is used // recursively. - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task GenericModelBinder_BindsArrayOfDictionary_EmptyPrefix_Success() { // Arrange @@ -283,7 +283,7 @@ public async Task GenericModelBinder_BindsArrayOfDictionary_EmptyPrefix_Success( Assert.Equal("key0", kvp.Key); Assert.Equal(10, kvp.Value); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -334,7 +334,7 @@ public async Task GenericModelBinder_BindsArrayOfDictionary_NoData() // This is part of a random sampling of scenarios where a GenericModelBinder is used // recursively. - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task GenericModelBinder_BindsCollectionOfKeyValuePair_WithPrefix_Success() { // Arrange @@ -364,7 +364,7 @@ public async Task GenericModelBinder_BindsCollectionOfKeyValuePair_WithPrefix_Su Assert.Equal("key0", kvp.Key); Assert.Equal(10, kvp.Value); - Assert.Equal(2, modelState.Count); // Fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -379,7 +379,7 @@ public async Task GenericModelBinder_BindsCollectionOfKeyValuePair_WithPrefix_Su // This is part of a random sampling of scenarios where a GenericModelBinder is used // recursively. - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task GenericModelBinder_BindsCollectionOfKeyValuePair_EmptyPrefix_Success() { // Arrange @@ -409,7 +409,7 @@ public async Task GenericModelBinder_BindsCollectionOfKeyValuePair_EmptyPrefix_S Assert.Equal("key0", kvp.Key); Assert.Equal(10, kvp.Value); - Assert.Equal(2, modelState.Count); //Fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -460,7 +460,7 @@ public async Task GenericModelBinder_BindsCollectionOfKeyValuePair_NoData() // This is part of a random sampling of scenarios where a GenericModelBinder is used // recursively. - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task GenericModelBinder_BindsDictionaryOfList_WithPrefix_Success() { // Arrange @@ -491,7 +491,7 @@ public async Task GenericModelBinder_BindsDictionaryOfList_WithPrefix_Success() Assert.Equal("key0", kvp.Key); Assert.Equal(new List() { 10, 11 }, kvp.Value); - Assert.Equal(3, modelState.Count); // Fails due to #2446 + Assert.Equal(3, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -510,7 +510,7 @@ public async Task GenericModelBinder_BindsDictionaryOfList_WithPrefix_Success() // This is part of a random sampling of scenarios where a GenericModelBinder is used // recursively. - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task GenericModelBinder_BindsDictionaryOfList_EmptyPrefix_Success() { // Arrange @@ -540,7 +540,7 @@ public async Task GenericModelBinder_BindsDictionaryOfList_EmptyPrefix_Success() Assert.Equal("key0", kvp.Key); Assert.Equal(new List() { 10, 11 }, kvp.Value); - Assert.Equal(3, modelState.Count); // Fails due to #2446 + Assert.Equal(3, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/HeaderModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/HeaderModelBinderIntegrationTest.cs index dc05c801d1..616564892f 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/HeaderModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/HeaderModelBinderIntegrationTest.cs @@ -116,7 +116,7 @@ public async Task BindPropertyFromHeader_WithPrefix_GetsBound() // The scenario is interesting as we to bind the top level model we fallback to empty prefix, // and hence the model state keys have an empty prefix. - [Fact(Skip = "ModelState.Value not set due to #2445. ModelState should not have empty key #2466.")] + [Fact(Skip = "ModelState.Value not set due to #2445.")] public async Task BindPropertyFromHeader_WithData_WithEmptyPrefix_GetsBound() { // Arrange @@ -160,8 +160,8 @@ public async Task BindPropertyFromHeader_WithData_WithEmptyPrefix_GetsBound() Assert.Equal("someValue", modelState[key].Value.AttemptedValue); } - [Theory(Skip = "Extra entries in model state #2446.")] - [InlineData(typeof(string[]), "value1, value2, value3")] + [Theory(Skip = "Greedy Model Binders should add a value in model state #2445.")] + [InlineData(typeof(string[]), "value1, value2, value3")] [InlineData(typeof(string), "value")] public async Task BindParameterFromHeader_WithData_WithPrefix_ModelGetsBound(Type modelType, string value) { diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/KeyValuePairModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/KeyValuePairModelBinderIntegrationTest.cs index 7374e4097d..230a1b34c8 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/KeyValuePairModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/KeyValuePairModelBinderIntegrationTest.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Integration tests targeting the behavior of the KeyValuePairModelBinder with other model binders. public class KeyValuePairModelBinderIntegrationTest { - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task KeyValuePairModelBinder_BindsKeyValuePairOfSimpleType_WithPrefix_Success() { // Arrange @@ -40,7 +40,7 @@ public async Task KeyValuePairModelBinder_BindsKeyValuePairOfSimpleType_WithPref var model = Assert.IsType>(modelBindingResult.Model); Assert.Equal(new KeyValuePair("key0", 10), model); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -53,7 +53,7 @@ public async Task KeyValuePairModelBinder_BindsKeyValuePairOfSimpleType_WithPref Assert.Equal("10", entry.Value.RawValue); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task KeyValuePairModelBinder_BindsKeyValuePairOfSimpleType_WithExplicitPrefix_Success() { // Arrange @@ -85,7 +85,7 @@ public async Task KeyValuePairModelBinder_BindsKeyValuePairOfSimpleType_WithExpl var model = Assert.IsType>(modelBindingResult.Model); Assert.Equal(new KeyValuePair("key0", 10), model); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -98,7 +98,7 @@ public async Task KeyValuePairModelBinder_BindsKeyValuePairOfSimpleType_WithExpl Assert.Equal("10", entry.Value.RawValue); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task KeyValuePairModelBinder_BindsKeyValuePairOfSimpleType_EmptyPrefix_Success() { // Arrange @@ -126,7 +126,7 @@ public async Task KeyValuePairModelBinder_BindsKeyValuePairOfSimpleType_EmptyPre var model = Assert.IsType>(modelBindingResult.Model); Assert.Equal(new KeyValuePair("key0", 10), model); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -176,7 +176,7 @@ private class Person public int Id { get; set; } } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task KeyValuePairModelBinder_BindsKeyValuePairOfComplexType_WithPrefix_Success() { // Arrange @@ -205,7 +205,7 @@ public async Task KeyValuePairModelBinder_BindsKeyValuePairOfComplexType_WithPre Assert.Equal("key0", model.Key); Assert.Equal(10, model.Value.Id); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -215,10 +215,10 @@ public async Task KeyValuePairModelBinder_BindsKeyValuePairOfComplexType_WithPre entry = Assert.Single(modelState, kvp => kvp.Key == "parameter.Value.Id").Value; Assert.Equal("10", entry.Value.AttemptedValue); - Assert.Same(model.Value, entry.Value.RawValue); + Assert.Equal(model.Value.Id.ToString(), entry.Value.RawValue); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task KeyValuePairModelBinder_BindsKeyValuePairOfComplexType_WithExplicitPrefix_Success() { // Arrange @@ -251,7 +251,7 @@ public async Task KeyValuePairModelBinder_BindsKeyValuePairOfComplexType_WithExp Assert.Equal("key0", model.Key); Assert.Equal(10, model.Value.Id); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -264,7 +264,7 @@ public async Task KeyValuePairModelBinder_BindsKeyValuePairOfComplexType_WithExp Assert.Equal("10", entry.Value.RawValue); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task KeyValuePairModelBinder_BindsKeyValuePairOfComplexType_EmptyPrefix_Success() { // Arrange @@ -293,7 +293,7 @@ public async Task KeyValuePairModelBinder_BindsKeyValuePairOfComplexType_EmptyPr Assert.Equal("key0", model.Key); Assert.Equal(10, model.Value.Id); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/MutableObjectModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/MutableObjectModelBinderIntegrationTest.cs index 45d4a03bb8..c8f3d1407d 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/MutableObjectModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/MutableObjectModelBinderIntegrationTest.cs @@ -44,7 +44,7 @@ private class Address1 public string Street { get; set; } } - [Fact(Skip = "Extra entries in model state #2446, ModelState.Value not set due to #2445.")] + [Fact(Skip = "ModelState.Value not set due to #2445.")] public async Task MutableObjectModelBinder_BindsNestedPOCO_WithBodyModelBinder_WithPrefix_Success() { // Arrange @@ -77,7 +77,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithBodyModelBinder_W Assert.NotNull(model.Customer.Address); Assert.Equal(AddressStreetContent, model.Customer.Address.Street); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -91,7 +91,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithBodyModelBinder_W Assert.Same(model.Customer.Address, entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446, ModelState.Value not set due to #2445.")] + [Fact(Skip = "ModelState.Value not set due to #2445.")] public async Task MutableObjectModelBinder_BindsNestedPOCO_WithBodyModelBinder_WithEmptyPrefix_Success() { // Arrange @@ -124,7 +124,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithBodyModelBinder_W Assert.NotNull(model.Customer.Address); Assert.Equal(AddressStreetContent, model.Customer.Address.Street); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -138,7 +138,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithBodyModelBinder_W Assert.Same(model.Customer.Address, entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsNestedPOCO_WithBodyModelBinder_WithPrefix_NoBodyData() { // Arrange @@ -153,6 +153,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithBodyModelBinder_W var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => { request.QueryString = new QueryString("?parameter.Customer.Name=bill"); + request.ContentType = "application/json"; }); var modelState = new ModelStateDictionary(); @@ -169,7 +170,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithBodyModelBinder_W Assert.Equal("bill", model.Customer.Name); Assert.Null(model.Customer.Address); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -180,7 +181,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithBodyModelBinder_W // We don't provide enough data in this test for the 'Person' model to be created. So even though there is // body data in the request, it won't be used. - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsNestedPOCO_WithBodyModelBinder_WithPrefix_PartialData() { // Arrange @@ -211,7 +212,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithBodyModelBinder_W Assert.Null(model.Customer); Assert.Equal(10, model.ProductId); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -222,7 +223,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithBodyModelBinder_W // We don't provide enough data in this test for the 'Person' model to be created. So even though there is // body data in the request, it won't be used. - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsNestedPOCO_WithBodyModelBinder_WithPrefix_NoData() { // Arrange @@ -252,7 +253,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithBodyModelBinder_W var model = Assert.IsType(modelBindingResult.Model); Assert.Null(model.Customer); - Assert.Equal(0, modelState.Count); // This fails due to #2446 + Assert.Equal(0, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); } @@ -272,7 +273,7 @@ private class Person2 public IScopedInstance BindingContext { get; set; } } - [Fact(Skip = "Extra entries in model state #2446, #2646.")] + [Fact(Skip = "FromServices should not have an entry in model state #2464.")] public async Task MutableObjectModelBinder_BindsNestedPOCO_WithServicesModelBinder_WithPrefix_Success() { // Arrange @@ -303,7 +304,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithServicesModelBind Assert.Equal("bill", model.Customer.Name); Assert.NotNull(model.Customer.BindingContext); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -312,7 +313,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithServicesModelBind Assert.Equal("bill", entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446, #2646.")] + [Fact(Skip = "FromServices should not have an entry in model state #2464.")] public async Task MutableObjectModelBinder_BindsNestedPOCO_WithServicesModelBinder_WithEmptyPrefix_Success() { // Arrange @@ -343,7 +344,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithServicesModelBind Assert.Equal("bill", model.Customer.Name); Assert.NotNull(model.Customer.BindingContext); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -354,7 +355,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithServicesModelBind // We don't provide enough data in this test for the 'Person' model to be created. So even though there is // a [FromServices], it won't be used. - [Fact(Skip = "Extra entries in model state #2446, #2646.")] + [Fact(Skip = "FromServices should not have an entry in model state #2464.")] public async Task MutableObjectModelBinder_BindsNestedPOCO_WithServicesModelBinder_WithPrefix_PartialData() { // Arrange @@ -385,7 +386,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithServicesModelBind Assert.Null(model.Customer); Assert.Equal(10, model.ProductId); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -396,7 +397,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithServicesModelBind // We don't provide enough data in this test for the 'Person' model to be created. So even though there is // a [FromServices], it won't be used. - [Fact(Skip = "Extra entries in model state #2446, #2646.")] + [Fact(Skip = "Extra entries in model state #2646.")] public async Task MutableObjectModelBinder_BindsNestedPOCO_WithServicesModelBinder_WithPrefix_NoData() { // Arrange @@ -426,7 +427,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithServicesModelBind var model = Assert.IsType(modelBindingResult.Model); Assert.Null(model.Customer); - Assert.Equal(0, modelState.Count); // This fails due to #2446, #2464 + Assert.Equal(0, modelState.Count); // Fails due to #2464 Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); } @@ -445,7 +446,7 @@ private class Person3 public byte[] Token { get; set; } } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact(Skip = "Greedy model binders should set value. #2445")] public async Task MutableObjectModelBinder_BindsNestedPOCO_WithByteArrayModelBinder_WithPrefix_Success() { // Arrange @@ -477,7 +478,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithByteArrayModelBin Assert.Equal("bill", model.Customer.Name); Assert.Equal(ByteArrayContent, model.Customer.Token); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); // This fails due to #2445 Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -491,7 +492,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithByteArrayModelBin Assert.Equal(ByteArrayEncoded, entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact(Skip = "Greedy model binders should set value. #2445")] public async Task MutableObjectModelBinder_BindsNestedPOCO_WithByteArrayModelBinder_WithEmptyPrefix_Success() { // Arrange @@ -522,7 +523,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithByteArrayModelBin Assert.Equal("bill", model.Customer.Name); Assert.Equal(ByteArrayContent, model.Customer.Token); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -535,7 +536,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithByteArrayModelBin Assert.Equal(ByteArrayEncoded, entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsNestedPOCO_WithByteArrayModelBinder_WithPrefix_NoData() { // Arrange @@ -550,6 +551,10 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithByteArrayModelBin var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => { request.QueryString = new QueryString("?parameter.Customer.Name=bill"); + + // This is set so that the input formatter does not add an error to model state. + // Thus this prevents addition of an extra error unrelated to the test scenario. + request.ContentType = "application/json"; }); var modelState = new ModelStateDictionary(); @@ -566,7 +571,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithByteArrayModelBin Assert.Equal("bill", model.Customer.Name); Assert.Null(model.Customer.Address); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -589,7 +594,7 @@ private class Person4 public IEnumerable Documents { get; set; } } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact(Skip = "Greedy model binders should set value. #2445")] public async Task MutableObjectModelBinder_BindsNestedPOCO_WithFormFileModelBinder_WithPrefix_Success() { // Arrange @@ -621,7 +626,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithFormFileModelBind Assert.Equal("bill", model.Customer.Name); Assert.Single(model.Customer.Documents); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); // This fails due to #2445 Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -634,7 +639,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithFormFileModelBind Assert.Same(model.Customer.Documents, entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact(Skip = "Greedy model binders should set value. #2445")] public async Task MutableObjectModelBinder_BindsNestedPOCO_WithFormFileModelBinder_WithEmptyPrefix_Success() { // Arrange @@ -666,7 +671,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithFormFileModelBind Assert.Equal("bill", model.Customer.Name); Assert.Single(model.Customer.Documents); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -679,7 +684,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithFormFileModelBind Assert.Same(model.Customer.Documents, entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsNestedPOCO_WithFormFileModelBinder_WithPrefix_NoBodyData() { // Arrange @@ -710,9 +715,9 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithFormFileModelBind var model = Assert.IsType(modelBindingResult.Model); Assert.NotNull(model.Customer); Assert.Equal("bill", model.Customer.Name); - Assert.Null(model.Customer.Documents); + Assert.Empty(model.Customer.Documents); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -723,7 +728,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithFormFileModelBind // We don't provide enough data in this test for the 'Person' model to be created. So even though there are // form files in the request, it won't be used. - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsNestedPOCO_WithFormFileModelBinder_WithPrefix_PartialData() { // Arrange @@ -754,7 +759,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithFormFileModelBind Assert.Null(model.Customer); Assert.Equal(10, model.ProductId); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -765,7 +770,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithFormFileModelBind // We don't provide enough data in this test for the 'Person' model to be created. So even though there is // body data in the request, it won't be used. - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsNestedPOCO_WithFormFileModelBinder_WithPrefix_NoData() { // Arrange @@ -795,7 +800,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithFormFileModelBind var model = Assert.IsType(modelBindingResult.Model); Assert.Null(model.Customer); - Assert.Equal(0, modelState.Count); // This fails due to #2446 + Assert.Equal(0, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); } @@ -807,7 +812,7 @@ private class Order5 public int[] ProductIds { get; set; } } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsArrayProperty_WithPrefix_Success() { // Arrange @@ -838,7 +843,7 @@ public async Task MutableObjectModelBinder_BindsArrayProperty_WithPrefix_Success Assert.Equal("bill", model.Name); Assert.Equal(new int[] { 10, 11 }, model.ProductIds); - Assert.Equal(3, modelState.Count); // This fails due to #2446 + Assert.Equal(3, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -855,7 +860,7 @@ public async Task MutableObjectModelBinder_BindsArrayProperty_WithPrefix_Success Assert.Equal("11", entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsArrayProperty_EmptyPrefix_Success() { // Arrange @@ -886,7 +891,7 @@ public async Task MutableObjectModelBinder_BindsArrayProperty_EmptyPrefix_Succes Assert.Equal("bill", model.Name); Assert.Equal(new int[] { 10, 11 }, model.ProductIds); - Assert.Equal(3, modelState.Count); // This fails due to #2446 + Assert.Equal(3, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -903,7 +908,7 @@ public async Task MutableObjectModelBinder_BindsArrayProperty_EmptyPrefix_Succes Assert.Equal("11", entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsArrayProperty_NoCollectionData() { // Arrange @@ -933,7 +938,7 @@ public async Task MutableObjectModelBinder_BindsArrayProperty_NoCollectionData() Assert.Equal("bill", model.Name); Assert.Null(model.ProductIds); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -942,7 +947,7 @@ public async Task MutableObjectModelBinder_BindsArrayProperty_NoCollectionData() Assert.Equal("bill", entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsArrayProperty_NoData() { // Arrange @@ -972,7 +977,7 @@ public async Task MutableObjectModelBinder_BindsArrayProperty_NoData() Assert.Null(model.Name); Assert.Null(model.ProductIds); - Assert.Equal(0, modelState.Count); // This fails due to #2446 + Assert.Equal(0, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); } @@ -984,7 +989,7 @@ private class Order6 public List ProductIds { get; set; } } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsListProperty_WithPrefix_Success() { // Arrange @@ -1015,7 +1020,7 @@ public async Task MutableObjectModelBinder_BindsListProperty_WithPrefix_Success( Assert.Equal("bill", model.Name); Assert.Equal(new List() { 10, 11 }, model.ProductIds); - Assert.Equal(3, modelState.Count); // This fails due to #2446 + Assert.Equal(3, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -1032,7 +1037,7 @@ public async Task MutableObjectModelBinder_BindsListProperty_WithPrefix_Success( Assert.Equal("11", entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsListProperty_EmptyPrefix_Success() { // Arrange @@ -1063,7 +1068,7 @@ public async Task MutableObjectModelBinder_BindsListProperty_EmptyPrefix_Success Assert.Equal("bill", model.Name); Assert.Equal(new List() { 10, 11 }, model.ProductIds); - Assert.Equal(3, modelState.Count); // This fails due to #2446 + Assert.Equal(3, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -1080,7 +1085,7 @@ public async Task MutableObjectModelBinder_BindsListProperty_EmptyPrefix_Success Assert.Equal("11", entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsListProperty_NoCollectionData() { // Arrange @@ -1110,7 +1115,7 @@ public async Task MutableObjectModelBinder_BindsListProperty_NoCollectionData() Assert.Equal("bill", model.Name); Assert.Null(model.ProductIds); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -1119,7 +1124,7 @@ public async Task MutableObjectModelBinder_BindsListProperty_NoCollectionData() Assert.Equal("bill", entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsListProperty_NoData() { // Arrange @@ -1149,7 +1154,7 @@ public async Task MutableObjectModelBinder_BindsListProperty_NoData() Assert.Null(model.Name); Assert.Null(model.ProductIds); - Assert.Equal(0, modelState.Count); // This fails due to #2446 + Assert.Equal(0, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); } @@ -1161,7 +1166,7 @@ private class Order7 public Dictionary ProductIds { get; set; } } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsDictionaryProperty_WithPrefix_Success() { // Arrange @@ -1192,7 +1197,7 @@ public async Task MutableObjectModelBinder_BindsDictionaryProperty_WithPrefix_Su Assert.Equal("bill", model.Name); Assert.Equal(new Dictionary() { { "key0", 10 } }, model.ProductIds); - Assert.Equal(3, modelState.Count); // This fails due to #2446 + Assert.Equal(3, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -1209,7 +1214,7 @@ public async Task MutableObjectModelBinder_BindsDictionaryProperty_WithPrefix_Su Assert.Equal("10", entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsDictionaryProperty_EmptyPrefix_Success() { // Arrange @@ -1240,7 +1245,7 @@ public async Task MutableObjectModelBinder_BindsDictionaryProperty_EmptyPrefix_S Assert.Equal("bill", model.Name); Assert.Equal(new Dictionary() { { "key0", 10 } }, model.ProductIds); - Assert.Equal(3, modelState.Count); // This fails due to #2446 + Assert.Equal(3, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -1257,7 +1262,7 @@ public async Task MutableObjectModelBinder_BindsDictionaryProperty_EmptyPrefix_S Assert.Equal("10", entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsDictionaryProperty_NoCollectionData() { // Arrange @@ -1287,7 +1292,7 @@ public async Task MutableObjectModelBinder_BindsDictionaryProperty_NoCollectionD Assert.Equal("bill", model.Name); Assert.Null(model.ProductIds); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -1296,7 +1301,7 @@ public async Task MutableObjectModelBinder_BindsDictionaryProperty_NoCollectionD Assert.Equal("bill", entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsDictionaryProperty_NoData() { // Arrange @@ -1326,7 +1331,7 @@ public async Task MutableObjectModelBinder_BindsDictionaryProperty_NoData() Assert.Null(model.Name); Assert.Null(model.ProductIds); - Assert.Equal(0, modelState.Count); // This fails due to #2446 + Assert.Equal(0, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); } @@ -1338,7 +1343,7 @@ private class Order8 public KeyValuePair ProductId { get; set; } } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsKeyValuePairProperty_WithPrefix_Success() { // Arrange @@ -1369,7 +1374,7 @@ public async Task MutableObjectModelBinder_BindsKeyValuePairProperty_WithPrefix_ Assert.Equal("bill", model.Name); Assert.Equal(new KeyValuePair("key0", 10), model.ProductId); - Assert.Equal(3, modelState.Count); // This fails due to #2446 + Assert.Equal(3, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -1386,7 +1391,7 @@ public async Task MutableObjectModelBinder_BindsKeyValuePairProperty_WithPrefix_ Assert.Equal("10", entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsKeyValuePairProperty_EmptyPrefix_Success() { // Arrange @@ -1417,7 +1422,7 @@ public async Task MutableObjectModelBinder_BindsKeyValuePairProperty_EmptyPrefix Assert.Equal("bill", model.Name); Assert.Equal(new KeyValuePair("key0", 10), model.ProductId); - Assert.Equal(3, modelState.Count); // This fails due to #2446 + Assert.Equal(3, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -1434,7 +1439,7 @@ public async Task MutableObjectModelBinder_BindsKeyValuePairProperty_EmptyPrefix Assert.Equal("10", entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsKeyValuePairProperty_NoCollectionData() { // Arrange @@ -1464,7 +1469,7 @@ public async Task MutableObjectModelBinder_BindsKeyValuePairProperty_NoCollectio Assert.Equal("bill", model.Name); Assert.Equal(default(KeyValuePair), model.ProductId); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -1473,7 +1478,7 @@ public async Task MutableObjectModelBinder_BindsKeyValuePairProperty_NoCollectio Assert.Equal("bill", entry.Value.RawValue); } - [Fact(Skip = "Extra entries in model state #2446.")] + [Fact] public async Task MutableObjectModelBinder_BindsKeyValuePairProperty_NoData() { // Arrange @@ -1503,7 +1508,7 @@ public async Task MutableObjectModelBinder_BindsKeyValuePairProperty_NoData() Assert.Null(model.Name); Assert.Equal(default(KeyValuePair), model.ProductId); - Assert.Equal(0, modelState.Count); // This fails due to #2446 + Assert.Equal(0, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); } @@ -1524,7 +1529,7 @@ private class Person9 // If a nested POCO object has all properties bound from a greedy source, then it should be populated // if the top-level object is created. - [Fact(Skip = "Extra entries in model state #2446, ModelState.Value not set due to #2445.")] + [Fact(Skip = "ModelState.Value not set due to #2445.")] public async Task MutableObjectModelBinder_BindsNestedPOCO_WithAllGreedyBoundProperties() { // Arrange @@ -1557,7 +1562,7 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithAllGreedyBoundPro Assert.NotNull(model.Customer.Address); Assert.Equal(AddressStreetContent, model.Customer.Address.Street); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -1605,7 +1610,7 @@ public async Task MutableObjectModelBinder_WithRequiredComplexProperty_NoData_Ge var model = Assert.IsType(modelBindingResult.Model); Assert.Null(model.Customer); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(1, modelState.ErrorCount); Assert.False(modelState.IsValid); @@ -1659,7 +1664,7 @@ public async Task MutableObjectModelBinder_WithNestedRequiredProperty_WithPartia Assert.Equal(123, model.Customer.Id); Assert.Null(model.Customer.Name); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(1, modelState.ErrorCount); Assert.False(modelState.IsValid); @@ -1705,7 +1710,7 @@ public async Task MutableObjectModelBinder_WithNestedRequiredProperty_WithData_E Assert.Equal(123, model.Customer.Id); Assert.Null(model.Customer.Name); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(1, modelState.ErrorCount); Assert.False(modelState.IsValid); @@ -1755,7 +1760,7 @@ public async Task MutableObjectModelBinder_WithNestedRequiredProperty_WithData_C Assert.Equal(123, model.Customer.Id); Assert.Null(model.Customer.Name); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(1, modelState.ErrorCount); Assert.False(modelState.IsValid); @@ -1805,7 +1810,7 @@ public async Task MutableObjectModelBinder_WithRequiredProperty_NoData_GetsError var model = Assert.IsType(modelBindingResult.Model); Assert.Null(model.ProductName); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(1, modelState.ErrorCount); Assert.False(modelState.IsValid); @@ -1858,7 +1863,7 @@ public async Task MutableObjectModelBinder_WithRequiredProperty_NoData_CustomPre Assert.Equal("The ProductName field is required.", error.ErrorMessage); } - [Fact(Skip = "Extra model state entry due to #2446")] + [Fact] public async Task MutableObjectModelBinder_WithRequiredProperty_WithData_EmptyPrefix_GetsBound() { // Arrange @@ -1887,7 +1892,7 @@ public async Task MutableObjectModelBinder_WithRequiredProperty_WithData_EmptyPr var model = Assert.IsType(modelBindingResult.Model); Assert.Equal("abc", model.ProductName); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -1985,7 +1990,7 @@ public async Task MutableObjectModelBinder_WithRequiredCollectionProperty_NoData Assert.Equal("The OrderIds field is required.", error.ErrorMessage); } - [Fact(Skip = "Extra model state entry due to #2446")] + [Fact] public async Task MutableObjectModelBinder_WithRequiredCollectionProperty_WithData_EmptyPrefix_GetsBound() { // Arrange @@ -2014,7 +2019,7 @@ public async Task MutableObjectModelBinder_WithRequiredCollectionProperty_WithDa var model = Assert.IsType(modelBindingResult.Model); Assert.Equal(new[] { 123 }, model.OrderIds.ToArray()); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/ServicesModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/ServicesModelBinderIntegrationTest.cs index 49bff59748..e37516da6b 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/ServicesModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/ServicesModelBinderIntegrationTest.cs @@ -61,17 +61,14 @@ public async Task BindPropertyFromService_WithData_WithPrefix_GetsBound() // ModelState Assert.True(modelState.IsValid); - Assert.Equal(3, modelState.Keys.Count); - Assert.Single(modelState.Keys, k => k == "CustomParameter"); - Assert.Single(modelState.Keys, k => k == "CustomParameter.Address"); - + Assert.Equal(1, modelState.Keys.Count); var key = Assert.Single(modelState.Keys, k => k == "CustomParameter.Address.OutputFormatter"); Assert.Equal(ModelValidationState.Skipped, modelState[key].ValidationState); Assert.Null(modelState[key].Value); Assert.Empty(modelState[key].Errors); } - [Fact(Skip = "ModelState should not have empty key #2466.")] + [Fact(Skip = "Should be no entry for model bound using services. #2464")] public async Task BindPropertyFromService_WithData_WithEmptyPrefix_GetsBound() { // Arrange @@ -102,10 +99,8 @@ public async Task BindPropertyFromService_WithData_WithEmptyPrefix_GetsBound() // ModelState Assert.True(modelState.IsValid); - Assert.Equal(2, modelState.Keys.Count); - Assert.Single(modelState.Keys, k => k == "Address"); - var key = Assert.Single(modelState.Keys, k => k == "Address.OutputFormatter"); - Assert.Equal(ModelValidationState.Skipped, modelState[key].ValidationState); + Assert.Equal(1, modelState.Keys.Count); + var key = Assert.Single(modelState.Keys, k => k == "Address"); Assert.Null(modelState[key].Value); // For non user bound models there should be no value. Assert.Empty(modelState[key].Errors); } diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/TryUpdateModelIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/TryUpdateModelIntegrationTest.cs index cc67c50c8d..fba32dfbed 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/TryUpdateModelIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/TryUpdateModelIntegrationTest.cs @@ -18,7 +18,7 @@ private class Address public string Street { get; set; } } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task TryUpdateModel_ExistingModel_EmptyPrefix_GetsOverWritten() { // Arrange @@ -53,7 +53,7 @@ public async Task TryUpdateModel_ExistingModel_EmptyPrefix_GetsOverWritten() Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState); } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task TryUpdateModel_ExistingModel_EmptyPrefix_GetsBound() { // Arrange @@ -90,7 +90,7 @@ private class Person2 public List
Address { get; set; } } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task TryUpdateModel_SettableCollectionModel_EmptyPrefix_GetsBound() { // Arrange @@ -134,7 +134,7 @@ public Person3() public List
Address { get; } } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task TryUpdateModel_NonSettableCollectionModel_EmptyPrefix_GetsBound() { // Arrange @@ -173,7 +173,7 @@ private class Person6 public CustomReadOnlyCollection
Address { get; set; } } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task TryUpdateModel_ReadOnlyCollectionModel_EmptyPrefix_DoesNotGetBound() { // Arrange @@ -206,7 +206,7 @@ private class Person4 public Address[] Address { get; set; } } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task TryUpdateModel_SettableArrayModel_EmptyPrefix_GetsBound() { // Arrange @@ -245,7 +245,7 @@ private class Person5 public Address[] Address { get; } = new Address[] { }; } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task TryUpdateModel_NonSettableArrayModel_EmptyPrefix_GetsBound() { // Arrange @@ -274,7 +274,7 @@ public async Task TryUpdateModel_NonSettableArrayModel_EmptyPrefix_GetsBound() } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task TryUpdateModel_ExistingModel_WithPrefix_GetsOverWritten() { // Arrange @@ -309,7 +309,7 @@ public async Task TryUpdateModel_ExistingModel_WithPrefix_GetsOverWritten() Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState); } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task TryUpdateModel_ExistingModel_WithPrefix_GetsBound() { // Arrange @@ -341,7 +341,7 @@ public async Task TryUpdateModel_ExistingModel_WithPrefix_GetsBound() Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState); } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task TryUpdateModel_SettableCollectionModel_WithPrefix_GetsBound() { // Arrange @@ -353,7 +353,7 @@ public async Task TryUpdateModel_SettableCollectionModel_WithPrefix_GetsBound() var modelState = new ModelStateDictionary(); var model = new Person2(); // Act - var result = await TryUpdateModel(model, string.Empty, operationContext, modelState); + var result = await TryUpdateModel(model, "prefix", operationContext, modelState); // Assert Assert.True(result); @@ -375,7 +375,7 @@ public async Task TryUpdateModel_SettableCollectionModel_WithPrefix_GetsBound() Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState); } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task TryUpdateModel_NonSettableCollectionModel_WithPrefix_GetsBound() { // Arrange @@ -409,7 +409,7 @@ public async Task TryUpdateModel_NonSettableCollectionModel_WithPrefix_GetsBound Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState); } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task TryUpdateModel_ReadOnlyCollectionModel_WithPrefix_DoesNotGetBound() { // Arrange @@ -437,7 +437,7 @@ public async Task TryUpdateModel_ReadOnlyCollectionModel_WithPrefix_DoesNotGetBo Assert.Empty(modelState.Keys); } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task TryUpdateModel_SettableArrayModel_WithPrefix_GetsBound() { // Arrange @@ -463,7 +463,7 @@ public async Task TryUpdateModel_SettableArrayModel_WithPrefix_GetsBound() Assert.True(modelState.IsValid); Assert.Equal(1, modelState.Keys.Count); - var key = Assert.Single(modelState.Keys, k => k == "Address[0].Street"); + var key = Assert.Single(modelState.Keys, k => k == "prefix.Address[0].Street"); Assert.NotNull(modelState[key].Value); Assert.Equal("SomeStreet", modelState[key].Value.AttemptedValue); Assert.Equal("SomeStreet", modelState[key].Value.RawValue); @@ -471,7 +471,7 @@ public async Task TryUpdateModel_SettableArrayModel_WithPrefix_GetsBound() Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState); } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task TryUpdateModel_NonSettableArrayModel_WithPrefix_DoesNotGetBound() { // Arrange diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/TypeConverterModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/TypeConverterModelBinderIntegrationTest.cs index 8ba18736c7..74ef9990c3 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/TypeConverterModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/TypeConverterModelBinderIntegrationTest.cs @@ -20,7 +20,7 @@ private class Address public int Zip { get; set; } } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task BindProperty_WithData_WithPrefix_GetsBound() { // Arrange @@ -62,16 +62,16 @@ public async Task BindProperty_WithData_WithPrefix_GetsBound() Assert.True(modelState.IsValid); Assert.Equal(1, modelState.Keys.Count); - var key = Assert.Single(modelState.Keys, k => k == "CustomParameter.Address.Street"); + var key = Assert.Single(modelState.Keys, k => k == "CustomParameter.Address.Zip"); Assert.NotNull(modelState[key].Value); Assert.Equal("1", modelState[key].Value.AttemptedValue); - Assert.Equal(1, modelState[key].Value.RawValue); + Assert.Equal("1", modelState[key].Value.RawValue); Assert.NotNull(modelState[key].Value); Assert.Empty(modelState[key].Errors); Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState); } - [Fact(Skip = "Extra entries in model state dictionary. #2466")] + [Fact] public async Task BindProperty_WithData_WithEmptyPrefix_GetsBound() { // Arrange @@ -112,7 +112,7 @@ public async Task BindProperty_WithData_WithEmptyPrefix_GetsBound() var key = Assert.Single(modelState.Keys, k => k == "Address.Zip"); Assert.NotNull(modelState[key].Value); Assert.Equal("1", modelState[key].Value.AttemptedValue); - Assert.Equal(1, modelState[key].Value.RawValue); + Assert.Equal("1", modelState[key].Value.RawValue); Assert.NotNull(modelState[key].Value); Assert.Empty(modelState[key].Errors); Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState); diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/ValidationIntegrationTests.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/ValidationIntegrationTests.cs index 5dd3337483..b84112dcef 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/ValidationIntegrationTests.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/ValidationIntegrationTests.cs @@ -19,7 +19,7 @@ private class Order1 public string CustomerName { get; set; } } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task Validation_RequiredAttribute_OnSimpleTypeProperty_WithData() { // Arrange @@ -47,7 +47,7 @@ public async Task Validation_RequiredAttribute_OnSimpleTypeProperty_WithData() var model = Assert.IsType(modelBindingResult.Model); Assert.Equal("bill", model.CustomerName); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -57,7 +57,7 @@ public async Task Validation_RequiredAttribute_OnSimpleTypeProperty_WithData() Assert.Empty(entry.Errors); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task Validation_RequiredAttribute_OnSimpleTypeProperty_NoData() { // Arrange @@ -85,7 +85,7 @@ public async Task Validation_RequiredAttribute_OnSimpleTypeProperty_NoData() var model = Assert.IsType(modelBindingResult.Model); Assert.Null(model.CustomerName); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(1, modelState.ErrorCount); Assert.False(modelState.IsValid); @@ -108,7 +108,7 @@ private class Person2 public string Name { get; set; } } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task Validation_RequiredAttribute_OnPOCOProperty_WithData() { // Arrange @@ -137,7 +137,7 @@ public async Task Validation_RequiredAttribute_OnPOCOProperty_WithData() Assert.NotNull(model.Customer); Assert.Equal("bill", model.Customer.Name); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -200,7 +200,7 @@ private class Person3 public string Name { get; set; } } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task Validation_RequiredAttribute_OnNestedSimpleTypeProperty_WithData() { // Arrange @@ -229,7 +229,7 @@ public async Task Validation_RequiredAttribute_OnNestedSimpleTypeProperty_WithDa Assert.NotNull(model.Customer); Assert.Equal("bill", model.Customer.Name); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -239,7 +239,7 @@ public async Task Validation_RequiredAttribute_OnNestedSimpleTypeProperty_WithDa Assert.Empty(entry.Errors); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task Validation_RequiredAttribute_OnNestedSimpleTypeProperty_NoDataForRequiredProperty() { // Arrange @@ -270,7 +270,7 @@ public async Task Validation_RequiredAttribute_OnNestedSimpleTypeProperty_NoData Assert.Equal(17, model.Customer.Age); Assert.Null(model.Customer.Name); - Assert.Equal(2, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(1, modelState.ErrorCount); Assert.False(modelState.IsValid); @@ -293,7 +293,7 @@ private class Item4 public int ItemId { get; set; } } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task Validation_RequiredAttribute_OnCollectionProperty_WithData() { // Arrange @@ -322,7 +322,7 @@ public async Task Validation_RequiredAttribute_OnCollectionProperty_WithData() Assert.NotNull(model.Items); Assert.Equal(17, Assert.Single(model.Items).ItemId); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -381,7 +381,7 @@ private class Order5 public string Name { get; set; } } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task Validation_RequiredAttribute_OnPOCOPropertyOfBoundElement_WithData() { // Arrange @@ -409,7 +409,7 @@ public async Task Validation_RequiredAttribute_OnPOCOPropertyOfBoundElement_With var model = Assert.IsType>(modelBindingResult.Model); Assert.Equal(17, Assert.Single(model).ProductId); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -468,7 +468,7 @@ private class Order6 public string Name { get; set; } } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task Validation_StringLengthAttribute_OnPropertyOfPOCO_Valid() { // Arrange @@ -496,7 +496,7 @@ public async Task Validation_StringLengthAttribute_OnPropertyOfPOCO_Valid() var model = Assert.IsType(modelBindingResult.Model); Assert.Equal("bill", model.Name); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -506,7 +506,7 @@ public async Task Validation_StringLengthAttribute_OnPropertyOfPOCO_Valid() Assert.Empty(entry.Errors); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task Validation_StringLengthAttribute_OnPropertyOfPOCO_Invalid() { // Arrange @@ -534,7 +534,7 @@ public async Task Validation_StringLengthAttribute_OnPropertyOfPOCO_Invalid() var model = Assert.IsType(modelBindingResult.Model); Assert.Equal("billybob", model.Name); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(1, modelState.ErrorCount); Assert.False(modelState.IsValid); @@ -558,7 +558,7 @@ private class Person7 public string Name { get; set; } } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task Validation_StringLengthAttribute_OnPropertyOfNestedPOCO_Valid() { // Arrange @@ -586,7 +586,7 @@ public async Task Validation_StringLengthAttribute_OnPropertyOfNestedPOCO_Valid( var model = Assert.IsType(modelBindingResult.Model); Assert.Equal("bill", model.Customer.Name); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -596,7 +596,7 @@ public async Task Validation_StringLengthAttribute_OnPropertyOfNestedPOCO_Valid( Assert.Empty(entry.Errors); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task Validation_StringLengthAttribute_OnPropertyOfNestedPOCO_Invalid() { // Arrange @@ -624,7 +624,7 @@ public async Task Validation_StringLengthAttribute_OnPropertyOfNestedPOCO_Invali var model = Assert.IsType(modelBindingResult.Model); Assert.Equal("billybob", model.Customer.Name); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(1, modelState.ErrorCount); Assert.False(modelState.IsValid); @@ -637,7 +637,7 @@ public async Task Validation_StringLengthAttribute_OnPropertyOfNestedPOCO_Invali Assert.Null(error.Exception); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task Validation_StringLengthAttribute_OnPropertyOfNestedPOCO_NoData() { // Arrange @@ -665,7 +665,7 @@ public async Task Validation_StringLengthAttribute_OnPropertyOfNestedPOCO_NoData var model = Assert.IsType(modelBindingResult.Model); Assert.Null(model.Customer); - Assert.Equal(0, modelState.Count); // This fails due to #2446 + Assert.Equal(0, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); } @@ -696,7 +696,7 @@ protected override ValidationResult IsValid(object value, ValidationContext vali } } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task Validation_CustomAttribute_OnPOCOProperty_Valid() { // Arrange @@ -724,7 +724,7 @@ public async Task Validation_CustomAttribute_OnPOCOProperty_Valid() var model = Assert.IsType(modelBindingResult.Model); Assert.Equal("bill", model.Customer.Name); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -734,7 +734,7 @@ public async Task Validation_CustomAttribute_OnPOCOProperty_Valid() Assert.Empty(entry.Errors); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task Validation_CustomAttribute_OnPOCOProperty_Invalid() { // Arrange @@ -762,7 +762,7 @@ public async Task Validation_CustomAttribute_OnPOCOProperty_Invalid() var model = Assert.IsType(modelBindingResult.Model); Assert.Equal("billybob", model.Customer.Name); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(1, modelState.ErrorCount); Assert.False(modelState.IsValid); @@ -804,7 +804,7 @@ protected override ValidationResult IsValid(object value, ValidationContext vali } } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task Validation_CustomAttribute_OnCollectionElement_Valid() { // Arrange @@ -832,7 +832,7 @@ public async Task Validation_CustomAttribute_OnCollectionElement_Valid() var model = Assert.IsType(modelBindingResult.Model); Assert.Equal("bill", Assert.Single(model.Products).Name); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -842,7 +842,7 @@ public async Task Validation_CustomAttribute_OnCollectionElement_Valid() Assert.Empty(entry.Errors); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task Validation_CustomAttribute_OnCollectionElement_Invalid() { // Arrange @@ -870,7 +870,7 @@ public async Task Validation_CustomAttribute_OnCollectionElement_Invalid() var model = Assert.IsType(modelBindingResult.Model); Assert.Equal("billybob", Assert.Single(model.Products).Name); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(2, modelState.Count); Assert.Equal(1, modelState.ErrorCount); Assert.False(modelState.IsValid); @@ -893,7 +893,7 @@ private class Order10 public string Name { get; set; } } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task Validation_StringLengthAttribute_OnProperyOfCollectionElement_Valid() { // Arrange @@ -921,7 +921,7 @@ public async Task Validation_StringLengthAttribute_OnProperyOfCollectionElement_ var model = Assert.IsType>(modelBindingResult.Model); Assert.Equal("bill", Assert.Single(model).Name); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.True(modelState.IsValid); @@ -931,7 +931,7 @@ public async Task Validation_StringLengthAttribute_OnProperyOfCollectionElement_ Assert.Empty(entry.Errors); } - [Fact(Skip = "Extra ModelState key because of #2446")] + [Fact] public async Task Validation_StringLengthAttribute_OnProperyOfCollectionElement_Invalid() { // Arrange @@ -959,7 +959,7 @@ public async Task Validation_StringLengthAttribute_OnProperyOfCollectionElement_ var model = Assert.IsType>(modelBindingResult.Model); Assert.Equal("billybob", Assert.Single(model).Name); - Assert.Equal(1, modelState.Count); // This fails due to #2446 + Assert.Equal(1, modelState.Count); Assert.Equal(1, modelState.ErrorCount); Assert.False(modelState.IsValid); @@ -972,7 +972,7 @@ public async Task Validation_StringLengthAttribute_OnProperyOfCollectionElement_ Assert.Null(error.Exception); } - [Fact(Skip = "Extra ModelState key because of #2446, Empty collection should be created by the collection model binder #1579")] + [Fact(Skip = "Empty collection should be created by the collection model binder #1579")] public async Task Validation_StringLengthAttribute_OnProperyOfCollectionElement_NoData() { // Arrange @@ -1000,7 +1000,7 @@ public async Task Validation_StringLengthAttribute_OnProperyOfCollectionElement_ var model = Assert.IsType>(modelBindingResult.Model); Assert.Empty(model); - //Assert.Equal(0, modelState.Count); // This fails due to #2446 + Assert.Equal(0, modelState.Count); Assert.Equal(0, modelState.ErrorCount); Assert.False(modelState.IsValid); }