From 27565c4e8dec93d7326b25462d08d127c4a31167 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Tue, 24 May 2016 10:17:30 -0700 Subject: [PATCH] Fix broken query string binding test This test was relying on the parsing behavior of QueryString, that it would omit the key and value when the value is empty. The expectations weren't consistent with other tests for 'empty' values. --- ...MutableObjectModelBinderIntegrationTest.cs | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/MutableObjectModelBinderIntegrationTest.cs b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/MutableObjectModelBinderIntegrationTest.cs index 68a6809ac1..32099b28c4 100644 --- a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/MutableObjectModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/MutableObjectModelBinderIntegrationTest.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.ModelBinding; +using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Primitives; using Xunit; @@ -1887,10 +1888,11 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests Assert.Null(error.Exception); } - // This covers the case where a key is present, but has no value. The type converter - // will report an error. + // This covers the case where a key is present, but has no value. The model binder will + // report and error because it's a value type (non-nullable). [Fact] - public async Task MutableObjectModelBinder_BindsPOCO_TypeConvertedPropertyWithNoValue_NoError() + [ReplaceCulture] + public async Task MutableObjectModelBinder_BindsPOCO_TypeConvertedPropertyWithEmptyValue_Error() { // Arrange var argumentBinder = ModelBindingTestHelper.GetArgumentBinder(); @@ -1918,9 +1920,16 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests Assert.NotNull(model); Assert.Equal(0, model.ProductId); - Assert.Equal(0, modelState.Count); - Assert.Equal(0, modelState.ErrorCount); - Assert.True(modelState.IsValid); + var entry = Assert.Single(modelState); + Assert.Equal("parameter.ProductId", entry.Key); + Assert.Equal(string.Empty, entry.Value.AttemptedValue); + + var error = Assert.Single(entry.Value.Errors); + Assert.Equal("The value '' is invalid.", error.ErrorMessage, StringComparer.Ordinal); + Assert.Null(error.Exception); + + Assert.Equal(1, modelState.ErrorCount); + Assert.False(modelState.IsValid); } private static void SetJsonBodyContent(HttpRequest request, string content)