integration testing api having fluent validation

Viewed 527

I have API which uses FluentValidations.

I am writing integration test and wanted to assert that bad request response contains error field name and messages. I want to check for fieldname, and message and ensure they are same as returned from fluentvalidations. Am getting a json response filled with validation errors but not sure into which object should i deserialize into.

response.StatusCode.Should().Be(HttpStatusCode.BadRequest);

var result = JsonConvert.DeserializeObject<?>(await response.Content.ReadAsStringAsync());
result.Should().BeOfType<?>();
result.Should().NotBeNull();
result.Should().HaveCount(something);

sample response is fluentvalidation response

{
  "Name": [
    "Name is required.",
    "Name length cannot be more that 255 chars"
  ],
  "ListTypeId": [
    "Invalid listtypeid"
  ],
  "PartyRoleId": [
    "Invalid partyroleid"
  ]
}
1 Answers
Related