From fcf7b15c645cd58ecce2590b6ba57fcb39908dce Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Mon, 11 May 2015 17:18:52 -0700 Subject: [PATCH] Remove `FromBodyOnProperty_RequiredOnValueTypeSubProperty_AddsModelStateError` - this integration test depends on the old `[Required]` special case - #2388 explicitly removes that bahaviour so the test goes with it --- .../BodyValidationIntegrationTests.cs | 62 ------------------- 1 file changed, 62 deletions(-) diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/BodyValidationIntegrationTests.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/BodyValidationIntegrationTests.cs index 80ada3948f..532c85da01 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/BodyValidationIntegrationTests.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/BodyValidationIntegrationTests.cs @@ -220,67 +220,5 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests 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] - [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 httpContext = operationContext.HttpContext; - var actionContext = httpContext.RequestServices.GetRequiredService>().Value; - var modelState = actionContext.ModelState; - - // 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