New test.
[mono.git] / mcs / class / System.Web / Test / mainsoft / MainsoftWebApp / utils / GHTListControlBase.cs
1 //
2 // Authors:
3 //   Rafael Mizrahi   <rafim@mainsoft.com>
4 //   Erez Lotan       <erezl@mainsoft.com>
5 //   Vladimir Krasnov <vladimirk@mainsoft.com>
6 //   
7 // 
8 // Copyright (c) 2002-2005 Mainsoft Corporation.
9 // 
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29 using System;
30 using System.Collections;
31 using System.ComponentModel;
32 using System.Web;
33 using System.Web.SessionState;
34 using System.Web.UI;
35 using System.Web.UI.WebControls;
36 using System.Web.UI.HtmlControls;
37 using GHTWebControls;
38 using System.Drawing;
39 using System.Data;
40  
41 namespace GHTTests
42 {
43         /// <summary>
44         /// Summary description for GHTListControlBase.
45         /// </summary>
46         public class GHTListControlBase : GHTBaseWeb
47         {
48                 #region "Tests"
49                 protected void ListControl_AutoPostBack(Type ctrlType)
50                 {
51                         #region "Setting to true"
52                         GHTListContorlSubTestBegin(ctrlType, "AutoPostBack = True");
53                         try
54                         {
55                                 m_lcToTest.AutoPostBack = true;
56                         }
57                         catch (Exception ex)
58                         {
59                                 GHTSubTestUnexpectedExceptionCaught(ex);
60                         }
61                         GHTSubTestEnd();
62                         #endregion
63                         #region "Getting true:"
64                         GHTListContorlSubTestBegin(ctrlType, "Get AutoPostBack true");
65                         try
66                         {
67                                 m_lcToTest.AutoPostBack = true;
68                                 Compare(m_lcToTest.AutoPostBack, true);
69                         }
70                         catch (Exception ex)
71                         {
72                                 GHTSubTestUnexpectedExceptionCaught(ex);
73                         }
74                         #endregion
75                         #region "Setting to false"
76                         GHTListContorlSubTestBegin(ctrlType, "AutoPostBack = false");
77                         try
78                         {
79                                 m_lcToTest.AutoPostBack = false;
80                         }
81                         catch (Exception ex)
82                         {
83                                 GHTSubTestUnexpectedExceptionCaught(ex);
84                         }
85                         GHTSubTestEnd();
86                         #endregion
87                         #region "Getting false:"
88                         GHTListContorlSubTestBegin(ctrlType, "Get AutoPostBack false");
89                         try
90                         {
91                                 m_lcToTest.AutoPostBack = false;
92                                 Compare(m_lcToTest.AutoPostBack, false);
93                         }
94                         catch (Exception ex)
95                         {
96                                 GHTSubTestUnexpectedExceptionCaught(ex);
97                         }
98                         #endregion
99                 }
100                 protected void ListControl_ClearSelection(Type ctrlType)
101                 {
102                         #region "No item selected"
103                         GHTListContorlSubTestBegin(ctrlType, "No ite, selected");
104                         try
105                         {
106                                 m_lcToTest.Items.Add("A");
107                                 m_lcToTest.Items.Add("B");
108                                 m_lcToTest.Items.Add("C");
109                                 m_lcToTest.ClearSelection();
110                         }
111                         catch (Exception ex)
112                         {
113                                 GHTSubTestUnexpectedExceptionCaught(ex);
114                         }
115                         GHTSubTestEnd();
116                         #endregion
117                         #region "One item selected"
118                         GHTListContorlSubTestBegin(ctrlType, "One item selected");
119                         try
120                         {
121                                 m_lcToTest.Items.Add("A");
122                                 m_lcToTest.Items.Add("B");
123                                 m_lcToTest.Items.Add("C");
124                                 m_lcToTest.SelectedIndex = 1;
125                                 m_lcToTest.ClearSelection();
126                         }
127                         catch (Exception ex)
128                         {
129                                 GHTSubTestUnexpectedExceptionCaught(ex);
130                         }
131                         #endregion
132                 }
133                 protected void ListControl_DataMember(Type ctrlType)
134                 {
135                         InitDataSet();
136                         #region "Existing Table"
137                         GHTListContorlSubTestBegin(ctrlType, "Existing table");
138                         
139                         try
140                         {
141                                 m_lcToTest.DataSource = m_dsData;
142                                 m_lcToTest.DataMember = "Second";
143                                 m_lcToTest.DataTextField = "double Column";
144                                 m_lcToTest.DataBind();
145                                 Compare(m_lcToTest.DataMember, "Second");
146                         }
147                         catch (Exception ex)
148                         {
149                                 GHTSubTestUnexpectedExceptionCaught(ex);
150                         }
151
152                         GHTSubTestEnd();
153                         #endregion
154                         #region "Null"
155                         GHTListContorlSubTestBegin(ctrlType, "Null");
156                         try
157                         {
158                                 m_lcToTest.DataSource = m_dsData;
159                                 m_lcToTest.DataMember = null;
160                                 m_lcToTest.DataTextField = "char Column";
161                                 m_lcToTest.DataBind();
162                         }
163                         catch (Exception ex)
164                         {
165                                 GHTSubTestUnexpectedExceptionCaught(ex);
166                         }
167
168                         #endregion
169                         #region "Non existing table in a dataset"
170                         GHTListContorlSubTestBegin(ctrlType, "Non existing table in a dataset");
171                         
172                         try
173                         {
174                                 m_lcToTest.DataSource = m_dsData;
175                                 m_lcToTest.DataMember = "not a table name";
176                                 m_lcToTest.DataBind();
177                                 GHTSubTestExpectedExceptionNotCaught("HttpException");
178                         }
179                         catch (HttpException ex)
180                         {
181                                 GHTSubTestExpectedExceptionCaught(ex);
182                         }
183                         catch (Exception ex)
184                         {
185                                 GHTSubTestUnexpectedExceptionCaught(ex);
186                         }
187                         #endregion
188                         #region "DataSource is not a dataset - set"
189                         GHTListContorlSubTestBegin(ctrlType, "DataSource is not a dataset");
190                         
191                         try
192                         {
193                                 InitArray();
194                                 m_lcToTest.DataSource = m_items;
195                                 m_lcToTest.DataMember = "not a table name";
196                                 m_lcToTest.DataBind();
197                         }
198                         catch (Exception ex)
199                         {
200                                 GHTSubTestUnexpectedExceptionCaught(ex);
201                         }
202                         #endregion
203                 }
204
205                 protected void ListControl_DataSource(Type ctrlType)
206                 {
207                         InitDataSet();
208                         InitArray();
209                         #region "DataSource that implements IEnumerable"
210                         GHTListContorlSubTestBegin(ctrlType, "DataSource that implements IEnumerable");
211                         
212                         try
213                         {
214                                 IEnumerable dataSource = m_items;
215                                 m_lcToTest.DataSource = dataSource;
216                                 m_lcToTest.DataBind();
217                         }
218                         catch (Exception ex)
219                         {
220                                 GHTSubTestUnexpectedExceptionCaught(ex);
221                         }
222
223                         GHTSubTestEnd();
224                         #endregion
225                         #region "DataSource that implements IListSource"
226                         GHTListContorlSubTestBegin(ctrlType, "DataSource that implements IListSource");
227                         
228                         try
229                         {
230                                 IListSource dataSource = m_dsData;
231                                 m_lcToTest.DataSource = dataSource;
232                                 m_lcToTest.DataTextField = "char Column";
233                                 m_lcToTest.DataBind();
234                         }
235                         catch (Exception ex)
236                         {
237                                 GHTSubTestUnexpectedExceptionCaught(ex);
238                         }
239
240                         GHTSubTestEnd();
241                         #endregion
242                         #region "DataSource that does not implement IListSource or IEnumerable"
243                         GHTListContorlSubTestBegin(ctrlType, "DataSource that does not implement IListSource or IEnumerable");
244                         
245                         try
246                         {
247                                 DataItem dataSource = new DataItem(1, "aaa");
248                                 m_lcToTest.DataSource = dataSource;
249                                 m_lcToTest.DataBind();
250                                 GHTSubTestExpectedExceptionNotCaught("ArgumentException");
251                         }
252                         catch (ArgumentException ex)
253                         {
254                                 GHTSubTestExpectedExceptionCaught(ex);
255                         }
256                         catch (Exception ex)
257                         {
258                                 GHTSubTestUnexpectedExceptionCaught(ex);
259                         }
260
261                         GHTSubTestEnd();
262                         #endregion
263                 }
264
265                 protected void ListControl_DataTextField(Type ctrlType)
266                 {
267                         InitArray();
268                         InitDataSet();
269                         #region "string.empty - user defined items"
270                         GHTListContorlSubTestBegin(ctrlType, "string.empty");
271                         
272                         try
273                         {
274                                 m_lcToTest.DataSource = m_items;
275                                 m_lcToTest.DataTextField = string.Empty;
276                                 m_lcToTest.DataBind();
277                         }
278                         catch (Exception ex)
279                         {
280                                 GHTSubTestUnexpectedExceptionCaught(ex);
281                         }
282
283                         GHTSubTestEnd();
284                         #endregion
285
286 //The result is ToString of DataRow which is default Object.ToString()
287 //In Java we get @addres at the end.
288 //                      #region "string.empty - bound to a table"
289 //                      GHTListContorlSubTestBegin(ctrlType, "string.empty - bound to a table");
290 //                      
291 //                      try
292 //                      {
293 //                              m_lcToTest.DataSource = m_dsData;
294 //                              m_lcToTest.DataTextField = string.Empty;
295 //                              m_lcToTest.DataBind();
296 //                      }
297 //                      catch (Exception ex)
298 //                      {
299 //                              GHTSubTestUnexpectedExceptionCaught(ex);
300 //                      }
301 //
302 //                      GHTSubTestEnd();
303 //                      #endregion
304                         #region "Name of an items property"
305                         GHTListContorlSubTestBegin(ctrlType, "Name of an items property");
306                         
307                         try
308                         {
309                                 m_lcToTest.DataSource = m_items;
310                                 m_lcToTest.DataTextField = "Name";
311                                 m_lcToTest.DataBind();
312                         }
313                         catch (Exception ex)
314                         {
315                                 GHTSubTestUnexpectedExceptionCaught(ex);
316                         }
317
318                         GHTSubTestEnd();
319                         #endregion
320                         #region "Name of an item non-existing property"
321                         GHTListContorlSubTestBegin(ctrlType, "Name of an item non-existing property");
322                         
323                         try
324                         {
325                                 m_lcToTest.DataSource = m_items;
326                                 m_lcToTest.DataTextField = "non-existing property";
327                                 m_lcToTest.DataBind();
328                                 GHTSubTestExpectedExceptionNotCaught("HttpException");
329                         }
330                         catch (HttpException ex)
331                         {
332                                 GHTSubTestExpectedExceptionCaught(ex);
333                         }
334                         catch (Exception ex)
335                         {
336                                 GHTSubTestUnexpectedExceptionCaught(ex);
337                         }
338
339                         GHTSubTestEnd();
340                         #endregion
341                         #region "Name of a column"
342                         GHTListContorlSubTestBegin(ctrlType, "Name of a column");
343                         
344                         try
345                         {
346                                 m_lcToTest.DataSource = m_dsData;
347                                 m_lcToTest.DataTextField = "int Column";
348                                 m_lcToTest.DataBind();
349                         }
350                         catch (Exception ex)
351                         {
352                                 GHTSubTestUnexpectedExceptionCaught(ex);
353                         }
354
355                         GHTSubTestEnd();
356                         #endregion
357                         #region "Name of a non-existing column"
358                         GHTListContorlSubTestBegin(ctrlType, "Name of a non-existing column");
359                         
360                         try
361                         {
362                                 m_lcToTest.DataSource = m_dsData;
363                                 m_lcToTest.DataTextField = "non-existing column";
364                                 m_lcToTest.DataBind();
365                                 GHTSubTestExpectedExceptionNotCaught("HttpException");
366                         }
367                         catch (HttpException ex)
368                         {
369                                 GHTSubTestExpectedExceptionCaught(ex);
370                         }
371                         catch (Exception ex)
372                         {
373                                 GHTSubTestUnexpectedExceptionCaught(ex);
374                         }
375
376                         GHTSubTestEnd();
377                         #endregion
378                 }
379
380                 protected void ListControl_DataTextFormatString(Type ctrlType)
381                 {
382                         InitArray();
383                         #region "string.empty"
384                         GHTListContorlSubTestBegin(ctrlType, "string.empty");
385                         
386                         try
387                         {
388                                 m_lcToTest.DataSource = m_items;
389                                 m_lcToTest.DataTextField = "Name";
390                                 m_lcToTest.DataTextFormatString = string.Empty;
391                                 m_lcToTest.DataBind();
392                         }
393                         catch (Exception ex)
394                         {
395                                 GHTSubTestUnexpectedExceptionCaught(ex);
396                         }
397
398                         GHTSubTestEnd();
399                         #endregion
400                         #region "Valid format"
401                         GHTListContorlSubTestBegin(ctrlType, "Valid format");
402                         
403                         try
404                         {
405                                 m_lcToTest.DataSource = m_items;
406                                 m_lcToTest.DataTextField = "Name";
407                                 m_lcToTest.DataTextFormatString = "format {0} format";
408                                 m_lcToTest.DataBind();
409                         }
410                         catch (Exception ex)
411                         {
412                                 GHTSubTestUnexpectedExceptionCaught(ex);
413                         }
414
415                         GHTSubTestEnd();
416                         #endregion
417                         #region "Invalid format"
418                         GHTListContorlSubTestBegin(ctrlType, "Invalid format");
419                         
420                         try
421                         {
422                                 m_lcToTest.DataSource = m_items;
423                                 m_lcToTest.DataTextField = "Name";
424                                 m_lcToTest.DataTextFormatString = "{invalid format}";
425                                 m_lcToTest.DataBind();
426                                 GHTSubTestExpectedExceptionNotCaught("FormatException");
427                         }
428                         catch (FormatException ex)
429                         {
430                                 GHTSubTestExpectedExceptionCaught(ex);
431                         }
432                         catch (Exception ex)
433                         {
434                                 GHTSubTestUnexpectedExceptionCaught(ex);
435                         }
436
437                         GHTSubTestEnd();
438                         #endregion
439                 }
440
441                 protected void ListControl_Items(Type ctrlType)
442                 {
443                         InitArray();
444                         GHTListContorlSubTestBegin(ctrlType, "Type & contents");
445                         
446                         try
447                         {
448                                 m_lcToTest.DataSource = m_items;
449                                 m_lcToTest.DataTextField = "Name";
450                                 m_lcToTest.DataValueField = "Id";
451                                 m_lcToTest.DataBind();
452                                 //Check the type:
453                                 Compare(m_lcToTest.Items.GetType().ToString(), typeof(ListItemCollection).ToString());
454                                 //Check all the items.
455                                 for (int i=0; i<7; i++)
456                                 {
457                                         Compare(m_lcToTest.Items[i].Text, m_items[i].Name);
458                                         Compare(m_lcToTest.Items[i].Value.ToString(), m_items[i].Id.ToString());
459                                 }
460                         }
461                         catch (Exception ex)
462                         {
463                                 GHTSubTestUnexpectedExceptionCaught(ex);
464                         }
465
466                         GHTSubTestEnd();
467                 }
468
469                 protected void ListControl_DataValueField(Type ctrlType)
470                 {
471                         InitArray();
472                         InitDataSet();
473                         #region "string.empty - user defined items"
474                         GHTListContorlSubTestBegin(ctrlType, "string.empty");
475                         
476                         try
477                         {
478                                 m_lcToTest.DataSource = m_items;
479                                 m_lcToTest.DataValueField = string.Empty;
480                                 m_lcToTest.DataBind();
481                         }
482                         catch (Exception ex)
483                         {
484                                 GHTSubTestUnexpectedExceptionCaught(ex);
485                         }
486
487                         GHTSubTestEnd();
488                         #endregion
489                         #region "string.empty - bound to a table"
490                         GHTListContorlSubTestBegin(ctrlType, "string.empty - bound to a table");
491                         
492                         try
493                         {
494                                 m_lcToTest.DataSource = m_dsData;
495                                 m_lcToTest.DataValueField= string.Empty;
496                                 m_lcToTest.DataTextField = "char Column";
497                                 m_lcToTest.DataBind();
498                         }
499                         catch (Exception ex)
500                         {
501                                 GHTSubTestUnexpectedExceptionCaught(ex);
502                         }
503
504                         GHTSubTestEnd();
505                         #endregion
506                         #region "Name of an items property"
507                         GHTListContorlSubTestBegin(ctrlType, "Name of an items property");
508                         
509                         try
510                         {
511                                 m_lcToTest.DataSource = m_items;
512                                 m_lcToTest.DataValueField = "Id";
513                                 m_lcToTest.DataBind();
514                         }
515                         catch (Exception ex)
516                         {
517                                 GHTSubTestUnexpectedExceptionCaught(ex);
518                         }
519
520                         GHTSubTestEnd();
521                         #endregion
522                         #region "Name of an item non-existing property"
523                         GHTListContorlSubTestBegin(ctrlType, "Name of an item non-existing property");
524                         
525                         try
526                         {
527                                 m_lcToTest.DataSource = m_items;
528                                 m_lcToTest.DataValueField = "non-existing property";
529                                 m_lcToTest.DataBind();
530                                 GHTSubTestExpectedExceptionNotCaught("HttpException");
531                         }
532                         catch (HttpException ex)
533                         {
534                                 GHTSubTestExpectedExceptionCaught(ex);
535                         }
536                         catch (Exception ex)
537                         {
538                                 GHTSubTestUnexpectedExceptionCaught(ex);
539                         }
540
541                         GHTSubTestEnd();
542                         #endregion
543                         #region "Name of a column"
544                         GHTListContorlSubTestBegin(ctrlType, "Name of a column");
545                         
546                         try
547                         {
548                                 m_lcToTest.DataSource = m_dsData;
549                                 m_lcToTest.DataValueField = "int Column";
550                                 m_lcToTest.DataBind();
551                         }
552                         catch (Exception ex)
553                         {
554                                 GHTSubTestUnexpectedExceptionCaught(ex);
555                         }
556
557                         GHTSubTestEnd();
558                         #endregion
559                         #region "Name of a non-existing column"
560                         GHTListContorlSubTestBegin(ctrlType, "Name of a non-existing column");
561                         
562                         try
563                         {
564                                 m_lcToTest.DataSource = m_dsData;
565                                 m_lcToTest.DataValueField = "non-existing column";
566                                 m_lcToTest.DataBind();
567                                 GHTSubTestExpectedExceptionNotCaught("HttpException");
568                         }
569                         catch (HttpException ex)
570                         {
571                                 GHTSubTestExpectedExceptionCaught(ex);
572                         }
573                         catch (Exception ex)
574                         {
575                                 GHTSubTestUnexpectedExceptionCaught(ex);
576                         }
577
578                         GHTSubTestEnd();
579                         #endregion
580                 }
581                 protected void ListControl_SelectedIndex(Type ctrlType)
582                 {
583                         InitArray();
584                         #region "None selected"
585                         GHTListContorlSubTestBegin(ctrlType, "None selected");
586                         
587                         try
588                         {
589                                 m_lcToTest.DataSource = m_items;
590                                 m_lcToTest.DataBind();
591                                 m_lcToTest.SelectedIndex = -1;
592                                 GHTSubTestAddResult(m_lcToTest.SelectedIndex.ToString());
593                         }
594                         catch (Exception ex)
595                         {
596                                 GHTSubTestUnexpectedExceptionCaught(ex);
597                         }
598                         #endregion
599                         #region "valid value"
600                         GHTListContorlSubTestBegin(ctrlType, "valid value");
601                         
602                         try
603                         {
604                                 m_lcToTest.DataSource = m_items;
605                                 m_lcToTest.DataBind();
606                                 m_lcToTest.SelectedIndex = 5;
607                                 GHTSubTestAddResult(m_lcToTest.SelectedIndex.ToString());
608                         }
609                         catch (Exception ex)
610                         {
611                                 GHTSubTestUnexpectedExceptionCaught(ex);
612                         }
613                         #endregion
614                         #region "Invalid value - above length of items."
615                         GHTListContorlSubTestBegin(ctrlType, "Invalid value - above length of items.");
616                         
617                         try
618                         {
619                                 m_lcToTest.DataSource = m_items;
620                                 m_lcToTest.DataBind();
621                                 m_lcToTest.SelectedIndex = 10;
622                                 GHTSubTestExpectedExceptionNotCaught("ArgumentOutOfRangeException");
623                         }
624                         catch (ArgumentOutOfRangeException ex)
625                         {
626                                 GHTSubTestExpectedExceptionCaught(ex);
627                         }
628                         catch (Exception ex)
629                         {
630                                 GHTSubTestUnexpectedExceptionCaught(ex);
631                         }
632                         #endregion
633                         #region "Invalid value - below -1."
634                         GHTListContorlSubTestBegin(ctrlType, "Invalid value - below -1.");
635                         
636                         try
637                         {
638                                 m_lcToTest.DataSource = m_items;
639                                 m_lcToTest.DataBind();
640                                 m_lcToTest.SelectedIndex = -2;
641                                 GHTSubTestExpectedExceptionNotCaught("ArgumentOutOfRangeException");
642                         }
643                         catch (ArgumentOutOfRangeException ex)
644                         {
645                                 GHTSubTestExpectedExceptionCaught(ex);
646                         }
647                         catch (Exception ex)
648                         {
649                                 GHTSubTestUnexpectedExceptionCaught(ex);
650                         }
651                         #endregion
652                 }
653
654                 protected void ListControl_SelectedItem(Type ctrlType)
655                 {
656                         InitArray();
657                         #region "None selected"
658                         GHTListContorlSubTestBegin(ctrlType, "None selected");
659                         
660                         try
661                         {
662                                 m_lcToTest.DataSource = m_items;
663                                 m_lcToTest.DataTextField = "Name";
664                                 m_lcToTest.DataBind();
665                                 m_lcToTest.SelectedIndex = -1;
666                                 if (m_lcToTest.SelectedItem == null)
667                                 {
668                                         GHTSubTestAddResult("Test passed: SelectedItem is null");
669                                 }
670                                 else
671                                 {
672                                         GHTSubTestAddResult("Test failede: SelectedItem is not null");
673                                 }
674                         }
675                         catch (Exception ex)
676                         {
677                                 GHTSubTestUnexpectedExceptionCaught(ex);
678                         }
679                         #endregion
680                         #region "Single Item selected"
681                         GHTListContorlSubTestBegin(ctrlType, "valid value");
682                         
683                         try
684                         {
685                                 m_lcToTest.DataSource = m_items;
686                                 m_lcToTest.DataTextField = "Name";
687                                 m_lcToTest.DataBind();
688                                 m_lcToTest.SelectedIndex = 5;
689                                 Compare(m_lcToTest.SelectedItem.Text, m_items[5].Name );
690                         }
691                         catch (Exception ex)
692                         {
693                                 GHTSubTestUnexpectedExceptionCaught(ex);
694                         }
695                         #endregion
696                         #region "multiple Items selected"
697                         GHTListContorlSubTestBegin(ctrlType, "multiple Items selected");
698                         if (m_lcToTest is DropDownList)
699                         {
700                                 return;
701                         }
702                         if (m_lcToTest is ListBox)
703                         {
704                                 ((ListBox)m_lcToTest).SelectionMode = ListSelectionMode.Multiple;
705                         }
706                         try
707                         {
708                                 m_lcToTest.DataSource = m_items;
709                                 m_lcToTest.DataTextField = "Name";
710                                 m_lcToTest.DataBind();
711                                 m_lcToTest.Items[2].Selected = true;
712                                 m_lcToTest.Items[4].Selected = true;
713                                 m_lcToTest.Items[6].Selected = true;
714                                 Compare(m_lcToTest.SelectedItem.Text, m_items[2].Name );
715                         }
716                         catch (Exception ex)
717                         {
718                                 GHTSubTestUnexpectedExceptionCaught(ex);
719                         }
720
721                         #endregion
722                 }
723
724                 protected void ListControl_SelectedValue(Type ctrlType)
725                 {
726                         InitArray();
727                         #region "None selected - get"
728                         GHTListContorlSubTestBegin(ctrlType, "None selected - get");
729                         
730                         try
731                         {
732                                 m_lcToTest.DataSource = m_items;
733                                 m_lcToTest.DataValueField = "Id";
734                                 m_lcToTest.DataBind();
735                                 m_lcToTest.SelectedIndex = -1;
736                                 Compare(m_lcToTest.SelectedValue, string.Empty);
737                         }
738                         catch (Exception ex)
739                         {
740                                 GHTSubTestUnexpectedExceptionCaught(ex);
741                         }
742                         #endregion
743                         #region "valid value - get"
744                         GHTListContorlSubTestBegin(ctrlType, "valid value - get");
745                         
746                         try
747                         {
748                                 m_lcToTest.DataSource = m_items;
749                                 m_lcToTest.DataValueField = "Id";
750                                 m_lcToTest.DataBind();
751                                 m_lcToTest.SelectedIndex = 5;
752                                 Compare(m_lcToTest.SelectedValue, m_items[5].Id.ToString());
753                         }
754                         catch (Exception ex)
755                         {
756                                 GHTSubTestUnexpectedExceptionCaught(ex);
757                         }
758                         #endregion
759                         #region "valid value - set"
760                         GHTListContorlSubTestBegin(ctrlType, "valid value - set");
761                         
762                         try
763                         {
764                                 m_lcToTest.DataSource = m_items;
765                                 m_lcToTest.DataValueField = "Id";
766                                 m_lcToTest.DataBind();
767                                 m_lcToTest.SelectedValue = "5";
768                         }
769                         catch (Exception ex)
770                         {
771                                 GHTSubTestUnexpectedExceptionCaught(ex);
772                         }
773                         #endregion
774                         #region "Invalid value - set"
775                         GHTListContorlSubTestBegin(ctrlType, "Invalid value - set");
776                         
777                         try
778                         {
779                                 m_lcToTest.DataSource = m_items;
780                                 m_lcToTest.DataBind();
781                                 m_lcToTest.DataValueField = "Id";
782                                 m_lcToTest.SelectedValue = "10";
783                                 GHTSubTestExpectedExceptionNotCaught("ArgumentOutOfRangeException");
784                         }
785                         catch (ArgumentOutOfRangeException ex)
786                         {
787                                 GHTSubTestExpectedExceptionCaught(ex);
788                         }
789                         catch (Exception ex)
790                         {
791                                 GHTSubTestUnexpectedExceptionCaught(ex);
792                         }
793                         #endregion
794                 }
795
796                 #endregion
797
798                 #region "Construction"
799                 /// <summary>
800                 /// Default constructor.
801                 /// </summary>
802                 public GHTListControlBase()
803                 {
804                 }
805                 /// <summary>
806                 /// Static constructor.
807                 /// Initializes the static field m_types[].
808                 /// </summary>
809                 static GHTListControlBase()
810                 {
811                         initTypes();
812                 }
813                 #endregion
814                 
815                 #region "properties"
816                 public static Type[] TestedTypes
817                 {
818                         get
819                         {
820                                 return (Type[])(m_types.ToArray(typeof(Type)));
821                         }
822                 }
823                 #endregion
824
825                 #region "members"
826                 /// <summary>
827                 /// Holds the ListControl that is tested in the current subtest.
828                 /// </summary>
829                 private ListControl m_lcToTest;
830                 private int m_controlsCounter = 0;
831
832                 /// <summary>
833                 /// Holds all the types that are derived from ListControl, and should be tested.
834                 /// </summary>
835                 private  static readonly  ArrayList m_types = new ArrayList();
836                 /// <summary>
837                 /// Two data set to use while testing.
838                 /// Initialize this dataset using InitDataSet()
839                 /// </summary>
840                 private DataSet m_dsData;
841                 private DataTable m_dtFirst;
842                 private DataTable m_dtSecond;
843
844                 /// <summary>
845                 /// An array of Item objects that can be used as a datasource.
846                 /// initialize the array using InitArray()
847                 /// </summary>
848                 private DataItem[] m_items;
849                 #endregion
850
851                 #region "Private methods"
852                 /// <summary>
853                 /// Initializes the collection of types derived from ListControl.
854                 /// </summary>
855                 private static void initTypes()
856                 {
857                         m_types.Add(typeof(ListBox));
858                         m_types.Add(typeof(DropDownList));
859                         m_types.Add(typeof(RadioButtonList));
860                         m_types.Add(typeof(CheckBoxList));
861                 }
862                 /// <summary>
863                 /// Creates new sub test and adds a new ListControl to it.
864                 /// </summary>
865                 /// <param name="ctrlType">Actual type of the tested control</param>
866                 /// <param name="description">subtests description</param>
867                 private void GHTListContorlSubTestBegin(Type ctrlType, string description)
868                 {
869                         m_lcToTest = (ListControl)GHTElementClone(ctrlType);
870                         m_lcToTest.ID = "_ctrl" + m_controlsCounter;
871                         m_controlsCounter++;
872                         GHTSubTestBegin(description);
873                         GHTActiveSubTest.Controls.Add(m_lcToTest);
874                 }
875                 
876                 /// <summary>
877                 /// Initializes both m_dtFirst, and m_dtSecond with names ("First", "Second"), columns, and data.
878                 /// </summary>
879                 private void InitDataSet()
880                 {
881                         m_dtFirst = new DataTable("First");
882                         m_dtFirst.Columns.Add("int Column", typeof(int));
883                         m_dtFirst.Columns.Add("bool Column", typeof(bool));
884                         m_dtFirst.Columns.Add("char Column", typeof(char));
885
886                         m_dtSecond = new DataTable("Second");
887                         m_dtSecond.Columns.Add("double Column", typeof(int));
888                         m_dtSecond.Columns.Add("byte Column", typeof(bool));
889                         m_dtSecond.Columns.Add("time Column", typeof(DateTime));
890
891                         for (int i=0; i<10; i++)
892                         {
893                                 DataRow dr1 = m_dtFirst.NewRow();
894                                 dr1["int Column"] = i;
895                                 dr1["bool Column"] = ( i % 2  == 0 ) ? true : false;
896                                 dr1["char Column"] = (char)(i + 'a');
897                                 m_dtFirst.Rows.Add(dr1);
898
899                                 DataRow dr2 = m_dtSecond.NewRow();
900                                 dr2["double Column"] = double.Epsilon * i;
901                                 dr2["byte Column"] = (byte)( i % 10);
902                                 dr2["time Column"] = DateTime.Now;
903                                 m_dtSecond.Rows.Add(dr2);
904                         }
905
906                         m_dsData = new DataSet("Test dataset");
907                         m_dsData.Tables.Add(m_dtFirst);
908                         m_dsData.Tables.Add(m_dtSecond);
909                 }
910
911
912                 private void InitArray()
913                 {
914                         m_items = new DataItem[] {      new DataItem(1, "aaa"),
915                                                                                                                                                                         new DataItem(2, "bbb"),
916                                                                                                                                                                         new DataItem(3, "ccc"),
917                                                                                                                                                                         new DataItem(4, "ddd"),
918                                                                                                                                                                         new DataItem(5, "eee"),
919                                                                                                                                                                         new DataItem(6, "fff"),
920                                                                                                                                                                         new DataItem(7, "ggg")};
921                 }
922
923                 /// <summary>
924                 /// Nested class, to use as the items of the m_items array.
925                 /// </summary>
926                 private class DataItem
927                 {
928                         public DataItem(int a_id, string a_name)
929                         {
930                                 id = a_id;
931                                 name = a_name;
932                         }
933
934                         private int id;
935                         private string name;
936
937                         public int Id
938                         {
939                                 get
940                                 {
941                                         return id;
942                                 }
943                                 set
944                                 {
945                                         id = value;
946                                 }
947                         }
948
949                         public string Name
950                         {
951                                 get
952                                 {
953                                         return name;
954                                 }
955                                 set
956                                 {
957                                         name = value;
958                                 }
959
960                         }
961
962
963                         public override string ToString()
964                         {
965                                 return id.ToString() + name;
966                         }
967                 }
968         }
969         #endregion
970
971 }