public static Schema MixedSchema() { var inv = Partitioning.Invariant; var schema = new Schema("user"); schema = schema.Publish(); schema = schema.Update(new SchemaProperties { Hints = "The User" }); schema = schema.AddJson(1, "my-json", inv, new JsonFieldProperties()); schema = schema.AddAssets(2, "my-assets", inv, new AssetsFieldProperties()); schema = schema.AddString(3, "my-string1", inv, new StringFieldProperties { Label = "My String1", IsRequired = true, AllowedValues = ImmutableList.Create("a", "b") }); schema = schema.AddString(4, "my-string2", inv, new StringFieldProperties { Hints = "My String1" }); schema = schema.AddNumber(5, "my-number", inv, new NumberFieldProperties { MinValue = 1, MaxValue = 10 }); schema = schema.AddBoolean(6, "my-boolean", inv, new BooleanFieldProperties()); schema = schema.AddDateTime(7, "my-datetime", inv, new DateTimeFieldProperties { Editor = DateTimeFieldEditor.DateTime }); schema = schema.AddDateTime(8, "my-date", inv, new DateTimeFieldProperties { Editor = DateTimeFieldEditor.Date }); schema = schema.AddGeolocation(9, "my-geolocation", inv, new GeolocationFieldProperties()); schema = schema.AddReferences(10, "my-references", inv, new ReferencesFieldProperties()); schema = schema.AddTags(11, "my-tags", Partitioning.Language, new TagsFieldProperties()); schema = schema.HideField(7); schema = schema.LockField(8); schema = schema.DisableField(9); return(schema); }
public async Task Should_add_error_if_value_validator_throws_exception() { var validator = A.Fake <IValidator>(); A.CallTo(() => validator.ValidateAsync(A <object?> ._, A <ValidationContext> ._, A <AddError> ._)) .Throws(new InvalidOperationException()); var validatorFactory = A.Fake <IValidatorsFactory>(); A.CallTo(() => validatorFactory.CreateValueValidators(A <ValidationContext> ._, A <IField> ._, A <ValidatorFactory> ._)) .Returns(Enumerable.Repeat(validator, 1)); schema = schema.AddNumber(1, "my-field", Partitioning.Invariant, new NumberFieldProperties()); var data = new ContentData() .AddField("my-field", new ContentFieldData() .AddInvariant(1000)); await data.ValidateAsync(languagesConfig.ToResolver(), errors, schema, factory : validatorFactory); errors.Should().BeEquivalentTo( new List <ValidationError> { new ValidationError("Validation failed with internal error.", "my-field.iv") }); }
public async Task Should_add_error_if_validating_data_with_invalid_field() { schema = schema.AddNumber(1, "my-field", Partitioning.Invariant, new NumberFieldProperties { MaxValue = 100 }); var data = new NamedContentData() .AddField("my-field", new ContentFieldData() .AddValue(1000)); await data.ValidateAsync(context, schema, languagesConfig.ToResolver(), errors); errors.ShouldBeEquivalentTo( new List <ValidationError> { new ValidationError("my-field: Must be less or equals than '100'.", "my-field") }); }