public void NestedChildFieldMissingRequiredValue() { BodyWithNestedRequiredUrlField body = new BodyWithNestedRequiredUrlField() { UrlParam = new BodyWithUrlField() { Param1 = null } }; List <ValidationResult> validationResults = new List <ValidationResult>(); var result = RecursiveValidator.TryValidateObject(body, validationResults, true); result.ShouldBeFalse(); validationResults.ShouldContain(x => x.MemberNames.Contains("UrlParam.Param1") && x.ErrorMessage.Contains("Param1 is required")); }
public void NestedCollectionFieldMissingRequiredValue() { BodyWithNestedRequiredUrlField body = new BodyWithNestedRequiredUrlField() { UrlParam = new BodyWithUrlField() { Param1 = "https://google.com" }, Items = new BodyWithRequiredFields[] { new BodyWithRequiredFields() { Param1 = null, Param2 = "blah" } } }; List <ValidationResult> validationResults = new List <ValidationResult>(); var result = RecursiveValidator.TryValidateObject(body, validationResults, true); result.ShouldBeFalse(); validationResults.ShouldContain(x => x.MemberNames.Contains("Items[0].Param1") && x.ErrorMessage.Contains("Param1 is required")); }