예제 #1
0
        public void IsValid_WhenString_IsNull()
        {
            var command = new FakeStringLengthCommand {
                StringProperty = null
            };
            var validator = new FakeStringMinLengthValidator(new Random().Next(1, int.MaxValue - 3));

            var result = validator.Validate(command);

            result.IsValid.ShouldBeTrue();
            Func <ValidationFailure, bool> minLengthError = x => x.PropertyName == command.PropertyName(y => y.StringProperty);

            result.Errors.Any(minLengthError).ShouldBeFalse();
            validator.ShouldNotHaveValidationErrorFor(x => x.StringProperty, command.StringProperty);
        }
예제 #2
0
        public void IsValid_WhenStringLength_IsGreaterThanMinLength()
        {
            var command = new FakeStringLengthCommand {
                StringProperty = Guid.NewGuid().ToString()
            };
            var validator = new FakeStringMinLengthValidator(5);

            var result = validator.Validate(command);

            result.IsValid.ShouldBeTrue();
            Func <ValidationFailure, bool> minLengthError = x => x.PropertyName == command.PropertyName(y => y.StringProperty);

            result.Errors.Any(minLengthError).ShouldBeFalse();
            validator.ShouldNotHaveValidationErrorFor(x => x.StringProperty, command.StringProperty);
        }