Beispiel #1
0
        public void Executes_customasync_rule_when_condition_true()
        {
            var validator = new TestValidator();

            validator.When(x => true, () => validator.CustomAsync(x => TaskHelpers.FromResult(new ValidationFailure("foo", "bar"))));

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

            result.IsValid.ShouldBeFalse();
        }
Beispiel #2
0
        public void Does_not_execute_customasync_Rule_when_condition_false()
        {
            var validator = new TestValidator();

            validator.When(x => false, () => validator.CustomAsync(x => TaskHelpers.FromResult(new ValidationFailure("foo", "bar"))));

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

            result.IsValid.ShouldBeTrue();
        }
Beispiel #3
0
        public void Does_not_execute_customasync_Rule_when_async_condition_false()
        {
            var validator = new TestValidator();

            validator.WhenAsync(async x => (false), () => validator.CustomAsync(async x => (new ValidationFailure("foo", "bar"))));

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

            result.IsValid.ShouldBeTrue();
        }
Beispiel #4
0
        public void Nested_conditions_with_CustomAsync_rule()
        {
            var validator = new TestValidator();

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

            result.IsValid.ShouldBeTrue();
        }
 public void Should_throw_when_customasync_rule_is_null()
 {
     typeof(ArgumentNullException).ShouldBeThrownBy(() => validator.CustomAsync((Func <Person, Task <ValidationFailure> >)null));
 }