Skip to content

Commit fcf7b15

Browse files
committed
Remove FromBodyOnProperty_RequiredOnValueTypeSubProperty_AddsModelStateError
- this integration test depends on the old `[Required]` special case - aspnet#2388 explicitly removes that bahaviour so the test goes with it
1 parent de63075 commit fcf7b15

File tree

1 file changed

+0
-62
lines changed

1 file changed

+0
-62
lines changed

test/Microsoft.AspNet.Mvc.IntegrationTests/BodyValidationIntegrationTests.cs

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -220,67 +220,5 @@ public async Task FromBodyOnTopLevelProperty_RequiredOnSubProperty_AddsModelStat
220220
var error = Assert.Single(modelState[street].Errors);
221221
Assert.Equal("The Street field is required.", error.ErrorMessage);
222222
}
223-
224-
private class Person3
225-
{
226-
[FromBody]
227-
public Address3 Address { get; set; }
228-
}
229-
230-
private class Address3
231-
{
232-
public string Street { get; set; }
233-
234-
[Required]
235-
public int Zip { get; set; }
236-
}
237-
238-
[Theory]
239-
[InlineData("{ \"Street\" : \"someStreet\" }")]
240-
[InlineData("{}")]
241-
public async Task FromBodyOnProperty_RequiredOnValueTypeSubProperty_AddsModelStateError(string inputText)
242-
{
243-
// Arrange
244-
var argumentBinder = ModelBindingTestHelper.GetArgumentBinder();
245-
var parameter = new ParameterDescriptor()
246-
{
247-
BindingInfo = new BindingInfo()
248-
{
249-
BinderModelName = "CustomParameter",
250-
},
251-
ParameterType = typeof(Person3)
252-
};
253-
254-
var operationContext = ModelBindingTestHelper.GetOperationBindingContext(
255-
request =>
256-
{
257-
request.Body = new MemoryStream(Encoding.UTF8.GetBytes(inputText));
258-
request.ContentType = "application/json";
259-
});
260-
var httpContext = operationContext.HttpContext;
261-
var actionContext = httpContext.RequestServices.GetRequiredService<IScopedInstance<ActionContext>>().Value;
262-
var modelState = actionContext.ModelState;
263-
264-
// Act
265-
var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext);
266-
267-
// Assert
268-
Assert.NotNull(modelBindingResult);
269-
Assert.True(modelBindingResult.IsModelSet);
270-
var boundPerson = Assert.IsType<Person3>(modelBindingResult.Model);
271-
Assert.NotNull(boundPerson);
272-
Assert.False(modelState.IsValid);
273-
var street = Assert.Single(modelState.Keys, k => k == "CustomParameter.Address.Street");
274-
Assert.Equal(ModelValidationState.Valid, modelState[street].ValidationState);
275-
276-
// The error with an empty key is a bug(#2416) in our implementation which does not append the prefix and
277-
// use that along with the path. The expected key here would be Address.
278-
var zip = Assert.Single(modelState.Keys, k => k == "CustomParameter.Address.Zip");
279-
Assert.Equal(ModelValidationState.Valid, modelState[zip].ValidationState);
280-
var error = Assert.Single(modelState[""].Errors);
281-
Assert.StartsWith(
282-
"Required property 'Zip' not found in JSON. Path ''",
283-
error.Exception.Message);
284-
}
285223
}
286224
}

0 commit comments

Comments
 (0)