1 // 2 // Tests for System.Web.UI.WebControls.ListBoxTest.cs 3 // 4 // Author: 5 // Jackson Harper (jackson@ximian.com) 6 // Gonzalo Paniagua Javier (gonzalo@ximian.com) 7 // 8 9 // 10 // Copyright (C) 2005 Novell, Inc (http://www.novell.com) 11 // 12 // Permission is hereby granted, free of charge, to any person obtaining 13 // a copy of this software and associated documentation files (the 14 // "Software"), to deal in the Software without restriction, including 15 // without limitation the rights to use, copy, modify, merge, publish, 16 // distribute, sublicense, and/or sell copies of the Software, and to 17 // permit persons to whom the Software is furnished to do so, subject to 18 // the following conditions: 19 // 20 // The above copyright notice and this permission notice shall be 21 // included in all copies or substantial portions of the Software. 22 // 23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 30 // 31 32 using NUnit.Framework; 33 using System; 34 using System.IO; 35 using System.Drawing; 36 using System.Collections.Specialized; 37 using System.Globalization; 38 using System.Web; 39 using System.Web.UI; 40 using System.Web.UI.WebControls; 41 using System.Data; 42 using MonoTests.stand_alone.WebHarness; 43 using MonoTests.SystemWeb.Framework; 44 45 namespace MonoTests.System.Web.UI.WebControls 46 { 47 class ListBoxPoker : ListBox { 48 ListBoxPoker()49 public ListBoxPoker () 50 { 51 TrackViewState (); 52 } 53 LoadPD(string key, NameValueCollection values)54 public bool LoadPD (string key, NameValueCollection values) 55 { 56 return ((IPostBackDataHandler) this).LoadPostData (key, values); 57 } 58 SaveState()59 public object SaveState () 60 { 61 return SaveViewState (); 62 } 63 LoadState(object o)64 public void LoadState (object o) 65 { 66 LoadViewState (o); 67 } 68 69 public StateBag _ViewState { 70 get { return ViewState; } 71 } 72 73 Render()74 public string Render () 75 { 76 StringWriter sw = new StringWriter (); 77 sw.NewLine = "\n"; 78 HtmlTextWriter writer = new HtmlTextWriter (sw); 79 base.Render (writer); 80 return writer.InnerWriter.ToString (); 81 } 82 VerifyMultiSelect()83 public new virtual void VerifyMultiSelect() 84 { 85 base.VerifyMultiSelect(); 86 } 87 88 } 89 90 [TestFixture] 91 public class ListBoxTest { 92 93 [Test] Defaults()94 public void Defaults () 95 { 96 ListBox lb = new ListBox (); 97 98 Assert.AreEqual (lb.BorderColor, Color.Empty, "A1"); 99 Assert.AreEqual (lb.BorderStyle, BorderStyle.NotSet, "A2"); 100 Assert.AreEqual (lb.BorderWidth, Unit.Empty, "A3"); 101 Assert.AreEqual (lb.Rows, 4, "A4"); 102 Assert.AreEqual (lb.SelectionMode, ListSelectionMode.Single, "A5"); 103 Assert.AreEqual (lb.ToolTip, String.Empty, "A6"); 104 } 105 106 [Test] SetProps()107 public void SetProps () 108 { 109 ListBox lb = new ListBox (); 110 111 lb.BorderColor = Color.Black; 112 Assert.AreEqual (lb.BorderColor, Color.Black, "A1"); 113 114 lb.BorderStyle = BorderStyle.Dashed; 115 Assert.AreEqual (lb.BorderStyle, BorderStyle.Dashed, "A2"); 116 117 lb.BorderWidth = 0; 118 Assert.AreEqual (lb.BorderWidth, (Unit) 0, "A3"); 119 120 lb.BorderWidth = 15; 121 Assert.AreEqual (lb.BorderWidth, (Unit) 15, "A3"); 122 123 lb.Rows = 1; 124 Assert.AreEqual (lb.Rows, 1, "A4"); 125 126 lb.SelectionMode = ListSelectionMode.Multiple; 127 Assert.AreEqual (lb.SelectionMode, ListSelectionMode.Multiple, "A6"); 128 129 lb.ToolTip = "foo"; 130 Assert.AreEqual (lb.ToolTip, "foo", "A7"); 131 } 132 133 [Test] 134 [Category ("NotWorking")] RowsTooHigh()135 public void RowsTooHigh () 136 { 137 ListBox lb = new ListBox (); 138 lb.Rows = 2001; 139 } 140 141 [Test] 142 [ExpectedException (typeof (ArgumentOutOfRangeException))] RowsTooLow()143 public void RowsTooLow () 144 { 145 ListBox lb = new ListBox (); 146 lb.Rows = 0; 147 } 148 149 [Test] 150 [ExpectedException (typeof (ArgumentOutOfRangeException))] BadSelectionMode()151 public void BadSelectionMode () 152 { 153 ListBox lb = new ListBox (); 154 lb.SelectionMode = (ListSelectionMode) 500; 155 } 156 157 [Test] 158 [ExpectedException (typeof (ArgumentOutOfRangeException))] BadBorderStyle()159 public void BadBorderStyle () 160 { 161 ListBox lb = new ListBox (); 162 lb.BorderStyle = (BorderStyle) 500; 163 } 164 165 [Test] ViewState()166 public void ViewState () 167 { 168 ListBoxPoker p = new ListBoxPoker (); 169 170 p.BorderColor = Color.Red; 171 Assert.AreEqual (p._ViewState ["BorderColor"], 172 Color.Red, "A1"); 173 174 p.BorderStyle = BorderStyle.Double; 175 Assert.AreEqual (p._ViewState ["BorderStyle"], 176 BorderStyle.Double, "A2"); 177 178 p.BorderWidth = 25; 179 Assert.AreEqual (p._ViewState ["BorderWidth"], 180 (Unit) 25, "A3"); 181 182 p.SelectionMode = ListSelectionMode.Multiple; 183 Assert.AreEqual (p._ViewState ["SelectionMode"], 184 ListSelectionMode.Multiple, "A4"); 185 } 186 187 [Test] Render1()188 public void Render1 () 189 { 190 ListBoxPoker l = new ListBoxPoker (); 191 for (int i = 0; i < 3; i ++) 192 l.Items.Add (i.ToString ()); 193 194 l.SelectedIndex = l.Items.Count - 1; 195 196 string exp = @"<select size=""4""> 197 <option value=""0"">0</option> 198 <option value=""1"">1</option> 199 <option selected=""selected"" value=""2"">2</option> 200 201 </select>"; 202 203 HtmlDiff.AssertAreEqual (exp, l.Render (), "Render1"); 204 } 205 GetExampleData()206 DataSet GetExampleData () 207 { 208 DataSet ds = new DataSet (); 209 ds.ReadXml (new StringReader (@" 210 <DataSet> 211 <Stocks Company='Novell Inc.' Symbol='NOVL' Price='6.14' /> 212 <Stocks Company='Microsoft Corp.' Symbol='MSFT' Price='25.92' /> 213 <Stocks Company='Google' Symbol='GOOG' Price='291.60' /> 214 </DataSet> 215 ")); 216 return ds; 217 } 218 219 [Test] DoubleDataBind()220 public void DoubleDataBind () 221 { 222 ListBoxPoker l = new ListBoxPoker (); 223 l.DataSource = GetExampleData (); 224 l.DataTextField = "Company"; 225 l.DataBind (); 226 l.DataBind (); 227 228 string exp = @"<select size=""4""> 229 <option value=""Novell Inc."">Novell Inc.</option> 230 <option value=""Microsoft Corp."">Microsoft Corp.</option> 231 <option value=""Google"">Google</option> 232 233 </select>"; 234 235 HtmlDiff.AssertAreEqual (exp, l.Render (), "DoubleDataBind"); 236 } 237 238 class MyNC : Control, INamingContainer { 239 } 240 241 [Test] 242 [Category ("NotDotNet")] 243 [Category ("NotWorking")] NameIsUniqueID()244 public void NameIsUniqueID () 245 { 246 ListBoxPoker list = new ListBoxPoker (); 247 Page page = new Page (); 248 page.ID = "pg"; 249 Control ctrl = new MyNC (); 250 ctrl.ID = "ctrl"; 251 page.Controls.Add (ctrl); 252 ctrl.Controls.Add (list); 253 string str = list.Render(); 254 Assert.IsTrue (-1 != list.Render ().IndexOf (':'), "unique"); 255 } 256 257 [Test] HtmlEncodedText()258 public void HtmlEncodedText () 259 { 260 ListBoxPoker list = new ListBoxPoker (); 261 // The att. value is encoded by the writer, but the text is encoded in ListBox. 262 list.Items.Add (new ListItem ("\"hola", "\"adios")); 263 string output = list.Render (); 264 Assert.IsTrue (-1 != output.IndexOf (""hola"), "#01"); 265 Assert.IsTrue (-1 != output.IndexOf (""adios"), "#02"); 266 } 267 268 [Test] SelectSingle1()269 public void SelectSingle1 () 270 { 271 ListBoxPoker list = new ListBoxPoker (); 272 list.Items.Add (new ListItem ("1", "first")); 273 list.Items.Add (new ListItem ("2", "second")); 274 list.SelectedIndex = 0; 275 NameValueCollection coll = new NameValueCollection (); 276 coll.Add ("2", "second"); 277 Assert.IsTrue (list.LoadPD ("2", coll), "#00"); 278 Assert.IsFalse (list.Items [0].Selected, "#01"); 279 Assert.IsTrue (list.Items [1].Selected, "#02"); 280 Assert.AreEqual (1, list.SelectedIndex, "#03"); 281 } 282 283 [Test] SelectSingle2()284 public void SelectSingle2 () 285 { 286 ListBoxPoker list = new ListBoxPoker (); 287 list.Items.Add (new ListItem ("1", "first")); 288 list.Items.Add (new ListItem ("2", "second")); 289 list.SelectedIndex = 0; 290 NameValueCollection coll = new NameValueCollection (); 291 coll.Add ("willnotbefound", "second"); 292 Assert.IsTrue (list.LoadPD ("2", coll), "#00"); 293 Assert.IsFalse (list.Items [0].Selected, "#01"); 294 Assert.IsFalse (list.Items [1].Selected, "#02"); 295 Assert.AreEqual (-1, list.SelectedIndex, "#03"); 296 } 297 298 [Test] SelectMultiple1()299 public void SelectMultiple1 () 300 { 301 ListBoxPoker list = new ListBoxPoker (); 302 list.SelectionMode = ListSelectionMode.Multiple; 303 list.Items.Add (new ListItem ("1", "first")); 304 list.Items.Add (new ListItem ("2", "second")); 305 list.SelectedIndex = 0; 306 NameValueCollection coll = new NameValueCollection (); 307 coll.Add ("2", "second"); 308 Assert.IsTrue (list.LoadPD ("2", coll), "#00"); 309 Assert.IsFalse (list.Items [0].Selected, "#01"); 310 Assert.IsTrue (list.Items [1].Selected, "#02"); 311 Assert.AreEqual (1, list.SelectedIndex, "#03"); 312 } 313 314 [Test] SelectMultiple2()315 public void SelectMultiple2 () 316 { 317 ListBoxPoker list = new ListBoxPoker (); 318 list.SelectionMode = ListSelectionMode.Multiple; 319 list.Items.Add (new ListItem ("1", "first")); 320 list.Items.Add (new ListItem ("2", "second")); 321 list.Items.Add (new ListItem ("3", "third")); 322 list.Items.Add (new ListItem ("4", "forth")); 323 NameValueCollection coll = new NameValueCollection (); 324 coll.Add ("key", "second"); 325 coll.Add ("key", "forth"); 326 Assert.IsTrue (list.LoadPD ("key", coll), "#00"); 327 Assert.IsFalse (list.Items [0].Selected, "#01"); 328 Assert.IsTrue (list.Items [1].Selected, "#02"); 329 Assert.IsFalse (list.Items [2].Selected, "#03"); 330 Assert.IsTrue (list.Items [3].Selected, "#04"); 331 332 Assert.IsFalse (list.LoadPD ("key", coll), "#05"); 333 Assert.IsFalse (list.Items [0].Selected, "#06"); 334 Assert.IsTrue (list.Items [1].Selected, "#07"); 335 Assert.IsFalse (list.Items [2].Selected, "#08"); 336 Assert.IsTrue (list.Items [3].Selected, "#09"); 337 338 coll.Clear (); 339 coll.Add ("key", "first"); 340 coll.Add ("key", "third"); 341 Assert.IsTrue (list.LoadPD ("key", coll), "#10"); 342 Assert.IsTrue (list.Items [0].Selected, "#11"); 343 Assert.IsFalse (list.Items [1].Selected, "#12"); 344 Assert.IsTrue (list.Items [2].Selected, "#13"); 345 Assert.IsFalse (list.Items [3].Selected, "#14"); 346 347 } 348 349 [Test] VerifyMultiSelectPositive()350 public void VerifyMultiSelectPositive() 351 { 352 ListBoxPoker list = new ListBoxPoker(); 353 list.SelectionMode = ListSelectionMode.Multiple; 354 list.VerifyMultiSelect(); 355 } 356 357 [Test] 358 [ExpectedException(typeof(HttpException))] VerifyMultiSelectNegative()359 public void VerifyMultiSelectNegative() 360 { 361 ListBoxPoker list = new ListBoxPoker(); 362 list.SelectionMode = ListSelectionMode.Single; 363 list.VerifyMultiSelect(); 364 } 365 366 [Test] 367 [Category ("NunitWeb")] ListItemsViewState1()368 public void ListItemsViewState1 () 369 { 370 PageInvoker pi = PageInvoker.CreateOnLoad (new PageDelegate (ListItemsViewState_PageLoad)); 371 WebTest test = new WebTest (pi); 372 373 string html = test.Run (); 374 375 test.Request = new FormRequest (test.Response, "form1"); 376 test.Invoker = pi; 377 html = test.Run (); 378 } 379 380 [Test] 381 [Category ("NunitWeb")] ListItemsViewState2()382 public void ListItemsViewState2 () 383 { 384 PageInvoker pi = PageInvoker.CreateOnLoad (new PageDelegate (ListItemsViewState_PageLoad2)); 385 WebTest test = new WebTest (pi); 386 387 string html = test.Run (); 388 389 test.Request = new FormRequest (test.Response, "form1"); 390 test.Invoker = pi; 391 html = test.Run (); 392 } 393 394 [Test] 395 [Category ("NunitWeb")] ListItemsViewState3()396 public void ListItemsViewState3 () 397 { 398 PageDelegates pd = new PageDelegates (); 399 pd.Init = ListItemsViewState_Init; 400 pd.Load = ListItemsViewState_PageLoad3; 401 WebTest test = new WebTest (new PageInvoker (pd)); 402 403 string html = test.Run (); 404 Assert.IsTrue (html.IndexOf ("value=\"3\"") > 0, "ListItemsViewState3 #1"); 405 Assert.IsTrue (html.IndexOf ("value=\"4\"") > 0, "ListItemsViewState3 #2"); 406 407 test.Request = new FormRequest (test.Response, "form1"); 408 html = test.Run (); 409 Assert.IsTrue (html.IndexOf ("value=\"3\"") > 0, "ListItemsViewState3 #3"); 410 Assert.IsTrue (html.IndexOf ("value=\"4\"") > 0, "ListItemsViewState3 #4"); 411 } 412 413 [Test] 414 [Category ("NunitWeb")] ListItemsViewState4()415 public void ListItemsViewState4 () 416 { 417 PageDelegates pd = new PageDelegates (); 418 pd.Init = ListItemsViewState_Init; 419 pd.Load = ListItemsViewState_PageLoad4; 420 WebTest test = new WebTest (new PageInvoker (pd)); 421 422 string html = test.Run (); 423 Assert.IsTrue (html.IndexOf ("value=\"3\"") < 0, "ListItemsViewState4 #1"); 424 Assert.IsTrue (html.IndexOf ("value=\"heh\"") > 0, "ListItemsViewState4 #2"); 425 426 test.Request = new FormRequest (test.Response, "form1"); 427 html = test.Run (); 428 Assert.IsTrue (html.IndexOf ("value=\"2\"") > 0, "ListItemsViewState4 #3"); 429 Assert.IsTrue (html.IndexOf ("value=\"3\"") < 0, "ListItemsViewState4 #4"); 430 Assert.IsTrue (html.IndexOf ("value=\"heh\"") > 0, "ListItemsViewState4 #5"); 431 } 432 ListItemsViewState_Init(Page p)433 public static void ListItemsViewState_Init (Page p) 434 { 435 ListBox lb = new ListBox (); 436 lb.ID = "TestedListBox"; 437 lb.Items.Add (new ListItem ("1", "1")); 438 lb.Items.Add (new ListItem ("2", "2")); 439 lb.Items.Add (new ListItem ("3", "3")); 440 441 p.Form.Controls.Add (lb); 442 } 443 ListItemsViewState_PageLoad(Page p)444 public static void ListItemsViewState_PageLoad (Page p) 445 { 446 ListBox lb = new ListBox (); 447 if (!p.IsPostBack) { 448 lb.Items.Add (new ListItem ("1", "1")); 449 lb.Items.Add (new ListItem ("2", "2")); 450 lb.Items.Add (new ListItem ("3", "3")); 451 lb.Items.Add (new ListItem ("4", "4")); 452 lb.Items.Add (new ListItem ("5", "5")); 453 454 lb.Items [2].Selected = true; 455 } 456 457 p.Form.Controls.Add (lb); 458 } 459 ListItemsViewState_PageLoad2(Page p)460 public static void ListItemsViewState_PageLoad2 (Page p) 461 { 462 ListBox lb = new ListBox (); 463 if (!p.IsPostBack) { 464 lb.Items.Add (new ListItem ("1", "1")); 465 lb.Items.Add (new ListItem ("2", "2")); 466 lb.Items.Add (new ListItem ("3", "3")); 467 lb.Items.Add (new ListItem ("4", "4")); 468 lb.Items.Add (new ListItem ("5", "5")); 469 470 lb.SelectedIndex = 2; 471 } 472 473 p.Form.Controls.Add (lb); 474 } 475 ListItemsViewState_PageLoad3(Page p)476 public static void ListItemsViewState_PageLoad3 (Page p) 477 { 478 ListBox lb = (ListBox) p.FindControl ("TestedListBox"); 479 if (!p.IsPostBack) { 480 lb.Items.Add (new ListItem ("4", "4")); 481 lb.Items.Add (new ListItem ("5", "5")); 482 } 483 } 484 ListItemsViewState_PageLoad4(Page p)485 public static void ListItemsViewState_PageLoad4 (Page p) 486 { 487 ListBox lb = (ListBox) p.FindControl ("TestedListBox"); 488 if (!p.IsPostBack) { 489 lb.Items [2].Text = "heh"; 490 lb.Items [2].Value = "heh"; 491 lb.Items [2].Selected = true; 492 } 493 } 494 495 [Test] 496 [Category ("NunitWeb")] ListItemsSelectedTest1()497 public void ListItemsSelectedTest1 () 498 { 499 PageDelegates pd = new PageDelegates (); 500 pd.Init = ListItemsSelectedTest_Init; 501 WebTest test = new WebTest (new PageInvoker (pd)); 502 string html = test.Run (); 503 Assert.IsTrue (html.IndexOf ("selected=") < 0, "ListItemsSelectedTest1 #1"); 504 505 test.Request = new FormRequest (test.Response, "form1"); 506 //test.Invoker = new PageInvoker (pd); 507 html = test.Run (); 508 Assert.IsTrue (html.IndexOf ("selected=") < 0, "ListItemsSelectedTest1 #2"); 509 } 510 511 [Test] 512 [Category ("NunitWeb")] ListItemsSelectedTest2()513 public void ListItemsSelectedTest2 () 514 { 515 PageDelegates pd = new PageDelegates (); 516 pd.Init = ListItemsSelectedTest_Init; 517 pd.Load = ListItemsSelectedTest_Load; 518 WebTest test = new WebTest (new PageInvoker (pd)); 519 string html = test.Run (); 520 Assert.IsTrue (html.IndexOf ("selected=") < 0, "ListItemsSelectedTest2 #1"); 521 522 test.Request = new FormRequest (test.Response, "form1"); 523 html = test.Run (); 524 Assert.IsTrue (html.IndexOf ("value=\"3\"") > 0, "ListItemsSelectedTest2 #2"); 525 Assert.IsTrue (html.IndexOf ("selected=") < 0, "ListItemsSelectedTest2 #3"); 526 } 527 528 [Test] 529 [Category ("NunitWeb")] ListItemsSelectedTest3()530 public void ListItemsSelectedTest3 () 531 { 532 PageDelegates pd = new PageDelegates (); 533 pd.Init = ListItemsSelectedTest_Init; 534 pd.Load = ListItemsSelectedTest_Load2; 535 WebTest test = new WebTest (new PageInvoker (pd)); 536 string html = test.Run (); 537 Assert.IsTrue (html.IndexOf ("selected=") > 0, "ListItemsSelectedTest3 #1"); 538 539 FormRequest fr = new FormRequest (test.Response, "form1"); 540 fr.Controls.Add ("TestedListBox"); 541 fr.Controls ["TestedListBox"].Value = "2"; 542 test.Request = fr; 543 test.UserData = ""; 544 545 html = test.Run (); 546 Assert.IsTrue (html.IndexOf ("value=\"3\"") > 0, "ListItemsSelectedTest3 #2"); 547 Assert.IsTrue (html.IndexOf ("value=\"2\"") > 0, "ListItemsSelectedTest3 #3"); 548 Assert.IsTrue (html.IndexOf ("selected=") > 0, "ListItemsSelectedTest3 #4"); 549 Assert.AreEqual ("SelectedIndexChanged", test.UserData, "ListItemsSelectedTest3 #5"); 550 } 551 552 [Test] 553 [Category ("NunitWeb")] ListItemsSelectedTest4()554 public void ListItemsSelectedTest4 () 555 { 556 PageDelegates pd = new PageDelegates (); 557 pd.Init = ListItemsSelectedTest_Init; 558 pd.Load = ListItemsSelectedTest_Load3; 559 WebTest test = new WebTest (new PageInvoker (pd)); 560 string html = test.Run (); 561 Assert.IsTrue (html.IndexOf ("selected=") > 0, "ListItemsSelectedTest4 #1"); 562 563 FormRequest fr = new FormRequest (test.Response, "form1"); 564 fr.Controls.Add ("TestedListBox"); 565 fr.Controls ["TestedListBox"].Value = "2"; 566 test.Request = fr; 567 test.UserData = ""; 568 569 html = test.Run (); 570 Assert.IsTrue (html.IndexOf ("value=\"3\"") > 0, "ListItemsSelectedTest4 #2"); 571 Assert.IsTrue (html.IndexOf ("selected=") > 0, "ListItemsSelectedTest4 #3"); 572 Assert.AreEqual ("SelectedIndexChanged", test.UserData, "ListItemsSelectedTest4 #4"); 573 } 574 575 [Test] 576 [Category ("NunitWeb")] ListItemsSelectedTest5()577 public void ListItemsSelectedTest5 () 578 { 579 PageDelegates pd = new PageDelegates (); 580 pd.Init = ListItemsSelectedTest_Init2; 581 pd.Load = ListItemsSelectedTest_Load4; 582 WebTest test = new WebTest (new PageInvoker (pd)); 583 string html = test.Run (); 584 Assert.IsTrue (html.IndexOf ("selected=") > 0, "ListItemsSelectedTest5 #1"); 585 586 FormRequest fr = new FormRequest (test.Response, "form1"); 587 fr.Controls.Add ("TestedListBox"); 588 fr.Controls ["TestedListBox"].Value = "2"; 589 test.Request = fr; 590 test.UserData = ""; 591 592 html = test.Run (); 593 Assert.IsTrue (html.IndexOf ("value=\"1\"") > 0, "ListItemsSelectedTest5 #2"); 594 Assert.IsTrue (html.IndexOf ("value=\"2\"") > 0, "ListItemsSelectedTest5 #2"); 595 Assert.IsTrue (html.IndexOf ("value=\"3\"") > 0, "ListItemsSelectedTest5 #3"); 596 Assert.IsTrue (html.IndexOf ("selected=") > 0, "ListItemsSelectedTest5 #4"); 597 Assert.AreEqual ("SelectedIndexChanged", test.UserData, "ListItemsSelectedTest5 #5"); 598 } 599 ListItemsSelectedTest_Init(Page p)600 public static void ListItemsSelectedTest_Init (Page p) 601 { 602 ListBox lb = new ListBox (); 603 lb.ID = "TestedListBox"; 604 lb.SelectedIndex = 2; 605 606 lb.SelectedIndexChanged += new EventHandler (ListItemsSelectedTest_lb_SelectedIndexChanged); 607 608 p.Form.Controls.Add (lb); 609 } 610 ListItemsSelectedTest_Init2(Page p)611 public static void ListItemsSelectedTest_Init2 (Page p) 612 { 613 ListBox lb = new ListBox (); 614 lb.ID = "TestedListBox"; 615 lb.Items.Add (new ListItem ("1", "1")); 616 lb.Items.Add (new ListItem ("2", "2")); 617 lb.Items.Add (new ListItem ("3", "3")); 618 lb.Items.Add (new ListItem ("4", "4")); 619 lb.Items.Add (new ListItem ("5", "5")); 620 621 lb.SelectedIndexChanged += new EventHandler (ListItemsSelectedTest_lb_SelectedIndexChanged); 622 623 p.Form.Controls.Add (lb); 624 } 625 ListItemsSelectedTest_Load(Page p)626 public static void ListItemsSelectedTest_Load (Page p) 627 { 628 ListBox lb = (ListBox) p.FindControl ("TestedListBox"); 629 630 if (!p.IsPostBack) { 631 lb.Items.Add (new ListItem ("1", "1")); 632 lb.Items.Add (new ListItem ("2", "2")); 633 lb.Items.Add (new ListItem ("3", "3")); 634 lb.Items.Add (new ListItem ("4", "4")); 635 lb.Items.Add (new ListItem ("5", "5")); 636 } 637 } 638 ListItemsSelectedTest_Load2(Page p)639 public static void ListItemsSelectedTest_Load2 (Page p) 640 { 641 ListBox lb = (ListBox) p.FindControl ("TestedListBox"); 642 643 if (!p.IsPostBack) { 644 lb.DataSource = new string [] { "1", "2", "3", "4", "5" }; 645 lb.DataBind (); 646 } 647 } 648 ListItemsSelectedTest_Load3(Page p)649 public static void ListItemsSelectedTest_Load3 (Page p) 650 { 651 ListBox lb = (ListBox) p.FindControl ("TestedListBox"); 652 653 if (!p.IsPostBack) { 654 lb.Items.Add (new ListItem ("1", "1")); 655 lb.Items.Add (new ListItem ("2", "2")); 656 lb.Items.Add (new ListItem ("3", "3")); 657 lb.Items.Add (new ListItem ("4", "4")); 658 lb.Items.Add (new ListItem ("5", "5")); 659 660 lb.Items [2].Selected = true; 661 } 662 } 663 ListItemsSelectedTest_Load4(Page p)664 public static void ListItemsSelectedTest_Load4 (Page p) 665 { 666 ListBox lb = (ListBox) p.FindControl ("TestedListBox"); 667 668 if (!p.IsPostBack) { 669 lb.Items [2].Text = "heh"; 670 lb.Items [2].Selected = true; 671 } 672 } 673 ListItemsSelectedTest_lb_SelectedIndexChanged(object sender, EventArgs e)674 public static void ListItemsSelectedTest_lb_SelectedIndexChanged (object sender, EventArgs e) 675 { 676 WebTest.CurrentTest.UserData = "SelectedIndexChanged"; 677 } 678 } 679 } 680 681 682