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"); }
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()); }
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()); }
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()); }
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()); }
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."); }
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()); }
//[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()); }
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()); }