Exemplo n.º 1
0
        public void DropDownListThrowsWithNoName() {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

            // Act and assert
            ExceptionAssert.ThrowsArgNullOrEmpty(() => helper.DropDownList(name: null, selectList: null), "name");
        }
Exemplo n.º 2
0
        public void RadioButtonWithEmptyNameThrows() {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

            // Act and assert
            ExceptionAssert.ThrowsArgNullOrEmpty(() => helper.RadioButton(null, null), "name");
            ExceptionAssert.ThrowsArgNullOrEmpty(() => helper.RadioButton(String.Empty, null), "name");
        }
Exemplo n.º 3
0
        public void ValidationMessageWithNoErrorResultsInNullString() {
            // Arrange
            HtmlHelper htmlHelper = new HtmlHelper(new ModelStateDictionary());

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

            Assert.IsNull(html);
        }
Exemplo n.º 4
0
        public void TextAreaWithDefaultRowsAndCols() {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

            // Act
            var html = helper.TextArea("foo");

            // Assert
            Assert.AreEqual(@"<textarea cols=""20"" id=""foo"" name=""foo"" rows=""2""></textarea>", html.ToHtmlString());
        }
Exemplo n.º 5
0
        public void TextAreaWithEmptyNameThrows() {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

            // Act and assert
            ExceptionAssert.ThrowsArgumentException(() => helper.TextArea(null), "name", "Value cannot be null or an empty string.");

            // Act and assert
            ExceptionAssert.ThrowsArgumentException(() => helper.TextArea(String.Empty), "name", "Value cannot be null or an empty string.");
        }
Exemplo n.º 6
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());
        }
Exemplo n.º 7
0
        public void TextAreaWithNonZeroRowsAndColumns() {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

            // Act
            var html = helper.TextArea("foo", null, 4, 10, null);

            // Assert
            Assert.AreEqual(@"<textarea cols=""10"" id=""foo"" name=""foo"" rows=""4""></textarea>", html.ToHtmlString());
        }
Exemplo n.º 8
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());
        }
Exemplo n.º 9
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());
        }
Exemplo n.º 10
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.");
        }
Exemplo n.º 11
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());
        }
Exemplo n.º 12
0
        public void RadioButtonWithDictionaryAttributes() {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

            // Act
            var html = helper.RadioButton("foo", "bar", new Dictionary<string, object> { { "attr", "attr-value" } });

            // Assert
            Assert.AreEqual(@"<input attr=""attr-value"" id=""foo"" name=""foo"" type=""radio"" value=""bar"" />",
                html.ToHtmlString());
        }
Exemplo n.º 13
0
        public void EncodeStringNull() {
            // Arrange
            HtmlHelper htmlHelper = new HtmlHelper(new ModelStateDictionary());
            string text = null;

            // Act
            string encodedHtml = htmlHelper.Encode(text);

            // Assert
            Assert.AreEqual("", encodedHtml);
        }
Exemplo n.º 14
0
        public void EncodeString() {
            // Arrange
            HtmlHelper htmlHelper = new HtmlHelper(new ModelStateDictionary());
            var text = "<br />";

            // Act
            string encodedHtml = htmlHelper.Encode(text);

            // Assert
            Assert.AreEqual(encodedHtml, "&lt;br /&gt;", "Text is not being properly HTML-encoded.");
        }
Exemplo n.º 15
0
        public void EncodeObjectNull() {
            // Arrange
            HtmlHelper htmlHelper = new HtmlHelper(new ModelStateDictionary());
            object text = null;

            // Act
            string encodedHtml = htmlHelper.Encode(text);

            // Assert
            Assert.AreEqual(String.Empty, encodedHtml);
        }
Exemplo n.º 16
0
        public void TextAreaWithObjectAttributes() {
            // Arrange
            ModelStateDictionary modelState = new ModelStateDictionary();
            modelState.SetModelValue("foo", "foo-value");
            HtmlHelper helper = new HtmlHelper(modelState);

            // Act
            var html = helper.TextArea("foo", new { attr = "value", cols = 6 });

            // Assert
            Assert.AreEqual(@"<textarea attr=""value"" cols=""6"" id=""foo"" name=""foo"" rows=""2"">foo-value</textarea>", html.ToHtmlString());
        }
Exemplo n.º 17
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());
        }
Exemplo n.º 18
0
        public void RadioButtonUsesModelStateToRemoveChecked() {
            // Arrange
            var modelState = new ModelStateDictionary();
            modelState.SetModelValue("foo", "not-a-bar");
            HtmlHelper helper = new HtmlHelper(modelState);

            // Act
            var html = helper.RadioButton("foo", "bar", new { @checked = "checked" } );

            // Assert
            Assert.AreEqual(@"<input id=""foo"" name=""foo"" type=""radio"" value=""bar"" />",
                html.ToHtmlString());
        }
Exemplo n.º 19
0
        public void DropDownListWithAttributes() {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

            // Act
            var html = helper.DropDownList("foo", GetSelectList(), new { attr = "attr-val", attr2 = "attr-val2" });

            // Assert
            Assert.AreEqual(
                @"<select attr=""attr-val"" attr2=""attr-val2"" id=""foo"" name=""foo"">
<option value=""A"">Alpha</option>
<option value=""B"">Bravo</option>
<option value=""C"">Charlie</option>
</select>",
                html.ToHtmlString());
        }
Exemplo n.º 20
0
        public void DropDownListWithExplicitValue() {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

            // Act
            var html = helper.DropDownList("foo", null, GetSelectList(), "B", new Dictionary<string, object>{ {"attr",  "attr-val"} });

            // Assert
            Assert.AreEqual(
                @"<select attr=""attr-val"" id=""foo"" name=""foo"">
<option value=""A"">Alpha</option>
<option selected=""selected"" value=""B"">Bravo</option>
<option value=""C"">Charlie</option>
</select>",
                html.ToHtmlString());
        }
Exemplo n.º 21
0
        public void DropDownListWithNoSelectedItem() {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

            // Act
            var html = helper.DropDownList("foo", GetSelectList());

            // Assert
            Assert.AreEqual(
                @"<select id=""foo"" name=""foo"">
<option value=""A"">Alpha</option>
<option value=""B"">Bravo</option>
<option value=""C"">Charlie</option>
</select>",
                html.ToHtmlString());
        }
Exemplo n.º 22
0
        public void RadioButtonWithDefaultArguments() {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

            // Act
            var html = helper.RadioButton("foo", "bar", true);

            // Assert
            Assert.AreEqual(@"<input checked=""checked"" id=""foo"" name=""foo"" type=""radio"" value=""bar"" />",
                html.ToHtmlString());

            html = helper.RadioButton("foo", "bar", false);

            // Assert
            Assert.AreEqual(@"<input id=""foo"" name=""foo"" type=""radio"" value=""bar"" />",
                html.ToHtmlString());
        }
Exemplo n.º 23
0
        public void TextAreaWithDictionaryAttributes() {
            // Arrange
            ModelStateDictionary modelState = new ModelStateDictionary();
            modelState.SetModelValue("foo", "explicit-foo-value");
            HtmlHelper helper = new HtmlHelper(modelState);
            var attributes = new Dictionary<string, object>() { { "attr", "attr-val" }, { "rows", 15 }, { "cols", 12 } };
            // Act
            var html = helper.TextArea("foo", attributes);

            // Assert
            Assert.AreEqual(@"<textarea attr=""attr-val"" cols=""12"" id=""foo"" name=""foo"" rows=""15"">explicit-foo-value</textarea>", 
                html.ToHtmlString());
        }
Exemplo n.º 24
0
        public void ListBoxWithObjectDictionaryAndTitle() {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

            // Act
            var html = helper.ListBox("foo", "Select One", GetSelectList(), new { @class = "my-class" });

            // Assert
            Assert.AreEqual(
                @"<select class=""my-class"" id=""foo"" name=""foo"">
<option value="""">Select One</option>
<option value=""A"">Alpha</option>
<option value=""B"">Bravo</option>
<option value=""C"">Charlie</option>
</select>",
                html.ToHtmlString());
        }
Exemplo n.º 25
0
        public void ListBoxWithEmptyOptionLabel() {
            // Arrange
            var modelState = new ModelStateDictionary();
            modelState.AddError("foo", "some error");
            HtmlHelper helper = new HtmlHelper(modelState);

            // Act
            var html = helper.ListBox("foo", GetSelectList(), new { @class = "my-class" });

            // Assert
            Assert.AreEqual(
                @"<select class=""field-validation-error my-class"" id=""foo"" name=""foo"">
<option value=""A"">Alpha</option>
<option value=""B"">Bravo</option>
<option value=""C"">Charlie</option>
</select>",
                html.ToHtmlString());
        }
Exemplo n.º 26
0
        public void ListBoxWithDotReplacementForId() {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

            // Act
            var html = helper.ListBox("foo.bar", "Select One", GetSelectList());

            // Assert
            Assert.AreEqual(
                @"<select id=""foo_bar"" name=""foo.bar"">
<option value="""">Select One</option>
<option value=""A"">Alpha</option>
<option value=""B"">Bravo</option>
<option value=""C"">Charlie</option>
</select>",
                html.ToHtmlString());
        }
Exemplo n.º 27
0
        // [TestMethod]
        // Cant test this in multi-threaded
        public void TextAreaWithCustomErrorClass() {
            // Arrange
            ModelStateDictionary modelState = new ModelStateDictionary();
            modelState.AddError("foo", "some error");
            HtmlHelper.ValidationInputCssClassName = "custom-field-validation-error";
            HtmlHelper helper = new HtmlHelper(modelState);

            // Act
            var html = helper.TextArea("foo", String.Empty, new { @class = "my-css" });

            // Assert
            Assert.AreEqual(@"<textarea class=""custom-field-validation-error my-css"" cols=""20"" id=""foo"" name=""foo"" rows=""2""></textarea>",
                html.ToHtmlString());
        }
Exemplo n.º 28
0
        public void TextAreaWithError() {
            // Arrange
            ModelStateDictionary modelState = new ModelStateDictionary();
            modelState.AddError("foo", "some error");
            HtmlHelper helper = new HtmlHelper(modelState);

            // Act
            var html = helper.TextArea("foo", String.Empty);

            // Assert
            Assert.AreEqual(@"<textarea class=""field-validation-error"" cols=""20"" id=""foo"" name=""foo"" rows=""2""></textarea>",
                html.ToHtmlString());
        }
Exemplo n.º 29
0
        public void TextAreaWithNoValueAndObjectAttributes() {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());
            var attributes = new Dictionary<string, object>() { { "attr", "attr-val" }, { "rows", 15 }, { "cols", 12 } };
            // Act
            var html = helper.TextArea("foo", attributes);

            // Assert
            Assert.AreEqual(@"<textarea attr=""attr-val"" cols=""12"" id=""foo"" name=""foo"" rows=""15""></textarea>",
                html.ToHtmlString());
        }
Exemplo n.º 30
0
        public void DropDownWithModelValue() {
            // Arrange
            var modelState = new ModelStateDictionary();
            modelState.SetModelValue("foo", "C");
            HtmlHelper helper = new HtmlHelper(modelState);

            // Act
            var html = helper.DropDownList("foo", GetSelectList(), new { attr = "attr-val" } );

            // Assert
            Assert.AreEqual(
                @"<select attr=""attr-val"" id=""foo"" name=""foo"">
<option value=""A"">Alpha</option>
<option value=""B"">Bravo</option>
<option selected=""selected"" value=""C"">Charlie</option>
</select>",
                html.ToHtmlString());
        }