コード例 #1
0
        public void Executes_custom_rule_when_condition_true()
        {
            var validator = new TestValidator();

            validator.When(x => true, () => { validator.Custom(x => new ValidationFailure("foo", "bar")); });

            var result = validator.Validate(new Person());

            result.IsValid.ShouldBeFalse();
        }
コード例 #2
0
        public void Does_not_execute_custom_Rule_when_condition_false()
        {
            var validator = new TestValidator();

            validator.When(x => false, () => { validator.Custom(x => new ValidationFailure("foo", "bar")); });

            var result = validator.Validate(new Person());

            result.IsValid.ShouldBeTrue();
        }
コード例 #3
0
        public void Executes_custom_rule_when_async_condition_true()
        {
            var validator = new TestValidator();

            validator.WhenAsync(x => TaskHelpers.FromResult(true), () => { validator.Custom(x => new ValidationFailure("foo", "bar")); });

            var result = validator.Validate(new Person());

            result.IsValid.ShouldBeFalse();
        }
コード例 #4
0
        public void Does_not_execute_custom_Rule_when_async_condition_false()
        {
            var validator = new TestValidator();

            validator.WhenAsync(x => TaskHelpers.FromResult(false), () => { validator.Custom(x => new ValidationFailure("foo", "bar")); });

            var result = validator.ValidateAsync(new Person()).Result;

            result.IsValid.ShouldBeTrue();
        }
コード例 #5
0
        public void Nested_conditions_with_Custom_rule()
        {
            var validator = new TestValidator();

            validator.When(x => true, () => {
                validator.When(x => false, () => {
                    validator.Custom(x => new ValidationFailure("Custom", "The validation failed"));
                });
            });
            var result = validator.Validate(new Person());

            result.IsValid.ShouldBeTrue();
        }
コード例 #6
0
 public void Should_throw_when_custom_rule_is_null()
 {
     typeof(ArgumentNullException).ShouldBeThrownBy(() => validator.Custom((Func <Person, ValidationFailure>)null));
 }