public void DropDownListThrowsWithNoName() { // Arrange HtmlHelper helper = new HtmlHelper(new ModelStateDictionary()); // Act and assert ExceptionAssert.ThrowsArgNullOrEmpty(() => helper.DropDownList(name: null, selectList: null), "name"); }
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()); }
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()); }
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()); }
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()); }
public void DropDownListWithDotReplacementForId() { // Arrange HtmlHelper helper = new HtmlHelper(new ModelStateDictionary()); // Act var html = helper.DropDownList("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()); }
public void DropDownListWithObjectDictionaryAndTitle() { // Arrange HtmlHelper helper = new HtmlHelper(new ModelStateDictionary()); // Act var html = helper.DropDownList("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()); }
public void DropDownListWithEmptyOptionLabel() { // Arrange var modelState = new ModelStateDictionary(); modelState.AddError("foo", "some error"); HtmlHelper helper = new HtmlHelper(modelState); // Act var html = helper.DropDownList("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()); }