예제 #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");
        }
예제 #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());
        }
예제 #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());
        }
예제 #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());
        }
예제 #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());
        }
예제 #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.");
        }
예제 #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());
        }
예제 #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());
        }
예제 #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());
        }