public static ValidationResult PerformCustomValidation(CustomValidationTestObject obj, ValidationContext context)
 {
     if (obj.Id == 0)
         return new ValidationResult("Id cannot be 0");
     else
         return ValidationResult.Success;
 }
Exemple #2
0
        public void Object_fails_custom_validation()
        {
            IValidationRunner runner = new DataAnnotationsValidationRunner();

            CustomValidationTestObject obj = new CustomValidationTestObject();

            IEnumerable<RuleViolation> errors = runner.Validate(obj);

            Assert.IsNotNull(errors);
            Assert.AreEqual(1, errors.Count());
        }