コード例 #1
0
        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"));
        }
コード例 #2
0
        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"));
        }