Exemple #1
0
        public void MergeHtmlAttributes_FromHtmlHelper()
        {
            // Arrange
            var attributes   = new { key1 = "abc" };
            var overrides    = new { key2 = "xyz" };
            var attrViewData = new ViewDataDictionary <TestModel>(_metadataProvider, _modelState);
            var overViewData = new ViewDataDictionary <TestModel>(_metadataProvider, _modelState);
            var attrHtml     = new Mock <IHtmlHelper>(MockBehavior.Strict);
            var overHtml     = new Mock <IHtmlHelper>(MockBehavior.Strict);

            var expected = new Dictionary <string, object>
            {
                { "key1", "abc" },
                { "key2", "xyz" }
            };

            attrViewData["htmlAttributes"] = attributes;
            overViewData["htmlAttributes"] = overrides;

            attrHtml.Setup(m => m.ViewData).Returns(attrViewData).Verifiable();
            overHtml.Setup(m => m.ViewData).Returns(overViewData).Verifiable();

            // Act
            var result = HtmlAttributesUtilities.MergeHtmlAttributes(attrHtml.Object, overHtml.Object);

            // Assert
            result.Should().BeEquivalentTo(expected);
            attrHtml.Verify();
            overHtml.Verify();
        }
Exemple #2
0
        public void MergeHtmlAttributes_FromNull()
        {
            // Arrange
            var expected = new Dictionary <string, object>();

            // Act
            var result = HtmlAttributesUtilities.MergeHtmlAttributes(null, null);

            // Assert
            result.Should().BeEquivalentTo(expected);
        }
Exemple #3
0
        public void MergeHtmlAttributes(
            object attributes,
            object overrides,
            IDictionary <string, object> expected)
        {
            // Arrange

            // Act
            var result = HtmlAttributesUtilities.MergeHtmlAttributes(attributes, overrides);

            // Assert
            result.Should().BeEquivalentTo(expected);
        }
Exemple #4
0
        public void MergeHtmlAttributes_FromViewData()
        {
            // Arrange
            var attributes   = new { key1 = "abc" };
            var overrides    = new { key2 = "xyz" };
            var attrViewData = new ViewDataDictionary <TestModel>(_metadataProvider, _modelState);
            var overViewData = new ViewDataDictionary <TestModel>(_metadataProvider, _modelState);
            var expected     = new Dictionary <string, object>
            {
                { "key1", "abc" },
                { "key2", "xyz" }
            };

            attrViewData["htmlAttributes"] = attributes;
            overViewData["htmlAttributes"] = overrides;

            // Act
            var result = HtmlAttributesUtilities.MergeHtmlAttributes(attrViewData, overViewData);

            // Assert
            result.Should().BeEquivalentTo(expected);
        }