Exemplo n.º 1
0
        public void Should_be_able_to_set_display_format()
        {
            builder.DisplayFormat("{0:d}");

            var configurator = (IModelMetadataItemConfigurator)builder;
            var item = new ModelMetadataItem();
            configurator.Configure(item);
            Assert.Equal("{0:d}", item.DisplayFormat());
        }
        public void Should_be_able_to_set_display_format()
        {
            builder.DisplayFormat("{0:d}");

            var configurator = (IModelMetadataItemConfigurator)builder;
            var item         = new ModelMetadataItem();

            configurator.Configure(item);
            Assert.Equal("{0:d}", item.DisplayFormat());
        }
Exemplo n.º 3
0
        public void Should_be_able_to_format_as_time_with_nullable_date_time()
        {
            var item    = new ModelMetadataItem();
            var builder = new ModelMetadataItemBuilder <DateTime?>(item);

            builder.FormatAsTimeOnly();

            Assert.Equal(item.DisplayFormat(), "{0:t}");
            Assert.Equal(item.EditFormat(), "{0:t}");
        }
Exemplo n.º 4
0
        public void Should_be_able_to_format_as_currency_with_nullable_decimal()
        {
            var item    = new ModelMetadataItem();
            var builder = new ModelMetadataItemBuilder <decimal?>(item);

            builder.FormatAsCurrency();

            Assert.Equal(item.DisplayFormat(), "{0:c}");
            Assert.Equal(item.EditFormat(), "{0:c}");
        }
        public void Should_be_able_to_format_as_time_with_date_time()
        {
            var item = new ModelMetadataItem();
            var builder = new ModelMetadataItemBuilder<DateTime>(item);

            builder.FormatAsTimeOnly();

            Assert.Equal(item.DisplayFormat(), "{0:t}");
            Assert.Equal(item.EditFormat(), "{0:t}");
        }
        public void Should_be_able_to_format_as_currency_with_nullable_decimal()
        {
            var item = new ModelMetadataItem();
            var builder = new ModelMetadataItemBuilder<decimal?>(item);

            builder.FormatAsCurrency();

            Assert.Equal(item.DisplayFormat(), "{0:c}");
            Assert.Equal(item.EditFormat(), "{0:c}");
        }
        public void Should_be_able_to_set_display_format()
        {
            builder.DisplayFormat("{0:d}");

            Assert.Equal("{0:d}", item.DisplayFormat());
        }
        public void Should_return_metadata_with_same_value_as_model_meta_data_item(bool hideSurroundingHtml, bool isReadOnly, bool isRequired, bool showForEdit, bool applyFormatInEditMode, string displayName, string shortDisplayName, string template, string description, string nullDisplayText, string watermark, string displayFormat, string editFormat)
        {
            var metadataItem = new ModelMetadataItem {
                HideSurroundingHtml = hideSurroundingHtml, IsReadOnly = isReadOnly, IsRequired = isRequired, ShowForEdit = showForEdit, ApplyFormatInEditMode = applyFormatInEditMode, TemplateName = template
            };

            if (displayName != null)
            {
                metadataItem.DisplayName = () => displayName;
            }

            if (shortDisplayName != null)
            {
                metadataItem.ShortDisplayName = () => shortDisplayName;
            }

            if (description != null)
            {
                metadataItem.Description = () => description;
            }

            if (nullDisplayText != null)
            {
                metadataItem.NullDisplayText = () => nullDisplayText;
            }

            if (watermark != null)
            {
                metadataItem.Watermark = () => watermark;
            }

            if (displayFormat != null)
            {
                metadataItem.DisplayFormat = () => displayFormat;
            }

            if (editFormat != null)
            {
                metadataItem.EditFormat = () => editFormat;
            }

            registry.Setup(r => r.GetModelPropertyMetadata(It.IsAny <Type>(), It.IsAny <string>())).Returns(metadataItem);

            var metadata = provider.GetMetadataForProperty(() => new DummyObject(), typeof(DummyObject), "Property1");

            Assert.Equal(metadataItem.HideSurroundingHtml, metadata.HideSurroundingHtml);
            Assert.Equal(metadataItem.IsReadOnly, metadata.IsReadOnly);
            Assert.Equal(metadataItem.IsRequired, metadata.IsRequired);
            Assert.Equal(metadataItem.ShowForEdit, metadata.ShowForEdit);

            if (displayName != null)
            {
                Assert.Equal(metadataItem.DisplayName(), metadata.DisplayName);
            }

            if (shortDisplayName != null)
            {
                Assert.Equal(metadataItem.ShortDisplayName(), metadata.ShortDisplayName);
            }

            Assert.Equal(metadataItem.TemplateName, metadata.TemplateHint);

            if (description != null)
            {
                Assert.Equal(metadataItem.Description(), metadata.Description);
            }

            if (nullDisplayText != null)
            {
                Assert.Equal(metadataItem.NullDisplayText(), metadata.NullDisplayText);
            }

            if (watermark != null)
            {
                Assert.Equal(metadataItem.Watermark(), metadata.Watermark);
            }

            if (displayFormat != null)
            {
                Assert.Equal(metadataItem.DisplayFormat(), metadata.DisplayFormatString);
            }

            if (editFormat != null)
            {
                Assert.Equal(metadataItem.EditFormat(), metadata.EditFormatString);
            }
        }
        public void Should_return_metadata_with_same_value_as_model_meta_data_item(bool hideSurroundingHtml, bool isReadOnly, bool isRequired, bool showForEdit, bool applyFormatInEditMode, string displayName, string shortDisplayName, string template, string description, string nullDisplayText, string watermark, string displayFormat, string editFormat)
        {
            var metadataItem = new ModelMetadataItem { HideSurroundingHtml = hideSurroundingHtml, IsReadOnly = isReadOnly, IsRequired = isRequired, ShowForEdit = showForEdit, ApplyFormatInEditMode = applyFormatInEditMode, TemplateName = template };

            if (displayName != null)
            {
                metadataItem.DisplayName = () => displayName;
            }

            if (shortDisplayName != null)
            {
                metadataItem.ShortDisplayName = () => shortDisplayName;
            }

            if (description != null)
            {
                metadataItem.Description = () => description;
            }

            if (nullDisplayText != null)
            {
                metadataItem.NullDisplayText = () => nullDisplayText;
            }

            if (watermark != null)
            {
                metadataItem.Watermark = () => watermark;
            }

            if (displayFormat != null)
            {
                metadataItem.DisplayFormat = () => displayFormat;
            }

            if (editFormat != null)
            {
                metadataItem.EditFormat = () => editFormat;
            }

            registry.Setup(r => r.GetModelPropertyMetadata(It.IsAny<Type>(), It.IsAny<string>())).Returns(metadataItem);

            var metadata = provider.GetMetadataForProperty(() => new DummyObject(), typeof(DummyObject), "Property1");

            Assert.Equal(metadataItem.HideSurroundingHtml, metadata.HideSurroundingHtml);
            Assert.Equal(metadataItem.IsReadOnly, metadata.IsReadOnly);
            Assert.Equal(metadataItem.IsRequired, metadata.IsRequired);
            Assert.Equal(metadataItem.ShowForEdit, metadata.ShowForEdit);

            if (displayName != null)
            {
                Assert.Equal(metadataItem.DisplayName(), metadata.DisplayName);
            }

            if (shortDisplayName != null)
            {
                Assert.Equal(metadataItem.ShortDisplayName(), metadata.ShortDisplayName);
            }

            Assert.Equal(metadataItem.TemplateName, metadata.TemplateHint);

            if (description != null)
            {
                Assert.Equal(metadataItem.Description(), metadata.Description);
            }

            if (nullDisplayText != null)
            {
                Assert.Equal(metadataItem.NullDisplayText(), metadata.NullDisplayText);
            }

            if (watermark != null)
            {
                Assert.Equal(metadataItem.Watermark(), metadata.Watermark);
            }

            if (displayFormat != null)
            {
                Assert.Equal(metadataItem.DisplayFormat(), metadata.DisplayFormatString);
            }

            if (editFormat != null)
            {
                Assert.Equal(metadataItem.EditFormat(), metadata.EditFormatString);
            }
        }