示例#1
0
        public void Should_create_field_by_properties()
        {
            var properties = new NumberFieldProperties();

            var field = sut.CreateField(1, "name", Partitioning.Invariant, properties);

            Assert.Equal(properties, field.RawProperties);
        }
示例#2
0
        public void Should_not_add_error_if_sut_is_valid()
        {
            var sut = new NumberFieldProperties
            {
                MinValue     = 0,
                MaxValue     = 100,
                DefaultValue = 5
            };

            sut.Validate(errors);

            Assert.Empty(errors);
        }
示例#3
0
        public void Should_add_error_if_allowed_values_and_max_value_is_specified()
        {
            var sut = new NumberFieldProperties {
                MaxValue = 10, AllowedValues = ImmutableList.Create <double>(4)
            };

            sut.Validate(errors);

            errors.ShouldBeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("Either allowed values or min and max value can be defined", "AllowedValues", "MinValue", "MaxValue")
            });
        }
示例#4
0
        public void Should_add_error_if_min_greater_than_max()
        {
            var sut = new NumberFieldProperties {
                MinValue = 10, MaxValue = 5
            };

            sut.Validate(errors);

            errors.ShouldBeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("Max value must be greater than min value", "MinValue", "MaxValue")
            });
        }
示例#5
0
        public void Should_add_error_if_default_value_is_greater_than_min()
        {
            var sut = new NumberFieldProperties {
                MaxValue = 0, DefaultValue = 5
            };

            sut.Validate(errors);

            errors.ShouldBeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("Default value must be less than max value", "DefaultValue")
            });
        }
示例#6
0
        public void Should_add_error_if_editor_is_not_valid()
        {
            var sut = new NumberFieldProperties {
                Editor = (NumberFieldEditor)123
            };

            sut.Validate(errors);

            errors.ShouldBeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("Editor is not a valid value", "Editor")
            });
        }
示例#7
0
        public void Should_add_error_if_radio_button_has_no_allowed_values()
        {
            var sut = new NumberFieldProperties {
                Editor = NumberFieldEditor.Radio
            };

            sut.Validate(errors);

            errors.ShouldBeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("Radio buttons or dropdown list need allowed values", "AllowedValues")
            });
        }
示例#8
0
        public void Should_set_or_freeze_sut()
        {
            var sut = new NumberFieldProperties();

            foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
            {
                var value =
                    property.PropertyType.GetTypeInfo().IsValueType ?
                    Activator.CreateInstance(property.PropertyType) :
                    null;

                property.SetValue(sut, value);

                var result = property.GetValue(sut);

                Assert.Equal(value, result);
            }

            sut.Freeze();

            foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
            {
                var value =
                    property.PropertyType.GetTypeInfo().IsValueType ?
                    Activator.CreateInstance(property.PropertyType) :
                    null;

                Assert.Throws <InvalidOperationException>(() =>
                {
                    try
                    {
                        property.SetValue(sut, value);
                    }
                    catch (Exception ex)
                    {
                        throw ex.InnerException;
                    }
                });
            }
        }
示例#9
0
 public static RootField <NumberFieldProperties> Number(long id, string name, Partitioning partitioning, NumberFieldProperties properties = null)
 {
     return(new RootField <NumberFieldProperties>(id, name, partitioning, properties ?? new NumberFieldProperties()));
 }
示例#10
0
 public static ArrayField AddNumber(this ArrayField field, long id, string name, NumberFieldProperties properties = null)
 {
     return(field.AddField(Number(id, name, properties)));
 }
示例#11
0
 public static Schema AddNumber(this Schema schema, long id, string name, Partitioning partitioning, NumberFieldProperties properties = null)
 {
     return(schema.AddField(Number(id, name, partitioning, properties)));
 }
示例#12
0
 public static NestedField <NumberFieldProperties> Number(long id, string name, NumberFieldProperties properties = null)
 {
     return(new NestedField <NumberFieldProperties>(id, name, properties ?? new NumberFieldProperties()));
 }
示例#13
0
 public static NestedField <NumberFieldProperties> Number(long id, string name, NumberFieldProperties properties = null, IFieldSettings settings = null)
 {
     return(new NestedField <NumberFieldProperties>(id, name, properties, settings));
 }
示例#14
0
 public static RootField <NumberFieldProperties> Number(long id, string name, Partitioning partitioning, NumberFieldProperties properties = null, IFieldSettings settings = null)
 {
     return(new RootField <NumberFieldProperties>(id, name, partitioning, properties, settings));
 }