Ejemplo n.º 1
0
        public async Task Should_add_error_if_array_field_has_required_nested_field()
        {
            schema = schema.AddArray(1, "my-field", Partitioning.Invariant, f => f.
                                     AddNumber(2, "my-nested", new NumberFieldProperties {
                IsRequired = true
            }));

            var data =
                new ContentData()
                .AddField("my-field",
                          new ContentFieldData()
                          .AddInvariant(
                              JsonValue.Array(
                                  JsonValue.Object(),
                                  JsonValue.Object().Add("my-nested", 1),
                                  JsonValue.Object())));

            await data.ValidatePartialAsync(languagesConfig.ToResolver(), errors, schema);

            errors.Should().BeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("Field is required.", "my-field.iv[1].my-nested"),
                new ValidationError("Field is required.", "my-field.iv[3].my-nested")
            });
        }
Ejemplo n.º 2
0
        public async Task Should_add_error_if_array_field_has_required_nested_field()
        {
            schema =
                schema.AddArray(1, "my-field", Partitioning.Invariant, f => f.
                                AddNumber(1, "my-nested", new NumberFieldProperties {
                IsRequired = true
            }));

            var data =
                new NamedContentData()
                .AddField("my-field",
                          new ContentFieldData()
                          .AddValue("iv", new JArray(
                                        new JObject(),
                                        new JObject(new JProperty("my-nested", 1)),
                                        new JObject())));

            await data.ValidatePartialAsync(context, schema, languagesConfig.ToResolver(), errors);

            errors.ShouldBeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("my-field[1].my-nested: Field is required.", "my-field[1].my-nested"),
                new ValidationError("my-field[3].my-nested: Field is required.", "my-field[3].my-nested"),
            });
        }