Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: Validator extension "ShouldHaveValidationErrorFor" and checking whole accessor path.

$
0
0
Hi,

We have tree class structure, and some properties from leafs are validated only when property from root are checked. Cause it's hard to make conditional validator for whole class, we decided to write validations rules from root. Then i wanted to test, but such code is not working:
         _validator.ShouldHaveValidationErrorFor(el => el.Child.Child.Property, model);
,cause in ValidatorTester it checks only this.accessor.Member.Name. Shouldn't it get path like that: http://stackoverflow.com/a/3049904/1202306 ?

Now we have to write tests like that:
            var result = _validator.Validate(dto);
            var error = result.Errors.FirstOrDefault(el => el.PropertyName == "Child.Child.Property");
            Assert.IsNotNull(error);

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>