Example #1
0
        public async Task Should_not_add_error_if_value_is_empty()
        {
            var sut = new StringLengthValidator(100, 200);

            await sut.ValidateAsync(string.Empty, errors);

            Assert.Empty(errors);
        }
Example #2
0
        public async Task Should_not_add_error_if_value_is_within_range(int?min, int?max)
        {
            var sut = new StringLengthValidator(min, max);

            await sut.ValidateAsync(CreateString(1500), errors);

            Assert.Empty(errors);
        }
Example #3
0
        public async Task Should_not_add_error_if_value_is_null()
        {
            var sut = new StringLengthValidator();

            await sut.ValidateAsync(null, errors);

            Assert.Empty(errors);
        }
Example #4
0
        public async Task Should_add_error_if_value_is_greater_than_max()
        {
            var sut = new StringLengthValidator(null, 1000);

            await sut.ValidateAsync(CreateString(1500), errors);

            errors.ShouldBeEquivalentTo(
                new[] { "<FIELD> must have less than '1000' characters." });
        }
Example #5
0
        public async Task Should_add_error_if_value_is_smaller_than_min()
        {
            var sut = new StringLengthValidator(2000, null);

            await sut.ValidateAsync(CreateString(1500), errors);

            errors.ShouldBeEquivalentTo(
                new[] { "<FIELD> must have more than '2000' characters." });
        }
Example #6
0
        public async Task Should_add_error_if_collection_count_is_not_in_range()
        {
            var sut = new StringLengthValidator(2000, 5000);

            await sut.ValidateAsync(CreateString(1), errors);

            errors.Should().BeEquivalentTo(
                new[] { "Must have between 2000 and 5000 character(s)." });
        }
Example #7
0
        public async Task Should_add_error_if_value_is_greater_than_max()
        {
            var sut = new StringLengthValidator(null, 1000);

            await sut.ValidateAsync(CreateString(1500), errors);

            errors.Should().BeEquivalentTo(
                new[] { "Must not have more than 1000 character(s)." });
        }
Example #8
0
        public async Task Should_add_error_if_value_is_smaller_than_min()
        {
            var sut = new StringLengthValidator(2000, null);

            await sut.ValidateAsync(CreateString(1500), errors);

            errors.Should().BeEquivalentTo(
                new[] { "Must have at least 2000 character(s)." });
        }
Example #9
0
        public async Task Should_add_error_if_value_has_not_exact_number_of_characters()
        {
            var sut = new StringLengthValidator(2000, 2000);

            await sut.ValidateAsync(CreateString(4), errors);

            errors.Should().BeEquivalentTo(
                new[] { "Must have exactly 2000 character(s)." });
        }