Exemplo n.º 1
0
        public FieldPropertiesDto Visit(ReferencesFieldProperties properties)
        {
            var result = SimpleMapper.Map(properties, new ReferencesFieldPropertiesDto());

            result.SchemaIds = properties.SchemaIds?.ToArray();

            return(result);
        }
Exemplo n.º 2
0
 public IEnumerable <ValidationError> Visit(ReferencesFieldProperties properties)
 {
     if (properties.MaxItems.HasValue && properties.MinItems.HasValue && properties.MinItems.Value >= properties.MaxItems.Value)
     {
         yield return(new ValidationError("Max items must be greater than min items.",
                                          nameof(properties.MinItems),
                                          nameof(properties.MaxItems)));
     }
 }
Exemplo n.º 3
0
 public IEnumerable <ValidationError> Visit(ReferencesFieldProperties properties)
 {
     if (properties.MaxItems.HasValue && properties.MinItems.HasValue && properties.MinItems.Value > properties.MaxItems.Value)
     {
         yield return(new ValidationError(Not.GreaterEquals("Max items", "min items"),
                                          nameof(properties.MinItems),
                                          nameof(properties.MaxItems)));
     }
 }
        public async Task Should_not_add_error_if_references_are_empty_but_not_required()
        {
            var properties = new ReferencesFieldProperties();

            var sut = Validator(properties);

            await sut.ValidateAsync(CreateValue(), errors);

            Assert.Empty(errors);
        }
        public void Should_not_add_error_if_min_items_greater_equals_to_max_items()
        {
            var sut = new ReferencesFieldProperties {
                MinItems = 2, MaxItems = 2
            };

            var errors = FieldPropertiesValidator.Validate(sut).ToList();

            Assert.Empty(errors);
        }
        public async Task Should_not_add_error_if_schemas_not_defined()
        {
            var properties = new ReferencesFieldProperties();

            var sut = Validator(properties, schemaId2, (ref2, Status.Published));

            await sut.ValidateAsync(CreateValue(ref2), errors);

            Assert.Empty(errors);
        }
        public async Task Should_add_error_if_references_are_not_valid()
        {
            var properties = new ReferencesFieldProperties();

            var sut = Validator(properties);

            await sut.ValidateAsync(CreateValue(ref1), errors);

            errors.Should().BeEquivalentTo(
                new[] { $"[1]: Reference '{ref1}' not found." });
        }
        public async Task Should_add_error_if_reference_contains_duplicate_values()
        {
            var properties = new ReferencesFieldProperties();

            var sut = Validator(properties, schemaId1, (ref1, Status.Published));

            await sut.ValidateAsync(CreateValue(ref1, ref1), errors);

            errors.Should().BeEquivalentTo(
                new[] { "Must not contain duplicate values." });
        }
        public async Task Should_not_add_error_if_duplicates_are_allowed()
        {
            var properties = new ReferencesFieldProperties {
                AllowDuplicates = true
            };

            var sut = Validator(properties, schemaId1, (ref1, Status.Published));

            await sut.ValidateAsync(CreateValue(ref1, ref1), errors);

            Assert.Empty(errors);
        }
        public async Task Should_not_add_error_if_reference_invalid_but_publishing()
        {
            var properties = new ReferencesFieldProperties {
                SchemaId = schemaId1
            };

            var sut = Validator(properties, schemaId2, (ref2, Status.Published));

            await sut.ValidateAsync(CreateValue(ref2), errors, action : ValidationAction.Publish);

            Assert.Empty(errors);
        }
Exemplo n.º 11
0
        public IEnumerable <IValidator> Visit(ReferencesFieldProperties properties)
        {
            if (properties.IsRequired || properties.MinItems.HasValue || properties.MaxItems.HasValue)
            {
                yield return(new CollectionValidator <Guid>(properties.IsRequired, properties.MinItems, properties.MaxItems));
            }

            if (properties.SchemaId != Guid.Empty)
            {
                yield return(new ReferencesValidator(properties.SchemaId));
            }
        }
        public async Task Should_add_error_if_references_are_published_required()
        {
            var properties = new ReferencesFieldProperties {
                MustBePublished = true, IsRequired = true
            };

            var sut = Validator(properties, schemaId1, (ref1, Status.Published));

            await sut.ValidateAsync(CreateValue(), errors);

            errors.Should().BeEquivalentTo(
                new[] { "Field is required." });
        }
        public async Task Should_add_error_if_value_has_too_much_items()
        {
            var properties = new ReferencesFieldProperties {
                MaxItems = 1
            };

            var sut = Validator(properties, schemaId1, (ref1, Status.Published), (ref2, Status.Draft));

            await sut.ValidateAsync(CreateValue(ref1, ref2), errors);

            errors.Should().BeEquivalentTo(
                new[] { "Must not have more than 1 item(s)." });
        }
        public async Task Should_add_error_if_value_has_not_enough_published_items()
        {
            var properties = new ReferencesFieldProperties {
                MinItems = 2, MustBePublished = true
            };

            var sut = Validator(properties, schemaId1, (ref1, Status.Published), (ref2, Status.Draft));

            await sut.ValidateAsync(CreateValue(ref1, ref2), errors);

            errors.Should().BeEquivalentTo(
                new[] { "Must have at least 2 item(s)." });
        }
        public async Task Should_add_error_if_reference_schema_is_not_valid()
        {
            var properties = new ReferencesFieldProperties {
                SchemaId = schemaId1
            };

            var sut = Validator(properties, schemaId2, (ref2, Status.Draft));

            await sut.ValidateAsync(CreateValue(ref2), errors);

            errors.Should().BeEquivalentTo(
                new[] { $"[1]: Reference '{ref2}' has invalid schema." });
        }
        public void Should_add_error_if_editor_is_not_valid()
        {
            var sut = new ReferencesFieldProperties {
                Editor = (ReferencesFieldEditor)123
            };

            var errors = FieldPropertiesValidator.Validate(sut).ToList();

            errors.Should().BeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("Editor is not a valid value.", "Editor")
            });
        }
Exemplo n.º 17
0
        public void Should_add_error_if_min_greater_than_max()
        {
            var sut = new ReferencesFieldProperties {
                MinItems = 10, MaxItems = 5
            };

            var errors = FieldPropertiesValidator.Validate(sut).ToList();

            errors.ShouldBeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("Max items must be greater than min items.", "MinItems", "MaxItems")
            });
        }
        public void Should_add_error_if_resolving_references_with_more_than_one_max_items()
        {
            var sut = new ReferencesFieldProperties {
                ResolveReference = true, MaxItems = 2
            };

            var errors = FieldPropertiesValidator.Validate(sut).ToList();

            errors.Should().BeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("Can only resolve references when MaxItems is 1.", "ResolveReference", "MaxItems")
            });
        }
Exemplo n.º 19
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;
        }
Exemplo n.º 20
0
        public IEnumerable <ValidationError> Visit(ReferencesFieldProperties properties)
        {
            if (!properties.Editor.IsEnumValue())
            {
                yield return(new ValidationError(Not.Valid(nameof(properties.Editor)),
                                                 nameof(properties.Editor)));
            }

            if (properties.MaxItems.HasValue && properties.MinItems.HasValue && properties.MinItems > properties.MaxItems)
            {
                yield return(new ValidationError(Not.GreaterEqualsThan(nameof(properties.MaxItems), nameof(properties.MinItems)),
                                                 nameof(properties.MinItems),
                                                 nameof(properties.MaxItems)));
            }

            if (properties.ResolveReference && properties.MaxItems != 1)
            {
                yield return(new ValidationError(T.Get("schemas.references.resolveError"),
                                                 nameof(properties.ResolveReference),
                                                 nameof(properties.MaxItems)));
            }
        }
Exemplo n.º 21
0
        public IEnumerable <ValidationError> Visit(ReferencesFieldProperties properties)
        {
            if (!properties.Editor.IsEnumValue())
            {
                yield return(new ValidationError(Not.Valid("Editor"),
                                                 nameof(properties.Editor)));
            }

            if (properties.MaxItems.HasValue && properties.MinItems.HasValue && properties.MinItems.Value > properties.MaxItems.Value)
            {
                yield return(new ValidationError(Not.GreaterEquals("Max items", "min items"),
                                                 nameof(properties.MinItems),
                                                 nameof(properties.MaxItems)));
            }

            if (properties.ResolveReference && properties.MaxItems != 1)
            {
                yield return(new ValidationError("Can only resolve references when MaxItems is 1.",
                                                 nameof(properties.ResolveReference),
                                                 nameof(properties.MaxItems)));
            }
        }
Exemplo n.º 22
0
        public ContentUnionGraphType(Builder builder, FieldInfo fieldInfo, ReferencesFieldProperties properties)
        {
            Name = fieldInfo.UnionType;

            if (properties.SchemaIds?.Any() == true)
            {
                foreach (var schemaId in properties.SchemaIds)
                {
                    var contentType = builder.GetContentType(schemaId);

                    if (contentType != null)
                    {
                        types[schemaId] = contentType;
                    }
                }
            }
            else
            {
                foreach (var(key, value) in builder.GetAllContentTypes())
                {
                    types[key.Schema.Id] = value;
                }
            }

            foreach (var type in types)
            {
                AddPossibleType(type.Value);
            }

            ResolveType = value =>
            {
                if (value is IContentEntity content)
                {
                    return(types.GetOrDefault(content.SchemaId.Id));
                }

                return(null);
            };
        }
Exemplo n.º 23
0
        public IJsonValue Visit(ReferencesFieldProperties properties, Args args)
        {
            var value = GetDefaultValue(properties.DefaultValue, properties.DefaultValues, args.Partition);

            return(Array(value));
        }
Exemplo n.º 24
0
 private static ReferencesField Field(ReferencesFieldProperties properties)
 {
     return(new ReferencesField(1, "my-refs", Partitioning.Invariant, properties));
 }
Exemplo n.º 25
0
 private static Field <ReferencesFieldProperties> Field(ReferencesFieldProperties properties)
 {
     return(Fields.References(1, "my-refs", Partitioning.Invariant, properties));
 }
Exemplo n.º 26
0
 public FieldPropertiesDto Visit(ReferencesFieldProperties properties)
 {
     return(SimpleMapper.Map(properties, new ReferencesFieldPropertiesDto()));
 }
 private IValidator Validator(ReferencesFieldProperties properties)
 {
     return(new ReferencesValidator(properties.IsRequired, properties, FoundReferences(schemaId1)));
 }
 private IValidator Validator(ReferencesFieldProperties properties, DomainId schemaId, params (DomainId Id, Status Status)[] references)
Exemplo n.º 29
0
        private static FieldPropertiesDto Convert(ReferencesFieldProperties source)
        {
            var result = SimpleMapper.Map(source, new ReferencesFieldPropertiesDto());

            return(result);
        }
Exemplo n.º 30
0
 public JToken Visit(ReferencesFieldProperties properties)
 {
     return(new JArray());
 }