ObjectValidation problem

Jun 5, 2014 at 3:18 AM
Edited Jun 5, 2014 at 3:19 AM
Found a problem on Data validation, Not sure is it my code problem?
the result is Suppose to be false, but it is true here.
Seems [Required] works, but [Range] not working.
    public class ValidationTest {
        class Dog{
            public string Name { get; set; }
            public int Age { get; set; }
        public void ObjectValidationTest(){
            var dog = new Dog(){Age = -1,Name = "Jim"};
            ICollection<ValidationResult> validationResults = new List<ValidationResult>();
            var result = dog.TryValidate(validationResults);
Jun 5, 2014 at 1:54 PM
There is indeed a bug. Apparently the default behavior for Validator.TryValidate (which is what the extension method wraps) is to only validate Required properties... Why the hell you would make that the default, I don't know. Anyway, I'm pushing up a fix now and adding your above code to the unit tests (along with a couple other checks).
Jun 12, 2014 at 6:25 PM
My code has issues, it is better to put Required with other Range.