Beispiel #1
0
        public void CheckboxWithEmptyNameThrows() {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

            // Act and assert
            ExceptionAssert.ThrowsArgNullOrEmpty(() => helper.CheckBox(null), "name");
            ExceptionAssert.ThrowsArgNullOrEmpty(() => helper.CheckBox(String.Empty), "name");
        }
Beispiel #2
0
        public void CheckboxWithExplicitChecked() {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

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

            // Assert
            Assert.AreEqual(@"<input checked=""checked"" id=""foo"" name=""foo"" type=""checkbox"" />",
                html.ToHtmlString());
        }
Beispiel #3
0
        public void CheckboxWithDictionaryAttributes() {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

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

            // Assert
            Assert.AreEqual(@"<input attr=""attr-value"" id=""foo"" name=""foo"" type=""checkbox"" />",
                html.ToHtmlString());
        }
Beispiel #4
0
        public void CheckboxWithDefaultArguments() {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

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

            // Assert
            Assert.AreEqual(@"<input id=""foo"" name=""foo"" type=""checkbox"" />",
                html.ToHtmlString());
        }
Beispiel #5
0
        public void CheckboxWithModelValue() {
            // Arrange
            var modelState = new ModelStateDictionary();
            modelState.SetModelValue("foo", true);
            HtmlHelper helper = new HtmlHelper(modelState);

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

            // Assert
            Assert.AreEqual(@"<input checked=""checked"" id=""foo"" name=""foo"" type=""checkbox"" />",
                html.ToHtmlString());
        }
Beispiel #6
0
        public void CheckboxWithNonBooleanModelValue() {
            // Arrange
            var modelState = new ModelStateDictionary();
            modelState.SetModelValue("foo", Boolean.TrueString);
            HtmlHelper helper = new HtmlHelper(modelState);

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

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


            modelState.SetModelValue("foo", new object());
            helper = new HtmlHelper(modelState);

            // Act and Assert
            ExceptionAssert.Throws<InvalidOperationException>(() => helper.CheckBox("foo"), 
                "The parameter conversion from type \"System.Object\" to type \"System.Boolean\" failed because no " +
                "type converter can convert between these types.");
        }
Beispiel #7
0
        public void CheckBoxOverwritesImplicitAttributes() {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

            // Act
            var html = helper.CheckBox("foo", true, new { type = "fooType", name = "bar" });

            // Assert
            Assert.AreEqual(@"<input checked=""checked"" id=""foo"" name=""foo"" type=""fooType"" />",
                html.ToHtmlString());
        }
Beispiel #8
0
        //[TestMethod]
        // Can't test as it sets a static property
        // Review: Need to redo test once we fix set once property
        public void CheckBoxUsesCustomErrorClass() {
            // Arrange
            var modelState = new ModelStateDictionary();
            modelState.AddError("foo", "error");
            HtmlHelper.ValidationInputCssClassName = "my-error-class";
            HtmlHelper helper = new HtmlHelper(modelState);

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

            // Assert
            Assert.AreEqual(@"<input checked=""checked"" class=""my-error-class my-class"" id=""foo"" name=""foo"" type=""checkbox"" />",
                html.ToHtmlString());
        }
Beispiel #9
0
        public void CheckBoxWithModelStateCheckedOverwritesHtmlAttribute() {
            // Arrange
            var modelState = new ModelStateDictionary();
            modelState.SetModelValue("foo", false);
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

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

            // Assert
            Assert.AreEqual(@"<input id=""foo"" name=""foo"" type=""checkbox"" />",
                html.ToHtmlString());
        }