예제 #1
0
        public void Should_provide_specific_default_value()
        {
            var sut = new DateTimeFieldProperties {
                DefaultValue = FutureDays(15)
            };

            Assert.Equal(FutureDays(15).ToString(), sut.GetDefaultValue());
        }
예제 #2
0
        public void Should_provide_today_default_value()
        {
            var sut = new DateTimeFieldProperties {
                CalculatedDefaultValue = DateTimeCalculatedDefaultValue.Today
            };

            Assert.Equal(DateTime.UtcNow.Date.ToString("o"), sut.GetDefaultValue().ToString());
        }
예제 #3
0
        public void Should_provide_now_default_value()
        {
            var sut = new DateTimeFieldProperties {
                CalculatedDefaultValue = DateTimeCalculatedDefaultValue.Now
            };

            Assert.Equal(DateTime.UtcNow.ToString("o").Substring(0, 16), sut.GetDefaultValue().ToString().Substring(0, 16));
        }
예제 #4
0
        public void Should_not_add_error_if_sut_is_valid()
        {
            var sut = new DateTimeFieldProperties
            {
                MinValue     = FutureDays(10),
                MaxValue     = FutureDays(20),
                DefaultValue = FutureDays(15)
            };

            sut.Validate(errors);

            Assert.Empty(errors);
        }
예제 #5
0
        public void Should_add_error_if_editor_is_not_valid()
        {
            var sut = new DateTimeFieldProperties {
                Editor = (DateTimeFieldEditor)123
            };

            sut.Validate(errors);

            errors.ShouldBeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("Editor is not a valid value", "Editor")
            });
        }
예제 #6
0
        public void Should_add_error_if_min_greater_than_max()
        {
            var sut = new DateTimeFieldProperties {
                MinValue = FutureDays(10), MaxValue = FutureDays(5)
            };

            sut.Validate(errors);

            errors.ShouldBeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("Max value must be greater than min value", "MinValue", "MaxValue")
            });
        }
예제 #7
0
        public void Should_add_error_if_default_value_is_greater_than_min()
        {
            var sut = new DateTimeFieldProperties {
                MaxValue = FutureDays(10), DefaultValue = FutureDays(15)
            };

            sut.Validate(errors);

            errors.ShouldBeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("Default value must be less than max value", "DefaultValue")
            });
        }
예제 #8
0
        public void Should_add_error_if_calculated_default_value_default_value_is_defined()
        {
            var sut = new DateTimeFieldProperties {
                CalculatedDefaultValue = DateTimeCalculatedDefaultValue.Now, DefaultValue = FutureDays(10)
            };

            sut.Validate(errors);

            errors.ShouldBeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("Calculated default value and default value cannot be used together", "CalculatedDefaultValue", "DefaultValue")
            });
        }
예제 #9
0
        public void Should_add_error_if_calculated_default_value_is_not_valid()
        {
            var sut = new DateTimeFieldProperties {
                CalculatedDefaultValue = (DateTimeCalculatedDefaultValue)123
            };

            sut.Validate(errors);

            errors.ShouldBeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("Calculated default value is not valid", "CalculatedDefaultValue")
            });
        }
예제 #10
0
        public void Should_set_or_freeze_sut()
        {
            var sut = new DateTimeFieldProperties();

            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;
                    }
                });
            }
        }
예제 #11
0
 public static NestedField <DateTimeFieldProperties> DateTime(long id, string name, DateTimeFieldProperties properties = null)
 {
     return(new NestedField <DateTimeFieldProperties>(id, name, properties ?? new DateTimeFieldProperties()));
 }
예제 #12
0
 public static RootField <DateTimeFieldProperties> DateTime(long id, string name, Partitioning partitioning, DateTimeFieldProperties properties = null)
 {
     return(new RootField <DateTimeFieldProperties>(id, name, partitioning, properties ?? new DateTimeFieldProperties()));
 }
예제 #13
0
 public static ArrayField AddDateTime(this ArrayField field, long id, string name, DateTimeFieldProperties properties = null)
 {
     return(field.AddField(DateTime(id, name, properties)));
 }
예제 #14
0
 public static Schema AddDateTime(this Schema schema, long id, string name, Partitioning partitioning, DateTimeFieldProperties properties = null)
 {
     return(schema.AddField(DateTime(id, name, partitioning, properties)));
 }
예제 #15
0
 public static NestedField <DateTimeFieldProperties> DateTime(long id, string name, DateTimeFieldProperties properties = null, IFieldSettings settings = null)
 {
     return(new NestedField <DateTimeFieldProperties>(id, name, properties, settings));
 }
예제 #16
0
 public static RootField <DateTimeFieldProperties> DateTime(long id, string name, Partitioning partitioning, DateTimeFieldProperties properties = null, IFieldSettings settings = null)
 {
     return(new RootField <DateTimeFieldProperties>(id, name, partitioning, properties, settings));
 }