예제 #1
0
        public async Task Should_not_add_error_if_value_is_wrong_type()
        {
            var sut = new CollectionItemValidator(new RangeValidator <int>(2, 4));

            await sut.ValidateAsync(true, errors);

            Assert.Empty(errors);
        }
예제 #2
0
        public async Task Should_not_add_error_if_all_values_are_valid()
        {
            var sut = new CollectionItemValidator(new RangeValidator <int>(2, 4));

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

            Assert.Empty(errors);
        }
예제 #3
0
        public void SetUp()
        {
            _collectionItem = new CollectionItem();
            var noErrSpec = new Mock <ISpecification>();

            noErrSpec.Setup(x => x.Satisfy(It.IsAny <DomainEntity>())).Returns(Error.Empty);
            _emptySpec = new Mock <IEmptySpecification>();
            _emptySpec.Setup(x => x.SetProperty(It.IsAny <string>())).Returns(noErrSpec.Object);
            _validator = new CollectionItemValidator(_emptySpec.Object);
        }
예제 #4
0
        public async Task Should_add_error_if_at_least_one_item_is_not_valid()
        {
            var sut = new CollectionItemValidator(new RangeValidator <int>(2, 4));

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

            errors.Should().BeEquivalentTo(
                new[]
            {
                "[2]: Must be greater than or equal to '2'.",
                "[4]: Must be less than or equal to '4'."
            });
        }
예제 #5
0
        public async Task Should_add_error_if_at_least_one_item_is_not_valid()
        {
            var sut = new CollectionItemValidator <int>(new RangeValidator <int>(2, 4));

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

            errors.ShouldBeEquivalentTo(
                new[]
            {
                "<FIELD> item #2 must be greater or equals than '2'.",
                "<FIELD> item #4 must be less or equals than '4'."
            });
        }