Adding some deserialization to a test for SerializableError

This commit is contained in:
Ryan Nowak 2015-05-14 15:08:03 -07:00
parent cc4ee1068d
commit 7767251dad
1 changed files with 16 additions and 1 deletions

View File

@ -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<Dictionary<string, string[]>>(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);
}
}
}