コード例 #1
0
        public void ValidationSummaryWithMultipleFormErrorsAndExcludedFieldErrors() {
            // Arrange
            ModelStateDictionary modelState = new ModelStateDictionary();
            modelState.AddFormError("error <1>");
            modelState.AddFormError("error <2>");

            HtmlHelper htmlHelper = new HtmlHelper(modelState);

            // Act
            var html = htmlHelper.ValidationSummary(excludeFieldErrors: true);

            // Assert
            Assert.AreEqual(@"<div class=""validation-summary-errors""><ul>
<li>error &lt;1&gt;</li>
<li>error &lt;2&gt;</li>
</ul></div>"
                , html.ToHtmlString());
        }
コード例 #2
0
        public void ValidationSummaryWithNoErrorReturnsNull() {
            // Arrange
            HtmlHelper htmlHelper = new HtmlHelper(new ModelStateDictionary());

            // Act
            var html = htmlHelper.ValidationSummary();

            // Assert
            Assert.IsNull(html);
        }
コード例 #3
0
        public void ValidationSummaryWithNoFormErrorsAndExcludedFieldErrorsReturnsNull() {
            // Arrange
            ModelStateDictionary modelState = new ModelStateDictionary();
            modelState.AddError("foo", "error");
            modelState.AddError("bar", "error");

            HtmlHelper htmlHelper = new HtmlHelper(modelState);

            // Act
            var html = htmlHelper.ValidationSummary(excludeFieldErrors: true);

            // Assert
            Assert.IsNull(html);
        }
コード例 #4
0
        //[TestMethod]
        // Cant test this, as it sets a static property 
        public void ValidationSummaryWithCustomValidationSummaryClass() {
            // Arrange
            HtmlHelper.ValidationSummaryClass = "my-val-class";
            HtmlHelper htmlHelper = new HtmlHelper(GetModelStateWithErrors());

            // Act
            var html = htmlHelper.ValidationSummary("This is a message.", new Dictionary<string, object> { { "attr", "attr-value" }, { "class", "my-class" } });

            // Assert
            Assert.AreEqual(@"<div attr=""attr-value"" class=""my-val-class my-class""><span>This is a message.</span>
<ul>
<li>foo error &lt;1&gt;</li>
<li>foo error &lt;2&gt;</li>
<li>bar error &lt;1&gt;</li>
<li>bar error &lt;2&gt;</li>
</ul></div>"
                , html.ToHtmlString());
        }
コード例 #5
0
        public void ValidationSummaryWithDictionary() {
            // Arrange
            HtmlHelper htmlHelper = new HtmlHelper(GetModelStateWithErrors());

            // Act
            var html = htmlHelper.ValidationSummary(new Dictionary<string, object> 
                { { "attr", "attr-value"} , { "class", "my-class" }} );

            // Assert
            Assert.AreEqual(@"<div attr=""attr-value"" class=""validation-summary-errors my-class""><ul>
<li>foo error &lt;1&gt;</li>
<li>foo error &lt;2&gt;</li>
<li>bar error &lt;1&gt;</li>
<li>bar error &lt;2&gt;</li>
</ul></div>"
                , html.ToHtmlString());
        }
コード例 #6
0
        public void ValidationSummaryWithObjectProperties() {
            // Arrange
            HtmlHelper htmlHelper = new HtmlHelper(GetModelStateWithErrors());

            // Act
            var html = htmlHelper.ValidationSummary(new { attr = "attr-value", @class = "my-class" });

            // Assert
            Assert.AreEqual(@"<div attr=""attr-value"" class=""validation-summary-errors my-class""><ul>
<li>foo error &lt;1&gt;</li>
<li>foo error &lt;2&gt;</li>
<li>bar error &lt;1&gt;</li>
<li>bar error &lt;2&gt;</li>
</ul></div>"
                , html.ToHtmlString());
        }
コード例 #7
0
        public void ValidationSummaryWithFormErrorsAndExcludeFieldErrors() {
            // Arrange
            HtmlHelper htmlHelper = new HtmlHelper(GetModelStateWithFormErrors());

            // Act
            var html = htmlHelper.ValidationSummary(excludeFieldErrors: true);

            // Assert
            Assert.AreEqual(@"<div class=""validation-summary-errors""><ul>
<li>some form error &lt;1&gt;</li>
<li>some form error &lt;2&gt;</li>
</ul></div>"
                , html.ToHtmlString());
        }
コード例 #8
0
        public void ValidationSummaryWithMessage() {
            // Arrange
            HtmlHelper htmlHelper = new HtmlHelper(GetModelStateWithErrors());

            // Act
            var html = htmlHelper.ValidationSummary("test message");

            // Assert
            Assert.AreEqual(@"<div class=""validation-summary-errors""><span>test message</span>
<ul>
<li>foo error &lt;1&gt;</li>
<li>foo error &lt;2&gt;</li>
<li>bar error &lt;1&gt;</li>
<li>bar error &lt;2&gt;</li>
</ul></div>"
                , html.ToHtmlString());
        }