Ejemplo n.º 1
0
        public void ValidationMessageWithNoErrorResultsInNullString() {
            // Arrange
            HtmlHelper htmlHelper = new HtmlHelper(new ModelStateDictionary());

            // Act
            var html = htmlHelper.ValidationMessage("does-not-exist");

            Assert.IsNull(html);
        }
Ejemplo n.º 2
0
        public void ValidationMessageReturnsWithCustomMessage() {
            // Arrange
            HtmlHelper htmlHelper = new HtmlHelper(GetModelStateWithErrors());

            // Atc
            var html = htmlHelper.ValidationMessage("foo", "bar error");

            // Assert
            Assert.AreEqual(@"<span class=""field-validation-error"">bar error</span>", html.ToHtmlString());
        }
Ejemplo n.º 3
0
        public void ValidationMessageReturnsWithObjectAttributes() {
            // Arrange
            HtmlHelper htmlHelper = new HtmlHelper(GetModelStateWithErrors());

            // Act
            var html = htmlHelper.ValidationMessage("foo", new { attr = "attr-value" });

            // Assert
            Assert.AreEqual(@"<span attr=""attr-value"" class=""field-validation-error"">foo error &lt;1&gt;</span>", html.ToHtmlString());
        }
Ejemplo n.º 4
0
        public void ValidationMessageReturnsNullForInvalidName() {
            // Arrange
            HtmlHelper htmlHelper = new HtmlHelper(GetModelStateWithErrors());

            // Act
            var html = htmlHelper.ValidationMessage("baz");

            // Assert
            Assert.IsNull(html, "html should be null if name is invalid.");
        }
Ejemplo n.º 5
0
        public void ValidationMessageReturnsFirstError() {
            // Arrange
            HtmlHelper htmlHelper = new HtmlHelper(GetModelStateWithErrors());

            // Act 
            var html = htmlHelper.ValidationMessage("foo");

            // Assert
            Assert.AreEqual(@"<span class=""field-validation-error"">foo error &lt;1&gt;</span>", html.ToHtmlString());
        }
Ejemplo n.º 6
0
        public void ValidationMessageAllowsEmptyModelName() {
            // Arrange
            ModelStateDictionary dictionary = new ModelStateDictionary();
            dictionary.AddError("test", "some error text");
            HtmlHelper htmlHelper = new HtmlHelper(dictionary);

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

            // Assert
            Assert.AreEqual(@"<span class=""field-validation-error"">some error text</span>", html.ToHtmlString());
        }
Ejemplo n.º 7
0
        public void ValidationMessageWithModelStateAndNoErrors() {
            // Arrange
            HtmlHelper htmlHelper = new HtmlHelper(GetModelStateWithErrors());

            // Act
            var html = htmlHelper.ValidationMessage("baz");

            // Assert
            Assert.IsNull(html, "html should be null if there are no errors");
        }
Ejemplo n.º 8
0
        public void ValidationMessageReturnsWithCustomMessageAndObjectAttributes() {
            // Arrange
            HtmlHelper htmlHelper = new HtmlHelper(GetModelStateWithErrors());

            // Act
            var html = htmlHelper.ValidationMessage("foo", "bar error", new { baz = "baz" });

            // Assert
            Assert.AreEqual(@"<span baz=""baz"" class=""field-validation-error"">bar error</span>", html.ToHtmlString());
        }