public IEnumerable <ValidationError> Visit(NumberFieldProperties properties) { if (!properties.Editor.IsEnumValue()) { yield return(new ValidationError(Not.Valid(nameof(properties.Editor)), nameof(properties.Editor))); } if ((properties.Editor == NumberFieldEditor.Radio || properties.Editor == NumberFieldEditor.Dropdown) && properties.AllowedValues?.Any() != true) { yield return(new ValidationError(T.Get("schemas.stringEditorsNeedAllowedValuesError"), nameof(properties.AllowedValues))); } if (properties.MaxValue.HasValue && properties.MinValue.HasValue && properties.MinValue >= properties.MaxValue) { yield return(new ValidationError(Not.GreaterThan(nameof(properties.MaxValue), nameof(properties.MinValue)), nameof(properties.MinValue), nameof(properties.MaxValue))); } if (properties.InlineEditable && properties.Editor == NumberFieldEditor.Radio) { yield return(new ValidationError(T.Get("schemas.number.inlineEditorError"), nameof(properties.InlineEditable), nameof(properties.Editor))); } }
public FieldPropertiesDto Visit(NumberFieldProperties properties) { var result = SimpleMapper.Map(properties, new NumberFieldPropertiesDto()); result.AllowedValues = properties.AllowedValues?.ToArray(); return(result); }
public void Should_update_field() { var properties = new NumberFieldProperties(); var parent_1 = parent_0.AddField(CreateField(1)); var parent_2 = parent_1.UpdateField(1, f => f.Update(properties)); Assert.NotSame(properties, parent_1.FieldsById[1].RawProperties); Assert.Same(properties, parent_2.FieldsById[1].RawProperties); }
public void Should_not_add_error_if_inline_editing_is_allowed_for_editor(NumberFieldEditor editor) { var sut = new NumberFieldProperties { InlineEditable = true, Editor = editor, AllowedValues = ImmutableList.Create(1.0) }; var errors = FieldPropertiesValidator.Validate(sut).ToList(); Assert.Empty(errors); }
public void Should_update_field() { var properties = new NumberFieldProperties(); var schema_1 = schema_0.AddField(CreateField(1)); var schema_2 = schema_1.UpdateField(1, properties); Assert.NotSame(properties, schema_1.FieldsById[1].RawProperties); Assert.Same(properties, schema_2.FieldsById[1].RawProperties); }
private static FieldPropertiesDto Convert(NumberFieldProperties source) { var result = SimpleMapper.Map(source, new NumberFieldPropertiesDto()); if (source.AllowedValues != null) { result.AllowedValues = source.AllowedValues.ToArray(); } return(result); }
public void Should_not_add_error_if_sut_is_valid() { var sut = new NumberFieldProperties { MinValue = 0, MaxValue = 100, DefaultValue = 5 }; var errors = FieldPropertiesValidator.Validate(sut).ToList(); Assert.Empty(errors); }
public void Should_add_error_if_inline_editing_is_not_allowed_for_editor(NumberFieldEditor editor) { var sut = new NumberFieldProperties { InlineEditable = true, Editor = editor, AllowedValues = ReadOnlyCollection.Create(1.0) }; var errors = FieldPropertiesValidator.Validate(sut).ToList(); errors.Should().BeEquivalentTo( new List <ValidationError> { new ValidationError("Inline editing is only allowed for dropdowns and input fields.", "InlineEditable", "Editor") }); }
public void Should_add_error_if_default_value_is_less_than_min() { var sut = new NumberFieldProperties { MinValue = 10, DefaultValue = 5 }; var errors = FieldPropertiesValidator.Validate(sut).ToList(); errors.Should().BeEquivalentTo( new List <ValidationError> { new ValidationError("Default value must be greater or equal to min value.", "DefaultValue") }); }
public void Should_add_error_if_inline_editing_is_not_allowed_for_editor(NumberFieldEditor editor) { var sut = new NumberFieldProperties { InlineEditable = true, Editor = editor, AllowedValues = ImmutableList.Create(1.0) }; var errors = FieldPropertiesValidator.Validate(sut).ToList(); errors.Should().BeEquivalentTo( new List <ValidationError> { new ValidationError("Inline editing is not allowed for Radio editor.", "InlineEditable", "Editor") }); }
public void Should_add_error_if_min_greater_than_max() { var sut = new NumberFieldProperties { MinValue = 10, MaxValue = 5 }; var errors = FieldPropertiesValidator.Validate(sut).ToList(); errors.ShouldBeEquivalentTo( new List <ValidationError> { new ValidationError("Max value must be greater than min value.", "MinValue", "MaxValue") }); }
public void Should_add_error_if_radio_button_has_no_allowed_values() { var sut = new NumberFieldProperties { Editor = NumberFieldEditor.Radio }; var errors = FieldPropertiesValidator.Validate(sut).ToList(); errors.ShouldBeEquivalentTo( new List <ValidationError> { new ValidationError("Radio buttons or dropdown list need allowed values.", "AllowedValues") }); }
public void Should_add_error_if_default_value_is_greater_than_min() { var sut = new NumberFieldProperties { MaxValue = 0, DefaultValue = 5 }; var errors = FieldPropertiesValidator.Validate(sut).ToList(); errors.ShouldBeEquivalentTo( new List <ValidationError> { new ValidationError("Default value must be less than max value.", "DefaultValue") }); }
public void Should_add_error_if_editor_is_not_valid() { var sut = new NumberFieldProperties { Editor = (NumberFieldEditor)123 }; var errors = FieldPropertiesValidator.Validate(sut).ToList(); errors.ShouldBeEquivalentTo( new List <ValidationError> { new ValidationError("Editor is not a valid value.", "Editor") }); }
public void Should_add_error_if_allowed_values_and_max_value_is_specified() { var sut = new NumberFieldProperties { MaxValue = 10, AllowedValues = ImmutableList.Create <double>(4) }; var errors = FieldPropertiesValidator.Validate(sut).ToList(); errors.ShouldBeEquivalentTo( new List <ValidationError> { new ValidationError("Either allowed values or min and max value can be defined.", "AllowedValues", "MinValue", "MaxValue") }); }
public IEnumerable <ValidationError> Visit(NumberFieldProperties properties) { if (!properties.Editor.IsEnumValue()) { yield return(new ValidationError("Editor is not a valid value.", nameof(properties.Editor))); } if ((properties.Editor == NumberFieldEditor.Radio || properties.Editor == NumberFieldEditor.Dropdown) && (properties.AllowedValues == null || properties.AllowedValues.Count == 0)) { yield return(new ValidationError("Radio buttons or dropdown list need allowed values.", nameof(properties.AllowedValues))); } if (properties.DefaultValue.HasValue && properties.MinValue.HasValue && properties.DefaultValue.Value < properties.MinValue.Value) { yield return(new ValidationError("Default value must be greater than min value.", nameof(properties.DefaultValue))); } if (properties.DefaultValue.HasValue && properties.MaxValue.HasValue && properties.DefaultValue.Value > properties.MaxValue.Value) { yield return(new ValidationError("Default value must be less than max value.", nameof(properties.DefaultValue))); } if (properties.MaxValue.HasValue && properties.MinValue.HasValue && properties.MinValue.Value >= properties.MaxValue.Value) { yield return(new ValidationError("Max value must be greater than min value.", nameof(properties.MinValue), nameof(properties.MaxValue))); } if (properties.AllowedValues != null && properties.AllowedValues.Count > 0 && (properties.MinValue.HasValue || properties.MaxValue.HasValue)) { yield return(new ValidationError("Either allowed values or min and max value can be defined.", nameof(properties.AllowedValues), nameof(properties.MinValue), nameof(properties.MaxValue))); } if (properties.InlineEditable && properties.Editor != NumberFieldEditor.Input && properties.Editor != NumberFieldEditor.Dropdown) { yield return(new ValidationError("Inline editing is only allowed for dropdowns and input fields.", nameof(properties.InlineEditable), nameof(properties.Editor))); } }
public IEnumerable <ValidationError> Visit(NumberFieldProperties properties) { if (!properties.Editor.IsEnumValue()) { yield return(new ValidationError(Not.Valid("Editor"), nameof(properties.Editor))); } if ((properties.Editor == NumberFieldEditor.Radio || properties.Editor == NumberFieldEditor.Dropdown) && (properties.AllowedValues == null || properties.AllowedValues.Count == 0)) { yield return(new ValidationError("Radio buttons or dropdown list need allowed values.", nameof(properties.AllowedValues))); } if (properties.DefaultValue.HasValue && properties.MinValue.HasValue && properties.DefaultValue.Value < properties.MinValue.Value) { yield return(new ValidationError(Not.GreaterEquals("Default value", "min value"), nameof(properties.DefaultValue))); } if (properties.DefaultValue.HasValue && properties.MaxValue.HasValue && properties.DefaultValue.Value > properties.MaxValue.Value) { yield return(new ValidationError(Not.LessEquals("Default value", "max value"), nameof(properties.DefaultValue))); } if (properties.MaxValue.HasValue && properties.MinValue.HasValue && properties.MinValue.Value >= properties.MaxValue.Value) { yield return(new ValidationError(Not.GreaterThan("Max value", "min value"), nameof(properties.MinValue), nameof(properties.MaxValue))); } if (properties.AllowedValues != null && properties.AllowedValues.Count > 0 && (properties.MinValue.HasValue || properties.MaxValue.HasValue)) { yield return(new ValidationError("Either allowed values or min and max value can be defined.", nameof(properties.AllowedValues), nameof(properties.MinValue), nameof(properties.MaxValue))); } if (properties.InlineEditable && properties.Editor == NumberFieldEditor.Radio) { yield return(new ValidationError("Inline editing is not allowed for Radio editor.", nameof(properties.InlineEditable), nameof(properties.Editor))); } }
public IEnumerable <IValidator> Visit(NumberFieldProperties properties) { if (properties.IsRequired) { yield return(new RequiredValidator()); } if (properties.MinValue.HasValue || properties.MaxValue.HasValue) { yield return(new RangeValidator <double>(properties.MinValue, properties.MaxValue)); } if (properties.AllowedValues != null) { yield return(new AllowedValuesValidator <double>(properties.AllowedValues.ToArray())); } }
public void AddField_should_update_schema_and_create_events() { var properties = new NumberFieldProperties(); CreateSchema(); sut.AddField(CreateCommand(new AddField { Name = fieldName, Properties = properties })); Assert.Equal(properties, sut.Schema.Fields[1].RawProperties); sut.GetUncomittedEvents() .ShouldHaveSameEvents( CreateEvent(new FieldAdded { Name = fieldName, FieldId = fieldId, Properties = properties }) ); }
public void Should_update_field() { var properties1 = new NumberFieldProperties { MinValue = 10 }; var properties2 = new NumberFieldProperties { MinValue = 10 }; var schema_1 = schema_0.AddField(CreateField(1)); var schema_2 = schema_1.UpdateField(1, f => f.Update(properties1)); var schema_3 = schema_2.UpdateField(1, f => f.Update(properties2)); Assert.NotSame(properties1, schema_1.FieldsById[1].RawProperties); Assert.Same(properties1, schema_2.FieldsById[1].RawProperties); Assert.Same(properties1, schema_3.FieldsById[1].RawProperties); Assert.Same(schema_2, schema_3); }
public void UpdateField_should_update_schema_and_create_events() { var properties = new NumberFieldProperties(); CreateSchema(); CreateField(); sut.UpdateField(CreateCommand(new UpdateField { FieldId = 1, Properties = properties })); Assert.Equal(properties, sut.Snapshot.SchemaDef.FieldsById[1].RawProperties); sut.GetUncomittedEvents() .ShouldHaveSameEvents( CreateEvent(new FieldUpdated { FieldId = fieldId, Properties = properties }) ); }
private static NumberField Field(NumberFieldProperties properties) { return(new NumberField(1, "my-number", Partitioning.Invariant, properties)); }
private static RootField <NumberFieldProperties> Field(NumberFieldProperties properties) { return(Fields.Number(1, "my-number", Partitioning.Invariant, properties)); }
public static Schema AddNumber(this Schema schema, long id, string name, Partitioning partitioning, NumberFieldProperties properties = null) { return(schema.AddField(Number(id, name, partitioning, properties))); }
public JToken Visit(NumberFieldProperties properties) { return(properties.DefaultValue); }
public IJsonValue Visit(NumberFieldProperties properties, Args args) { var value = GetDefaultValue(properties.DefaultValue, properties.DefaultValues, args.Partition); return(JsonValue.Create(value)); }
public static Field <NumberFieldProperties> Number(long id, string name, Partitioning partitioning, NumberFieldProperties properties = null) { return(new Field <NumberFieldProperties>(id, name, partitioning, properties ?? new NumberFieldProperties())); }
public FieldPropertiesDto Visit(NumberFieldProperties properties) { return(SimpleMapper.Map(properties, new NumberFieldPropertiesDto())); }