Exemplo n.º 1
0
        public async Task Should_not_add_error_if_array_contains_no_duplicates()
        {
            var sut = new UniqueValuesValidator <int>();

            await sut.ValidateAsync(new[] { 1, 2, 3 }, errors);

            Assert.Empty(errors);
        }
Exemplo n.º 2
0
        public async Task Should_not_add_error_if_value_is_not_collection()
        {
            var sut = new UniqueValuesValidator <int>();

            await sut.ValidateAsync("value", errors);

            Assert.Empty(errors);
        }
Exemplo n.º 3
0
        public async Task Should_add_error_if_array_contains_duplicates()
        {
            var sut = new UniqueValuesValidator <int>();

            await sut.ValidateAsync(new[] { 1, 2, 2, 3 }, errors);

            errors.Should().BeEquivalentTo(
                new[] { "Must not contain duplicate values." });
        }
Exemplo n.º 4
0
        public ReferencesValidator(bool isRequired, ReferencesFieldProperties properties, CheckContentsByIds checkReferences)
        {
            Guard.NotNull(properties, nameof(properties));
            Guard.NotNull(checkReferences, nameof(checkReferences));

            this.properties = properties;

            if (isRequired || properties.MinItems != null || properties.MaxItems != null)
            {
                collectionValidator = new CollectionValidator(isRequired, properties.MinItems, properties.MaxItems);
            }

            if (!properties.AllowDuplicates)
            {
                uniqueValidator = new UniqueValuesValidator <DomainId>();
            }

            this.checkReferences = checkReferences;
        }