private static ViewDataDictionary GetViewDataWithSelectList() { ViewDataDictionary viewData = new ViewDataDictionary(); SelectList selectList = new SelectList(MultiSelectListTest.GetSampleAnonymousObjects(), "Letter", "FullWord", "C"); viewData["foo"] = selectList; viewData["foo.bar"] = selectList; return(viewData); }
public void DropDownListWithAttributesDictionary() { // Arrange HtmlHelper helper = HtmlHelperTest.GetHtmlHelper(new ViewDataDictionary()); SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings()); // Act string html = helper.DropDownList("foo", selectList, null /* optionLabel */, HtmlHelperTest.AttributesDictionary); // Assert Assert.AreEqual( @"<select baz=""BazValue"" id=""foo"" name=""foo""><option>Alpha</option> <option>Bravo</option> <option>Charlie</option> </select>", html); }
public void DropDownListUsesViewDataDefaultValueNoOptionLabel() { // Arrange HtmlHelper helper = HtmlHelperTest.GetHtmlHelper(_dropDownListViewData); SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings(), "Charlie"); // Act string html = helper.DropDownList("foo", selectList); // Assert Assert.AreEqual( @"<select id=""foo"" name=""foo""><option>Alpha</option> <option selected=""selected"">Bravo</option> <option>Charlie</option> </select>", html); }
public void ListBoxWithObjectDictionary() { // Arrange HtmlHelper helper = HtmlHelperTest.GetHtmlHelper(new ViewDataDictionary()); MultiSelectList selectList = new MultiSelectList(MultiSelectListTest.GetSampleStrings()); // Act string html = helper.ListBox("foo", selectList, HtmlHelperTest.AttributesObjectDictionary); // Assert Assert.AreEqual( @"<select baz=""BazObjValue"" id=""foo"" multiple=""multiple"" name=""foo""><option>Alpha</option> <option>Bravo</option> <option>Charlie</option> </select>", html); }
public void ListBoxUsesViewDataDefaultValue() { // Arrange HtmlHelper helper = HtmlHelperTest.GetHtmlHelper(_listBoxViewData); MultiSelectList selectList = new MultiSelectList(MultiSelectListTest.GetSampleStrings(), new[] { "Charlie" }); // Act string html = helper.ListBox("foo", selectList); // Assert Assert.AreEqual( @"<select id=""foo"" multiple=""multiple"" name=""foo""><option>Alpha</option> <option selected=""selected"">Bravo</option> <option>Charlie</option> </select>", html); }
public void ListBoxUsesExplicitValueIfNotProvidedInViewData() { // Arrange HtmlHelper helper = HtmlHelperTest.GetHtmlHelper(new ViewDataDictionary()); MultiSelectList selectList = new MultiSelectList(MultiSelectListTest.GetSampleAnonymousObjects(), "Letter", "FullWord", new[] { "A", "C" }); // Act string html = helper.ListBox("foo", selectList); // Assert Assert.AreEqual( @"<select id=""foo"" multiple=""multiple"" name=""foo""><option selected=""selected"" value=""A"">Alpha</option> <option value=""B"">Bravo</option> <option selected=""selected"" value=""C"">Charlie</option> </select>", html); }
public void DropDownListUsesExplicitValueIfNotProvidedInViewData() { // Arrange HtmlHelper helper = HtmlHelperTest.GetHtmlHelper(new ViewDataDictionary()); SelectList selectList = new SelectList(MultiSelectListTest.GetSampleAnonymousObjects(), "Letter", "FullWord", "C"); // Act string html = helper.DropDownList("foo", selectList, (string)null /* optionLabel */); // Assert Assert.AreEqual( @"<select id=""foo"" name=""foo""><option value=""A"">Alpha</option> <option value=""B"">Bravo</option> <option selected=""selected"" value=""C"">Charlie</option> </select>", html); }
public void ListBoxWithNullSelectListUsesViewData() { // Arrange HtmlHelper helper = HtmlHelperTest.GetHtmlHelper(); helper.ViewData["foo"] = new MultiSelectList(MultiSelectListTest.GetSampleStrings(), new[] { "Charlie" }); // Act string html = helper.ListBox("foo", null); // Assert Assert.AreEqual( @"<select id=""foo"" multiple=""multiple"" name=""foo""><option>Alpha</option> <option>Bravo</option> <option selected=""selected"">Charlie</option> </select>", html); }
public void ListBoxWithErrorsAndCustomClass() { // Arrange ViewDataDictionary viewData = GetViewDataWithErrors(); HtmlHelper helper = HtmlHelperTest.GetHtmlHelper(viewData); MultiSelectList selectList = new MultiSelectList(MultiSelectListTest.GetSampleStrings(), new[] { "Charlie" }); // Act string html = helper.ListBox("foo", selectList, new { @class = "foo-class" }); // Assert Assert.AreEqual( @"<select class=""input-validation-error foo-class"" id=""foo"" multiple=""multiple"" name=""foo""><option>Alpha</option> <option selected=""selected"">Bravo</option> <option selected=""selected"">Charlie</option> </select>", html); }
public void DropDownListWithObjectDictionaryAndTitle() { // Arrange HtmlHelper helper = HtmlHelperTest.GetHtmlHelper(new ViewDataDictionary()); SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings()); // Act string html = helper.DropDownList("foo", selectList, "[Select Something]", HtmlHelperTest.AttributesObjectDictionary); // Assert Assert.AreEqual( @"<select baz=""BazObjValue"" id=""foo"" name=""foo""><option value="""">[Select Something]</option> <option>Alpha</option> <option>Bravo</option> <option>Charlie</option> </select>", html); }
public void DropDownListWithErrorsAndCustomClass() { // Arrange SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings()); ViewDataDictionary viewData = GetViewDataWithErrors(); HtmlHelper helper = HtmlHelperTest.GetHtmlHelper(viewData); // Act string html = helper.DropDownList("foo", selectList, null /* optionLabel */, new { @class = "foo-class" }); // Assert Assert.AreEqual( @"<select class=""input-validation-error foo-class"" id=""foo"" name=""foo""><option>Alpha</option> <option selected=""selected"">Bravo</option> <option>Charlie</option> </select>", html); }
public void DropDownListWithErrors() { // Arrange SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings(), new[] { "Charlie" }); ViewDataDictionary viewData = GetViewDataWithErrors(); HtmlHelper helper = HtmlHelperTest.GetHtmlHelper(viewData); // Act string html = helper.DropDownList("foo", selectList, null /* optionLabel */, HtmlHelperTest.AttributesObjectDictionary); // Assert Assert.AreEqual( @"<select baz=""BazObjValue"" class=""input-validation-error"" id=""foo"" name=""foo""><option>Alpha</option> <option selected=""selected"">Bravo</option> <option>Charlie</option> </select>", html); }
public void ListBoxWithListOfSelectListItem() { // Arrange ViewDataDictionary vdd = new ViewDataDictionary { { "foo", MultiSelectListTest.GetSampleListObjects() } }; HtmlHelper helper = HtmlHelperTest.GetHtmlHelper(vdd); // Act string html = helper.ListBox("foo"); // Assert Assert.AreEqual( @"<select id=""foo"" multiple=""multiple"" name=""foo""><option value=""123456789"">John</option> <option value=""987654321"">Jane</option> <option selected=""selected"" value=""111111111"">Joe</option> </select>", html); }
public void ListBoxWithIEnumerableSelectListItemSelectsDefaultFromViewData() { // Arrange ViewDataDictionary vdd = new ViewDataDictionary { { "foo", "123456789" } }; HtmlHelper helper = HtmlHelperTest.GetHtmlHelper(vdd); // Act string html = helper.ListBox("foo", MultiSelectListTest.GetSampleIEnumerableObjects()); // Assert Assert.AreEqual( @"<select id=""foo"" multiple=""multiple"" name=""foo""><option value=""123456789"">John</option> <option value=""987654321"">Jane</option> <option value=""111111111"">Joe</option> </select>", html); }
public void DropDownListUsesModelState() { // Arrange SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings()); ViewDataDictionary viewData = GetViewDataWithErrors(); viewData["foo"] = selectList; HtmlHelper helper = HtmlHelperTest.GetHtmlHelper(viewData); // Act string html = helper.DropDownList("foo"); // Assert Assert.AreEqual( @"<select class=""input-validation-error"" id=""foo"" name=""foo""><option>Alpha</option> <option selected=""selected"">Bravo</option> <option>Charlie</option> </select>", html); }