Ejemplo n.º 1
0
        public void DisplayNameHelpers_ReturnPropertyName()
        {
            // Arrange
            var helper           = DefaultTemplatesUtilities.GetHtmlHelper();
            var enumerableHelper = DefaultTemplatesUtilities.GetHtmlHelperForEnumerable();

            // Act
            var displayNameResult              = helper.DisplayName("Property1");
            var displayNameForResult           = helper.DisplayNameFor(m => m.Property1);
            var displayNameForEnumerableResult = enumerableHelper.DisplayNameFor(m => m.Property1);

            // Assert
            Assert.Equal("Property1", displayNameResult);
            Assert.Equal("Property1", displayNameForResult);
            Assert.Equal("Property1", displayNameForEnumerableResult);
        }
Ejemplo n.º 2
0
        public void DisplayNameHelpers_ReturnPropertyName_ForNestedProperty()
        {
            // Arrange
            var helper           = DefaultTemplatesUtilities.GetHtmlHelper <OuterClass>(model: null);
            var enumerableHelper = DefaultTemplatesUtilities.GetHtmlHelperForEnumerable <OuterClass>(model: null);

            // Act
            var displayNameResult              = helper.DisplayName("Inner.Id");
            var displayNameForResult           = helper.DisplayNameFor(m => m.Inner.Id);
            var displayNameForEnumerableResult = enumerableHelper.DisplayNameFor(m => m.Inner.Id);

            // Assert
            Assert.Equal("Id", displayNameResult);
            Assert.Equal("Id", displayNameForResult);
            Assert.Equal("Id", displayNameForEnumerableResult);
        }
Ejemplo n.º 3
0
        public void DisplayNameHelpers_ReturnDisplayNameForProperty_IfNonNull(string displayName)
        {
            // Arrange
            var provider = new TestModelMetadataProvider();

            provider
            .ForProperty <DefaultTemplatesUtilities.ObjectTemplateModel>("Property1")
            .DisplayDetails(dd => dd.DisplayName = () => displayName);

            var helper           = DefaultTemplatesUtilities.GetHtmlHelper(provider: provider);
            var enumerableHelper = DefaultTemplatesUtilities.GetHtmlHelperForEnumerable(provider: provider);

            // Act
            var displayNameResult              = helper.DisplayName("Property1");
            var displayNameForResult           = helper.DisplayNameFor(m => m.Property1);
            var displayNameForEnumerableResult = enumerableHelper.DisplayNameFor(m => m.Property1);

            // Assert
            Assert.Equal(displayName, displayNameResult);
            Assert.Equal(displayName, displayNameForResult);
            Assert.Equal(displayName, displayNameForEnumerableResult);
        }
Ejemplo n.º 4
0
        public void DisplayNameHelpers_ReturnDisplayName_IfNonNull(string displayName)
        {
            // Arrange
            var provider = new TestModelMetadataProvider();

            provider
            .ForType <DefaultTemplatesUtilities.ObjectTemplateModel>()
            .DisplayDetails(dd => dd.DisplayName = () => displayName);

            var helper           = DefaultTemplatesUtilities.GetHtmlHelper(provider: provider);
            var enumerableHelper = DefaultTemplatesUtilities.GetHtmlHelperForEnumerable(provider: provider);

            // Act
            var displayNameResult              = helper.DisplayName(expression: string.Empty);
            var displayNameForResult           = helper.DisplayNameFor(m => m);
            var displayNameForEnumerableResult = enumerableHelper.DisplayNameFor((DefaultTemplatesUtilities.ObjectTemplateModel m) => m);
            var displayNameForModelResult      = helper.DisplayNameForModel();

            // Assert
            Assert.Equal(displayName, displayNameResult);
            Assert.Equal(displayName, displayNameForResult);
            Assert.Equal(displayName, displayNameForEnumerableResult);
            Assert.Equal(displayName, displayNameForModelResult);
        }