【发布时间】:2017-05-12 17:11:27
【问题描述】:
我有使用 FluentValidations 的 API。
我正在编写集成测试并想断言错误的请求响应包含错误字段名称和消息。我想检查字段名和消息,并确保它们与从 fluentvalidations 返回的相同。我收到一个充满验证错误的 json 响应,但不确定我应该反序列化到哪个对象。
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
var result = JsonConvert.DeserializeObject<?>(await response.Content.ReadAsStringAsync());
result.Should().BeOfType<?>();
result.Should().NotBeNull();
result.Should().HaveCount(something);
示例响应是 fluentvalidation 响应
{
"Name": [
"Name is required.",
"Name length cannot be more that 255 chars"
],
"ListTypeId": [
"Invalid listtypeid"
],
"PartyRoleId": [
"Invalid partyroleid"
]
}
【问题讨论】:
-
举个例子说明json响应内容是什么样子的
-
已更新。它来自 fluentvalidation 的基本原始响应
标签: c# asp.net-web-api2 fluentvalidation