From 7767251dad61beba3e9d789e3cbffc1bd3357c35 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Thu, 14 May 2015 15:08:03 -0700 Subject: [PATCH] Adding some deserialization to a test for SerializableError --- .../JsonOutputFormatterTests.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonOutputFormatterTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonOutputFormatterTests.cs index 55f8c7b7aa..2af52a2c22 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonOutputFormatterTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/JsonOutputFormatterTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Net.Http.Headers; @@ -72,7 +73,21 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Assert Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); - Assert.Equal(expectedOutput, await response.Content.ReadAsStringAsync()); + + var actualContent = await response.Content.ReadAsStringAsync(); + Assert.Equal(expectedOutput, actualContent); + + var modelStateErrors = JsonConvert.DeserializeObject>(actualContent); + Assert.Equal(2, modelStateErrors.Count); + + var errors = Assert.Single(modelStateErrors, kvp => kvp.Key == "Id").Value; + + var error = Assert.Single(errors); + Assert.Equal("The field Id must be between 10 and 100.", error); + + errors = Assert.Single(modelStateErrors, kvp => kvp.Key == "Name").Value; + error = Assert.Single(errors); + Assert.Equal("The field Name must be a string or array type with a minimum length of '15'.", error); } } } \ No newline at end of file