示例#1
0
        public void WhenAllValuesSet_ValidationPasses()
        {
            var validator = new AtLeastOneNonNullPropertyValidationAttribute("FirstValue", "SecondValue");
            var instance  = new ForValidation
            {
                FirstValue  = 1,
                SecondValue = 2
            };
            var context             = new ValidationContext(instance, null, null);
            ValidationResult result = validator.GetValidationResult(instance, context);

            Assert.Same(ValidationResult.Success, result);
        }
示例#2
0
        public void WhenAllValuesNull_ValidationFails()
        {
            var validator = new AtLeastOneNonNullPropertyValidationAttribute("FirstValue", "SecondValue");
            var instance  = new ForValidation
            {
                FirstValue  = null,
                SecondValue = null
            };
            var context             = new ValidationContext(instance, null, null);
            ValidationResult result = validator.GetValidationResult(instance, context);

            Assert.NotSame(ValidationResult.Success, result);
            Assert.NotNull(result.ErrorMessage);
            Assert.False(result.MemberNames.Except(new[] { "FirstValue", "SecondValue" }).Any());
        }