Example #1
0
        public void AdditinalSettings_should_be_overwritten()
        {
            // arrange
            var to       = new ModelMetadataItem();
            var settings = new DummyAdditinalSettings {
                Name = "val"
            };

            to.AdditionalSettings.Add(settings);

            var from      = new ModelMetadataItem();
            var settings2 = new DummyAdditinalSettings {
                Name = "val2"
            };

            from.AdditionalSettings.Add(settings2);

            // act
            from.MergeTo(to);

            // assert
            var item = to.GetAdditionalSetting <DummyAdditinalSettings>();

            Assert.NotNull(item);
            Assert.Equal("val", item.Name);
        }
Example #2
0
        public void Should_overwrite_values_that_were_not_set()
        {
            // assert
            var properties = GetMetadataProperties();

            var to   = new ModelMetadataItem();
            var from = new ModelMetadataItem();

            Func <string> funcFrom = () => "valueFrom";

            foreach (var propertyInfo in properties)
            {
                if (propertyInfo.PropertyType == typeof(bool) || propertyInfo.PropertyType == typeof(bool?))
                {
                    propertyInfo.SetValue(from, true, null);
                }
                else if (propertyInfo.PropertyType == typeof(int) || propertyInfo.PropertyType == typeof(int?))
                {
                    propertyInfo.SetValue(from, 10, null);
                }
                else if (propertyInfo.PropertyType == typeof(string))
                {
                    propertyInfo.SetValue(from, funcFrom(), null);
                }
                else if (propertyInfo.PropertyType == typeof(Func <string>))
                {
                    propertyInfo.SetValue(from, funcFrom, null);
                }
            }

            // act
            from.MergeTo(to);

            // assert
            foreach (var propertyInfo in properties)
            {
                Console.WriteLine(propertyInfo.Name);
                if (propertyInfo.PropertyType == typeof(bool) || propertyInfo.PropertyType == typeof(bool?))
                {
                    Assert.True((bool)propertyInfo.GetValue(to, null));
                }
                else if (propertyInfo.PropertyType == typeof(int) || propertyInfo.PropertyType == typeof(int?))
                {
                    Assert.Equal(10, (int)propertyInfo.GetValue(to, null));
                }
                else if (propertyInfo.PropertyType == typeof(string))
                {
                    var value = (string)propertyInfo.GetValue(to, null);
                    Assert.True(value == "valueFrom");
                }
                else if (propertyInfo.PropertyType == typeof(Func <string>))
                {
                    var value = (Func <string>)propertyInfo.GetValue(to, null);
                    Assert.True(value() == "valueFrom");
                }
            }
        }
Example #3
0
        public void ShowForDisplay_should_not_be_overwritten_if_it_was_set_to_false()
        {
            // arrange
            var to = new ModelMetadataItem {
                ShowForDisplay = false
            };
            var from = new ModelMetadataItem {
                ShowForDisplay = true
            };

            // act
            from.MergeTo(to);

            // assert
            Assert.False(to.ShowForDisplay);
        }
Example #4
0
        public void ApplyFormatInEditMode_should_not_be_overwritten_if_it_was_set_to_true()
        {
            // arrange
            var to = new ModelMetadataItem {
                ApplyFormatInEditMode = true
            };
            var from = new ModelMetadataItem {
                ApplyFormatInEditMode = false
            };

            // act
            from.MergeTo(to);

            // assert
            Assert.True(to.ApplyFormatInEditMode);
        }
Example #5
0
        public void RequiredMetadata_should_not_removed()
        {
            // arrange
            var to = new ModelMetadataItem();

            new ModelMetadataItemBuilder <string>(to).Required();

            var from = new ModelMetadataItem();

            // act
            from.MergeTo(to);

            // assert
            Assert.NotNull(to.IsRequired);
            Assert.True(to.IsRequired.Value);
            Assert.NotNull(to.GetValidation <RequiredValidationMetadata>());
        }
Example #6
0
        public void RequiredMetadata_should_set_if_it_was_added_for_from_metadata()
        {
            // arrange
            var to = new ModelMetadataItem();

            var from = new ModelMetadataItem();

            new ModelMetadataItemBuilder <string>(from).Required();

            // act
            from.MergeTo(to);

            // assert
            Assert.NotNull(to.IsRequired);
            Assert.True(to.IsRequired.Value);
            Assert.NotNull(to.GetValidation <RequiredValidationMetadata>());
        }
        public void AdditinalSettings_should_set_if_it_was_added_for_from_metadata()
        {
            // arrange
            var to = new ModelMetadataItem();

            var from = new ModelMetadataItem();
            var settings = new DummyAdditinalSettings { Name = "val2" };
            from.AdditionalSettings.Add(settings);

            // act
            from.MergeTo(to);

            // assert
            var item = to.GetAdditionalSetting<DummyAdditinalSettings>();
            Assert.NotNull(item);
            Assert.Equal("val2", item.Name);
        }
        public void AdditinalSettings_should_not_removed()
        {
            // arrange
            var to = new ModelMetadataItem();
            var settings = new DummyAdditinalSettings { Name = "val" };
            to.AdditionalSettings.Add(settings);

            var from = new ModelMetadataItem();

            // act
            from.MergeTo(to);

            // assert
            var item = to.GetAdditionalSetting<DummyAdditinalSettings>();
            Assert.NotNull(item);
            Assert.Equal("val", item.Name);
        }
Example #9
0
        public void Validation_should_set_if_it_was_added_for_from_metadata()
        {
            // arrange
            var to = new ModelMetadataItem();

            var from = new ModelMetadataItem();

            new ModelMetadataItemBuilder <string>(from).MaximumLength(50);

            // act
            from.MergeTo(to);

            // assert
            var item = to.GetValidation <StringLengthValidationMetadata>();

            Assert.NotNull(item);
            Assert.Equal(50, item.Maximum);
        }
Example #10
0
        public void Validation_should_not_removed()
        {
            // arrange
            var to = new ModelMetadataItem();

            new ModelMetadataItemBuilder <string>(to).MaximumLength(50);

            var from = new ModelMetadataItem();

            // act
            from.MergeTo(to);

            // assert
            var item = to.GetValidation <StringLengthValidationMetadata>();

            Assert.NotNull(item);
            Assert.Equal(50, item.Maximum);
        }
Example #11
0
        public void AdditinalSettings_should_set_if_it_was_added_for_from_metadata()
        {
            // arrange
            var to = new ModelMetadataItem();

            var from     = new ModelMetadataItem();
            var settings = new DummyAdditinalSettings {
                Name = "val2"
            };

            from.AdditionalSettings.Add(settings);

            // act
            from.MergeTo(to);

            // assert
            var item = to.GetAdditionalSetting <DummyAdditinalSettings>();

            Assert.NotNull(item);
            Assert.Equal("val2", item.Name);
        }
        public void RequiredMetadata_should_not_removed()
        {
            // arrange
            var to = new ModelMetadataItem();
            new ModelMetadataItemBuilder<string>(to).Required();

            var from = new ModelMetadataItem();

            // act
            from.MergeTo(to);

            // assert
            Assert.NotNull(to.IsRequired);
            Assert.True(to.IsRequired.Value);
            Assert.NotNull(to.GetValidation<RequiredValidationMetadata>());
        }
        public void Should_overwrite_values_that_were_not_set()
        {
            // assert
            var properties = GetMetadataProperties();

            var to = new ModelMetadataItem();
            var from = new ModelMetadataItem();

            Func<string> funcFrom = () => "valueFrom";

            foreach (var propertyInfo in properties)
            {
                if (propertyInfo.PropertyType == typeof(bool) || propertyInfo.PropertyType == typeof(bool?))
                {
                    propertyInfo.SetValue(from, true, null);
                }
                else if (propertyInfo.PropertyType == typeof(int) || propertyInfo.PropertyType == typeof(int?))
                {
                    propertyInfo.SetValue(from, 10, null);
                }
                else if (propertyInfo.PropertyType == typeof(string))
                {
                    propertyInfo.SetValue(from, funcFrom(), null);
                }
                else if (propertyInfo.PropertyType == typeof(Func<string>))
                {
                    propertyInfo.SetValue(from, funcFrom, null);
                }
            }

            // act
            from.MergeTo(to);

            // assert
            foreach (var propertyInfo in properties)
            {
                Console.WriteLine(propertyInfo.Name);
                if (propertyInfo.PropertyType == typeof(bool) || propertyInfo.PropertyType == typeof(bool?))
                {
                    Assert.True((bool)propertyInfo.GetValue(to, null));
                }
                else if (propertyInfo.PropertyType == typeof(int) || propertyInfo.PropertyType == typeof(int?))
                {
                    Assert.Equal(10, (int)propertyInfo.GetValue(to, null));
                }
                else if (propertyInfo.PropertyType == typeof(string))
                {
                    var value = (string)propertyInfo.GetValue(to, null);
                    Assert.True(value == "valueFrom");
                }
                else if (propertyInfo.PropertyType == typeof(Func<string>))
                {
                    var value = (Func<string>)propertyInfo.GetValue(to, null);
                    Assert.True(value() == "valueFrom");
                }
            }
        }
        public void ShowForDisplay_should_not_be_overwritten_if_it_was_set_to_false()
        {
            // arrange
            var to = new ModelMetadataItem { ShowForDisplay = false };
            var from = new ModelMetadataItem { ShowForDisplay = true };

            // act
            from.MergeTo(to);

            // assert
            Assert.False(to.ShowForDisplay);
        }
        public void Validation_should_not_removed()
        {
            // arrange
            var to = new ModelMetadataItem();
            new ModelMetadataItemBuilder<string>(to).MaximumLength(50);

            var from = new ModelMetadataItem();

            // act
            from.MergeTo(to);

            // assert
            var item = to.GetValidation<StringLengthValidationMetadata>();
            Assert.NotNull(item);
            Assert.Equal(50, item.Maximum);
        }
        public void RequiredMetadata_should_set_if_it_was_added_for_from_metadata()
        {
            // arrange
            var to = new ModelMetadataItem();

            var from = new ModelMetadataItem();
            new ModelMetadataItemBuilder<string>(from).Required();

            // act
            from.MergeTo(to);

            // assert
            Assert.NotNull(to.IsRequired);
            Assert.True(to.IsRequired.Value);
            Assert.NotNull(to.GetValidation<RequiredValidationMetadata>());
        }
        public void ApplyFormatInEditMode_should_be_overwritten_if_it_was_set_to_false()
        {
            // arrange
            var to = new ModelMetadataItem { ApplyFormatInEditMode = false };
            var from = new ModelMetadataItem { ApplyFormatInEditMode = true };

            // act
            from.MergeTo(to);

            // assert
            Assert.True(to.ApplyFormatInEditMode);
        }
        public void Validation_should_set_if_it_was_added_for_from_metadata()
        {
            // arrange
            var to = new ModelMetadataItem();

            var from = new ModelMetadataItem();
            new ModelMetadataItemBuilder<string>(from).MaximumLength(50);

            // act
            from.MergeTo(to);

            // assert
            var item = to.GetValidation<StringLengthValidationMetadata>();
            Assert.NotNull(item);
            Assert.Equal(50, item.Maximum);
        }