Exemplo n.º 1
0
        public async Task Should_not_add_error_if_optional()
        {
            var sut = new CollectionValidator(true, 1, 3);

            await sut.ValidateAsync(null, errors, updater : c => c.Optional(true));

            Assert.Empty(errors);
        }
Exemplo n.º 2
0
        public async Task Should_add_error_if_value_is_null()
        {
            var sut = new CollectionValidator(true, 1, 3);

            await sut.ValidateAsync(null, errors);

            errors.ShouldBeEquivalentTo(
                new[] { "Field is required." });
        }
Exemplo n.º 3
0
        public async Task Should_not_add_error_if_value_is_valid()
        {
            var sut = new CollectionValidator(true, 1, 3);

            await sut.ValidateAsync(new List <int> {
                1, 2
            }, errors);

            Assert.Empty(errors);
        }
Exemplo n.º 4
0
        public async Task Should_add_error_if_collection_has_too_many_items()
        {
            var sut = new CollectionValidator(true, 2, 3);

            await sut.ValidateAsync(new List <int> {
                1, 2, 3, 4
            }, errors);

            errors.ShouldBeEquivalentTo(
                new[] { "Must have not more than 3 item(s)." });
        }
Exemplo n.º 5
0
        public async Task Should_add_error_if_collection_has_too_few_items()
        {
            var sut = new CollectionValidator(true, 2, 3);

            await sut.ValidateAsync(new List <int> {
                1
            }, errors);

            errors.ShouldBeEquivalentTo(
                new[] { "Must have at least 2 item(s)." });
        }
        public async Task Should_add_error_if_collection_has_not_exact_number_of_items()
        {
            var sut = new CollectionValidator(true, 2, 2);

            await sut.ValidateAsync(new List <int> {
                1
            }, errors);

            errors.Should().BeEquivalentTo(
                new[] { "Must have exactly 2 item(s)." });
        }
        public async Task Should_add_error_if_collection_count_is_not_in_range()
        {
            var sut = new CollectionValidator(true, 2, 5);

            await sut.ValidateAsync(new List <int> {
                1
            }, errors);

            errors.Should().BeEquivalentTo(
                new[] { "Must have between 2 and 5 item(s)." });
        }