2007-01-30 Adar Wesley <adarw@mainsofot.com>
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / BaseDataListTest.cs
1 //
2 // BaseDataListTest.cs
3 //      - Unit tests for System.Web.UI.WebControls.BaseDataList
4 //
5 // Author:
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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
30 using System;
31 using System.Collections;
32 using System.Collections.Specialized;
33 using System.ComponentModel;
34 using System.IO;
35 using System.Web;
36 using System.Web.UI;
37 using System.Web.UI.WebControls;
38
39 using NUnit.Framework;
40
41 namespace MonoTests.System.Web.UI.WebControls {
42
43         public class TestBaseDataList : BaseDataList {
44
45                 private bool dataBindingCalled;
46
47
48                 public TestBaseDataList ()
49                         : base ()
50                 {
51                 }
52
53                 public string Tag {
54                         get { return base.TagName; }
55                 }
56
57                 public StateBag StateBag {
58                         get { return base.ViewState; }
59                 }
60 #if NET_2_0
61                 public bool IsDataBoundByDataSourceId {
62                         get { return base.IsBoundUsingDataSourceID; }
63                 }
64
65                 public bool IsInitialized {
66                         get { return base.Initialized; }
67                 }
68
69                 public bool RequiresDataBind {
70                         get { return base.RequiresDataBinding; }
71                 }
72
73                 public DataSourceSelectArguments Arguments {
74                         get { return base.SelectArguments; }
75                 }
76 #endif
77                 public void Add (object o)
78                 {
79                         base.AddParsedSubObject (o);
80                 }
81
82                 public string Render ()
83                 {
84                         StringWriter sw = new StringWriter ();
85                         sw.NewLine = "\n";
86                         HtmlTextWriter writer = new HtmlTextWriter (sw);
87                         base.Render (writer);
88                         return writer.InnerWriter.ToString ();
89                 }
90
91                 protected override void CreateControlHierarchy (bool useDataSource)
92                 {
93                 }
94
95                 protected override void PrepareControlHierarchy ()
96                 {
97                 }
98
99                 public void DoSelectedIndexChanged (EventArgs e)
100                 {
101                         OnSelectedIndexChanged (e);
102                 }
103 #if NET_2_0
104                 public DataSourceSelectArguments CreateArguments ()
105                 {
106                         return base.CreateDataSourceSelectArguments ();
107                 }
108
109                 public IEnumerable Data ()
110                 {
111                         return base.GetData ();
112                 }
113
114                 public void DataBindBool (bool raise)
115                 {
116                         DataBind (raise);
117                 }
118
119                 public void Ensure ()
120                 {
121                         base.EnsureDataBound ();
122                 }
123 #endif
124                 public bool DataBindingCalled {
125                         get { return dataBindingCalled; }
126                         set { dataBindingCalled = value; }
127                 }
128
129                 protected override void OnDataBinding (EventArgs e)
130                 {
131                         dataBindingCalled = true;
132                         base.OnDataBinding (e);
133                 }
134 #if NET_2_0
135                 private bool dataPropertyChangedCalled;
136                 private bool dataSourceViewChangedCalled;
137                 private bool initCalled;
138                 private bool loadCalled;
139                 private bool preRenderCalled;
140
141                 public bool DataPropertyChangedCalled {
142                         get { return dataPropertyChangedCalled; }
143                         set { dataPropertyChangedCalled = value; }
144                 }
145
146                 protected override void OnDataPropertyChanged ()
147                 {
148                         dataPropertyChangedCalled = true;
149                         base.OnDataPropertyChanged ();
150                 }
151
152                 public bool DataSourceViewChangedCalled {
153                         get { return dataSourceViewChangedCalled; }
154                         set { dataSourceViewChangedCalled = value; }
155                 }
156
157                 protected override void OnDataSourceViewChanged (object sender, EventArgs e)
158                 {
159                         dataSourceViewChangedCalled = true;
160                         base.OnDataSourceViewChanged (sender, e);
161                 }
162
163                 public void BaseOnDataSourceViewChanged (object sender, EventArgs e)
164                 {
165                         base.OnDataSourceViewChanged (sender, e);
166                 }
167
168                 public bool InitCalled {
169                         get { return initCalled; }
170                         set { initCalled = value; }
171                 }
172
173                 protected override void OnInit (EventArgs e)
174                 {
175                         initCalled = true;
176                         base.OnInit (e);
177                 }
178
179                 public void BaseOnInit (EventArgs e)
180                 {
181                         base.OnInit (e);
182                 }
183
184                 public bool LoadCalled {
185                         get { return loadCalled; }
186                         set { loadCalled = value; }
187                 }
188
189                 protected override void OnLoad (EventArgs e)
190                 {
191                         loadCalled = true;
192                         base.OnLoad (e);
193                 }
194
195                 public void BaseOnLoad (EventArgs e)
196                 {
197                         base.OnLoad (e);
198                 }
199
200                 public bool PreRenderCalled {
201                         get { return preRenderCalled; }
202                         set { preRenderCalled = value; }
203                 }
204
205                 protected override void OnPreRender (EventArgs e)
206                 {
207                         preRenderCalled = true;
208                         base.OnPreRender (e);
209                 }
210
211                 public void BaseOnPreRender (EventArgs e)
212                 {
213                         base.OnPreRender (e);
214                 }
215 #endif
216         }
217
218         public class TestDataSource : IListSource {
219
220                 private ArrayList list;
221
222
223                 public TestDataSource (ArrayList al)
224                 {
225                         list = al;
226                 }
227
228
229                 public bool ContainsListCollection {
230                         get { return true; }
231                 }
232
233                 public IList GetList ()
234                 {
235                         return list;
236                 }
237         }
238
239 #if NET_2_0
240         public class Test2DataSource : WebControl, IDataSource {
241
242                 public DataSourceView GetView (string viewName)
243                 {
244                         return new Test2DataSourceView (this, String.Empty);
245                 }
246
247                 public ICollection GetViewNames ()
248                 {
249                         return null;
250                 }
251
252                 public event EventHandler DataSourceChanged;
253         }
254
255         public class Test2DataSourceView : DataSourceView {
256
257                 public Test2DataSourceView (IDataSource owner, string viewName)
258                         : base (owner, viewName)
259                 {
260                 }
261
262                 protected override IEnumerable ExecuteSelect (DataSourceSelectArguments arguments)
263                 {
264                         ArrayList al = new ArrayList (3);
265                         for (int i=0; i < 3; i++)
266                                 al.Add (i+1);
267                         return al;
268                 }
269         }
270 #endif
271
272         [TestFixture]
273         public class BaseDataListTest {
274
275                 private HtmlTextWriter GetWriter ()
276                 {
277                         StringWriter sw = new StringWriter ();
278                         sw.NewLine = "\n";
279                         return new HtmlTextWriter (sw);
280                 }
281
282                 // IEnumerable (and IList) based
283                 private IEnumerable GetData (int n)
284                 {
285                         ArrayList al = new ArrayList ();
286                         for (int i = 0; i < n; i++) {
287                                 al.Add (i.ToString ());
288                         }
289                         return (IEnumerable) al;
290                 }
291
292                 // IListSource based
293                 private TestDataSource GetDataSource (int n)
294                 {
295                         return new TestDataSource ((ArrayList)GetData (n));
296                 }
297
298                 [Test]
299                 public void DefaultProperties ()
300                 {
301                         TestBaseDataList bdl = new TestBaseDataList ();
302                         Assert.AreEqual ("span", bdl.Tag, "TagName");
303
304                         Assert.AreEqual (0, bdl.Attributes.Count, "Attributes.Count-1");
305                         Assert.AreEqual (0, bdl.StateBag.Count, "ViewState.Count-1");
306                         
307                         Assert.AreEqual (String.Empty, bdl.Caption, "Caption");
308                         Assert.AreEqual (TableCaptionAlign.NotSet, bdl.CaptionAlign, "CaptionAlign");
309                         Assert.AreEqual (-1, bdl.CellPadding, "CellPadding");
310                         Assert.AreEqual (0, bdl.CellSpacing, "CellSpacing");
311                         Assert.AreEqual (0, bdl.Controls.Count, "Controls.Count");
312                         Assert.AreEqual (String.Empty, bdl.DataKeyField, "DataKeyField");
313                         Assert.AreEqual (String.Empty, bdl.DataMember, "DataMember");
314                         Assert.IsNull (bdl.DataSource, "DataSource");
315                         Assert.AreEqual (GridLines.Both, bdl.GridLines, "GridLines");
316                         Assert.AreEqual (HorizontalAlign.NotSet, bdl.HorizontalAlign, "HorizontalAlign");
317                         Assert.IsFalse (bdl.UseAccessibleHeader, "UseAccessibleHeader");
318 #if NET_2_0
319                         Assert.AreEqual (String.Empty, bdl.DataSourceID, "DataSourceID");
320 #endif
321                         Assert.AreEqual (0, bdl.Attributes.Count, "Attributes.Count-2");
322                         Assert.AreEqual (0, bdl.StateBag.Count, "ViewState.Count-2");
323
324                         Assert.AreEqual (0, bdl.DataKeys.Count, "DataKeys.Count");
325                         Assert.AreEqual (0, bdl.Attributes.Count, "Attributes.Count-3");
326                         // triggered by DataKeys, which makes DataKeysArray store its value.
327                         Assert.AreEqual (1, bdl.StateBag.Count, "ViewState.Count-3");
328                         Assert.AreEqual (typeof (ArrayList), bdl.StateBag ["DataKeys"].GetType (), "ViewState.Value-1");
329                 }
330
331                 [Test]
332                 public void NullProperties ()
333                 {
334                         TestBaseDataList bdl = new TestBaseDataList ();
335                         Assert.AreEqual (0, bdl.Attributes.Count, "Attributes.Count-1");
336                         Assert.AreEqual (0, bdl.StateBag.Count, "ViewState.Count-1");
337
338                         bdl.Caption = null;
339                         Assert.AreEqual (String.Empty, bdl.Caption, "Caption");
340                         bdl.CaptionAlign = TableCaptionAlign.NotSet;
341                         Assert.AreEqual (TableCaptionAlign.NotSet, bdl.CaptionAlign, "CaptionAlign");
342                         Assert.AreEqual (1, bdl.StateBag.Count, "ViewState.Count-2");
343
344                         // many properties can't be set without causing a InvalidCastException
345
346                         bdl.DataKeyField = null;
347                         Assert.AreEqual (String.Empty, bdl.DataKeyField, "DataKeyField");
348                         bdl.DataMember = null;
349                         Assert.AreEqual (String.Empty, bdl.DataMember, "DataMember");
350                         bdl.DataSource = null;
351                         Assert.IsNull (bdl.DataSource, "DataSource");
352                         bdl.UseAccessibleHeader = false;
353                         Assert.IsFalse (bdl.UseAccessibleHeader, "UseAccessibleHeader");
354 #if NET_2_0
355                         bdl.DataSourceID = String.Empty;
356                         Assert.AreEqual (String.Empty, bdl.DataSourceID, "DataSourceID");
357                         Assert.AreEqual (3, bdl.StateBag.Count, "ViewState.Count-3");
358 #else
359                         Assert.AreEqual (2, bdl.StateBag.Count, "ViewState.Count-3");
360 #endif
361                         Assert.AreEqual (0, bdl.Attributes.Count, "Attributes.Count-2");
362                 }
363
364                 [Test]
365                 public void CleanProperties ()
366                 {
367                         TestBaseDataList bdl = new TestBaseDataList ();
368
369                         bdl.Caption = "Mono";
370                         Assert.AreEqual ("Mono", bdl.Caption, "Caption");
371                         bdl.CaptionAlign = TableCaptionAlign.Top;
372                         Assert.AreEqual (TableCaptionAlign.Top, bdl.CaptionAlign, "CaptionAlign");
373                         // many properties can't be set without causing a InvalidCastException
374                         bdl.DataKeyField = "key";
375                         Assert.AreEqual ("key", bdl.DataKeyField, "DataKeyField");
376                         bdl.DataMember = "member";
377                         Assert.AreEqual ("member", bdl.DataMember, "DataMember");
378                         bdl.DataSource = GetData (2);
379                         Assert.IsNotNull (bdl.DataSource, "DataSource");
380                         bdl.UseAccessibleHeader = true;
381                         Assert.IsTrue (bdl.UseAccessibleHeader, "UseAccessibleHeader");
382
383                         Assert.AreEqual (0, bdl.Attributes.Count, "Attributes.Count-1");
384                         Assert.AreEqual (5, bdl.StateBag.Count, "ViewState.Count-1");
385
386                         bdl.Caption = null;
387                         Assert.AreEqual (String.Empty, bdl.Caption, "-Caption");
388                         bdl.CaptionAlign = TableCaptionAlign.NotSet;
389                         Assert.AreEqual (TableCaptionAlign.NotSet, bdl.CaptionAlign, "-CaptionAlign");
390                         // many properties can't be set without causing a InvalidCastException
391                         bdl.DataKeyField = null;
392                         Assert.AreEqual (String.Empty, bdl.DataKeyField, "-DataKeyField");
393                         bdl.DataMember = null;
394                         Assert.AreEqual (String.Empty, bdl.DataMember, "-DataMember");
395                         bdl.DataSource = null;
396                         Assert.IsNull (bdl.DataSource, "-DataSource");
397                         bdl.UseAccessibleHeader = false;
398                         Assert.IsFalse (bdl.UseAccessibleHeader, "-UseAccessibleHeader");
399
400                         Assert.AreEqual (0, bdl.Attributes.Count, "Attributes.Count-2");
401                         // CaptionAlign and UseAccessibleHeader aren't removed
402                         Assert.AreEqual (2, bdl.StateBag.Count, "ViewState.Count-2");
403                 }
404
405                 [Test]
406                 public void TableCaption ()
407                 {
408                         TestBaseDataList bdl = new TestBaseDataList ();
409                         foreach (TableCaptionAlign tca in Enum.GetValues (typeof (TableCaptionAlign))) {
410                                 bdl.CaptionAlign = tca;
411                         }
412                 }
413
414                 [Test]
415                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
416                 public void TableCaption_Int32MaxValue ()
417                 {
418                         TestBaseDataList bdl = new TestBaseDataList ();
419                         bdl.CaptionAlign = (TableCaptionAlign)Int32.MaxValue;
420                 }
421
422                 [Test]
423                 public void DataSource_IEnumerable ()
424                 {
425                         TestBaseDataList bdl = new TestBaseDataList ();
426                         bdl.DataSource = GetData (2);
427                         Assert.IsNotNull (bdl.DataSource, "DataSource");
428                 }
429
430                 [Test]
431                 public void DataSource_IListSource ()
432                 {
433                         TestBaseDataList bdl = new TestBaseDataList ();
434                         bdl.DataSource = GetDataSource (3);
435                         Assert.IsNotNull (bdl.DataSource, "DataSource");
436                 }
437
438                 [Test]
439                 [ExpectedException (typeof (ArgumentException))]
440                 public void DataSource_Other ()
441                 {
442                         TestBaseDataList bdl = new TestBaseDataList ();
443                         bdl.DataSource = new object ();
444                 }
445
446                 // CreateControlStyle isn't overriden so we can't assign it's properties
447
448                 [Test]
449                 [ExpectedException (typeof (InvalidCastException))]
450                 public void CellPadding_InvalidCastException ()
451                 {
452                         TestBaseDataList bdl = new TestBaseDataList ();
453                         Assert.AreEqual (-1, bdl.CellPadding, "CellPadding");
454                         bdl.CellPadding = -1;
455                 }
456
457                 [Test]
458                 [ExpectedException (typeof (InvalidCastException))]
459                 public void CellSpacing_InvalidCastException ()
460                 {
461                         TestBaseDataList bdl = new TestBaseDataList ();
462                         Assert.AreEqual (0, bdl.CellSpacing, "CellSpacing");
463                         bdl.CellSpacing = 0;
464                 }
465
466                 [Test]
467                 [ExpectedException (typeof (InvalidCastException))]
468                 public void GridLines_InvalidCastException ()
469                 {
470                         TestBaseDataList bdl = new TestBaseDataList ();
471                         Assert.AreEqual (GridLines.Both, bdl.GridLines, "GridLines");
472                         bdl.GridLines = GridLines.Both;
473                 }
474
475                 [Test]
476                 [ExpectedException (typeof (InvalidCastException))]
477                 public void HorizontalAlign_InvalidCastException ()
478                 {
479                         TestBaseDataList bdl = new TestBaseDataList ();
480                         Assert.AreEqual (HorizontalAlign.NotSet, bdl.HorizontalAlign, "HorizontalAlign");
481                         bdl.HorizontalAlign = HorizontalAlign.NotSet;
482                 }
483
484                 [Test]
485                 [ExpectedException (typeof (NullReferenceException))]
486                 public void IsBindableType_Null ()
487                 {
488                         BaseDataList.IsBindableType (null);
489                 }
490
491                 [Test]
492                 public void AddParsedSubObject ()
493                 {
494                         TestBaseDataList bdl = new TestBaseDataList ();
495                         bdl.Add (null);
496                         bdl.Add (new LiteralControl ("mono"));
497                         bdl.Add (new DataListItem (0, ListItemType.Item));
498                         bdl.Add (String.Empty);
499                         bdl.Add (new Control ());
500                         Assert.AreEqual (0, bdl.Controls.Count, "Controls");
501                         Assert.AreEqual (0, bdl.StateBag.Count, "StateBag");
502                 }
503
504                 [Test]
505                 public void Render_Empty ()
506                 {
507                         TestBaseDataList bdl = new TestBaseDataList ();
508                         Assert.AreEqual (String.Empty, bdl.Render ());
509                 }
510
511                 [Test]
512                 public void Render ()
513                 {
514                         TestBaseDataList bdl = new TestBaseDataList ();
515                         bdl.DataSource = GetDataSource (3);
516                         bdl.DataBind ();
517                         Assert.AreEqual (String.Empty, bdl.Render ());
518                 }
519
520                 private bool selectedIndexChangedEvent;
521
522                 private void SelectedIndexChangedHandler (object sender, EventArgs e)
523                 {
524                         selectedIndexChangedEvent = true;
525                 }
526
527                 [Test]
528                 public void Events ()
529                 {
530                         TestBaseDataList bdl = new TestBaseDataList ();
531                         selectedIndexChangedEvent = false;
532                         bdl.SelectedIndexChanged += new EventHandler (SelectedIndexChangedHandler);
533                         bdl.DoSelectedIndexChanged (new EventArgs ());
534                         Assert.IsTrue (selectedIndexChangedEvent, "selectedIndexChangedEvent");
535                 }
536
537                 [Test]
538                 public void OnDataBinding ()
539                 {
540                         // does DataBind calls base.OnDataBinding (like most sample do)
541                         // or does it call the overriden OnDataBinding (which seems logical)
542                         TestBaseDataList bdl = new TestBaseDataList ();
543                         Assert.IsFalse (bdl.DataBindingCalled, "Before DataBind");
544                         bdl.DataSource = GetDataSource (3);
545                         bdl.DataBind ();
546                         Assert.IsTrue (bdl.DataBindingCalled, "After DataBind");
547                 }
548 #if NET_2_0
549                 [Test]
550                 public void DataSourceID ()
551                 {
552                         TestBaseDataList bdl = new TestBaseDataList ();
553                         Assert.IsFalse (bdl.IsDataBoundByDataSourceId, "IsBoundUsingDataSourceID-1");
554                         bdl.DataSourceID = "mono";
555                         Assert.IsTrue (bdl.IsDataBoundByDataSourceId, "IsBoundUsingDataSourceID-2");
556                         bdl.DataBind ();
557                         Assert.IsTrue (bdl.IsDataBoundByDataSourceId, "IsBoundUsingDataSourceID-3");
558                 }
559
560                 [Test]
561                 // LAMESPEC ??? [ExpectedException (typeof (HttpException))]
562                 [ExpectedException (typeof (InvalidOperationException))]
563                 public void DataSourceID_WithDataSource ()
564                 {
565                         Page p = new Page ();
566                         TestBaseDataList bdl = new TestBaseDataList ();
567                         bdl.Page = p;
568                         bdl.DataSource = GetDataSource (1);
569
570                         Test2DataSource ds = new Test2DataSource ();
571                         ds.ID = "mono";
572                         ds.Page = p;
573                         p.Controls.Add (ds);
574                         p.Controls.Add (bdl);
575                         bdl.DataSourceID = "mono";
576                         Assert.IsNotNull (bdl.Data (), "GetData");
577                 }
578
579                 [Test]
580                 [ExpectedException (typeof (HttpException))]
581                 [Ignore ("LAMESPEC -and/or- bad test")]
582                 public void DataSource_WithDataSourceID ()
583                 {
584                         Test2DataSource ds = new Test2DataSource ();
585                         ds.ID = "mono";
586                         TestBaseDataList bdl = new TestBaseDataList ();
587                         Page p = new Page ();
588                         bdl.Page = p;
589                         ds.Page = p;
590                         p.Controls.Add (ds);
591                         p.Controls.Add (bdl);
592                         bdl.DataSourceID = "mono";
593                         Assert.IsNotNull (bdl.Data (), "GetData");
594
595                         bdl.DataSource = GetDataSource (1);
596                         bdl.DataBind ();
597                 }
598
599                 [Test]
600                 public void EnsureDataBound_WithoutDataSourceID ()
601                 {
602                         TestBaseDataList bdl = new TestBaseDataList ();
603                         Assert.IsFalse (bdl.DataBindingCalled, "Before EnsureDataBound");
604                         bdl.Ensure ();
605                         Assert.IsFalse (bdl.DataBindingCalled, "After EnsureDataBound");
606                 }
607
608                 [Test]
609                 public void EnsureDataBound_WithDataSourceID ()
610                 {
611                         XmlDataSource ds = new XmlDataSource ();
612                         ds.Data = "";
613                         ds.ID = "mono";
614                         TestBaseDataList bdl = new TestBaseDataList ();
615                         Page p = new Page ();
616                         bdl.Page = p;
617                         p.Controls.Add (ds);
618                         p.Controls.Add (bdl);
619                         bdl.DataSourceID = "mono";
620
621                         Assert.IsFalse (bdl.DataBindingCalled, "Before EnsureDataBound");
622                         bdl.Ensure ();
623                         Assert.IsFalse (bdl.DataBindingCalled, "After EnsureDataBound");
624
625                         bdl.BaseOnLoad (EventArgs.Empty);
626                         bdl.Ensure ();
627                         Assert.IsTrue (bdl.DataBindingCalled, "After BaseOnLoad|RequiresDataBinding");
628                 }
629
630                 [Test]
631                 public void GetData ()
632                 {
633                         Test2DataSource ds = new Test2DataSource ();
634                         ds.ID = "mono";
635                         TestBaseDataList bdl = new TestBaseDataList ();
636                         Page p = new Page ();
637                         bdl.Page = p;
638                         ds.Page = p;
639                         p.Controls.Add (ds);
640                         p.Controls.Add (bdl);
641                         bdl.DataSourceID = "mono";
642                         Assert.IsNotNull (bdl.Data (), "GetData");
643                 }
644
645                 [Test]
646                 public void GetData_WithoutDataSourceID ()
647                 {
648                         TestBaseDataList bdl = new TestBaseDataList ();
649                         Assert.IsNull (bdl.Data (), "GetData");
650                 }
651
652                 [Test]
653                 [ExpectedException (typeof (HttpException))]
654                 public void GetData_WithUnexistingDataSourceID ()
655                 {
656                         TestBaseDataList bdl = new TestBaseDataList ();
657                         bdl.Page = new Page ();
658                         bdl.DataSourceID = "mono";
659                         bdl.Data ();
660                 }
661
662                 [Test]
663                 public void OnDataBinding_True ()
664                 {
665                         TestBaseDataList bdl = new TestBaseDataList ();
666                         Assert.IsFalse (bdl.DataBindingCalled, "Before DataBind");
667                         bdl.DataSource = GetDataSource (3);
668                         bdl.DataBindBool (true);
669                         Assert.IsTrue (bdl.DataBindingCalled, "After DataBind");
670                 }
671
672                 [Test]
673                 public void OnDataBinding_False ()
674                 {
675                         TestBaseDataList bdl = new TestBaseDataList ();
676                         Assert.IsFalse (bdl.DataBindingCalled, "Before DataBind");
677                         bdl.DataSource = GetDataSource (3);
678                         bdl.DataBindBool (false);
679                         Assert.IsFalse (bdl.DataBindingCalled, "After DataBind");
680                 }
681
682                 [Test]
683                 public void OnDataPropertyChanged ()
684                 {
685                         TestBaseDataList bdl = new TestBaseDataList ();
686                         bdl.DataPropertyChangedCalled = false;
687                         bdl.DataMember = String.Empty;
688                         Assert.IsTrue (bdl.DataPropertyChangedCalled, "OnDataPropertyChanged-DataMember");
689                         Assert.IsFalse (bdl.IsInitialized, "Initialized-DataMember");
690
691                         bdl.DataPropertyChangedCalled = false;
692                         bdl.DataSource = null;
693                         Assert.IsTrue (bdl.DataPropertyChangedCalled, "OnDataPropertyChanged-DataSource");
694                         Assert.IsFalse (bdl.IsInitialized, "Initialized-DataSource");
695
696                         bdl.DataPropertyChangedCalled = false;
697                         bdl.DataSourceID = String.Empty;
698                         Assert.IsTrue (bdl.DataPropertyChangedCalled, "OnDataPropertyChanged-DataSourceID");
699                         Assert.IsFalse (bdl.IsInitialized, "Initialized-DataSourceID");
700                 }
701
702                 [Test]
703                 public void OnInit ()
704                 {
705                         TestBaseDataList bdl = new TestBaseDataList ();
706                         Assert.IsFalse (bdl.IsInitialized, "Initialized-1");
707                         bdl.BaseOnInit (EventArgs.Empty);
708                         Assert.IsFalse (bdl.IsInitialized, "Initialized-2");
709                         // OnInit doesn't set Initialized to true
710                 }
711
712                 [Test]
713                 public void OnDataSourceViewChanged ()
714                 {
715                         TestBaseDataList bdl = new TestBaseDataList ();
716                         Assert.IsFalse (bdl.RequiresDataBind, "RequiresDataBind-1");
717                         bdl.BaseOnDataSourceViewChanged (this, EventArgs.Empty);
718                         Assert.IsTrue (bdl.RequiresDataBind, "RequiresDataBind-2");
719                 }
720
721                 [Test]
722                 public void OnLoad_WithoutPage ()
723                 {
724                         TestBaseDataList bdl = new TestBaseDataList ();
725
726                         Assert.IsFalse (bdl.IsDataBoundByDataSourceId, "IsBoundUsingDataSourceID");
727                         Assert.IsTrue (bdl.EnableViewState, "EnabledViewState");
728                         Assert.IsNull (bdl.Page, "Page");
729                         bdl.BaseOnLoad (EventArgs.Empty);
730                         Assert.IsTrue (bdl.IsInitialized, "IsInitialized");
731                         Assert.IsFalse (bdl.RequiresDataBind, "RequiresDataBind");
732                 }
733
734                 [Test]
735                 public void OnLoad_WithoutPageWithoutViewState ()
736                 {
737                         TestBaseDataList bdl = new TestBaseDataList ();
738                         bdl.EnableViewState = false;
739
740                         Assert.IsFalse (bdl.IsDataBoundByDataSourceId, "IsBoundUsingDataSourceID");
741                         Assert.IsFalse (bdl.EnableViewState, "EnabledViewState");
742                         Assert.IsNull (bdl.Page, "Page");
743                         bdl.BaseOnLoad (EventArgs.Empty);
744                         Assert.IsTrue (bdl.IsInitialized, "IsInitialized");
745                         Assert.IsFalse (bdl.RequiresDataBind, "RequiresDataBind");
746                 }
747
748                 [Test]
749                 public void OnLoad_WithPage ()
750                 {
751                         TestBaseDataList bdl = new TestBaseDataList ();
752                         Page p = new Page ();
753                         bdl.Page = p;
754                         Assert.IsFalse (bdl.IsDataBoundByDataSourceId, "IsBoundUsingDataSourceID-2");
755                         Assert.IsTrue (bdl.EnableViewState, "EnabledViewState-2");
756                         Assert.IsFalse (bdl.Page.IsPostBack, "IsPostBack-2");
757                         bdl.BaseOnLoad (EventArgs.Empty);
758                         Assert.IsTrue (bdl.IsInitialized, "IsInitialized-2");
759                         Assert.IsTrue (bdl.RequiresDataBind, "RequiresDataBind-2");
760                 }
761
762                 [Test]
763                 public void OnLoad_WithPageWithoutViewState ()
764                 {
765                         TestBaseDataList bdl = new TestBaseDataList ();
766                         Page p = new Page ();
767                         bdl.Page = p;
768                         bdl.EnableViewState = false;
769                         Assert.IsFalse (bdl.IsDataBoundByDataSourceId, "IsBoundUsingDataSourceID");
770                         Assert.IsFalse (bdl.EnableViewState, "EnabledViewState");
771                         Assert.IsFalse (bdl.Page.IsPostBack, "IsPostBack");
772                         bdl.BaseOnLoad (EventArgs.Empty);
773                         Assert.IsTrue (bdl.IsInitialized, "IsInitialized");
774                         Assert.IsTrue (bdl.RequiresDataBind, "RequiresDataBind");
775                 }
776
777                 [Test]
778                 public void OnLoad_WithDataSource ()
779                 {
780                         XmlDataSource ds = new XmlDataSource ();
781                         ds.ID = "mono";
782                         TestBaseDataList bdl = new TestBaseDataList ();
783                         Page p = new Page ();
784                         bdl.Page = p;
785                         p.Controls.Add (ds);
786                         p.Controls.Add (bdl);
787                         bdl.DataSourceID = "mono";
788                         Assert.IsTrue (bdl.IsDataBoundByDataSourceId, "IsBoundUsingDataSourceID");
789                         Assert.IsTrue (bdl.EnableViewState, "EnabledViewState");
790                         Assert.IsFalse (bdl.Page.IsPostBack, "IsPostBack");
791                         bdl.BaseOnLoad (EventArgs.Empty);
792                         Assert.IsTrue (bdl.IsInitialized, "IsInitialized");
793                         Assert.IsTrue (bdl.RequiresDataBind, "RequiresDataBind");
794                 }
795 #endif
796                 [Test]
797                 public void IsBindableType ()
798                 {
799                         // documented
800                         Assert.IsTrue (BaseDataList.IsBindableType (typeof (bool)), "bool");
801                         Assert.IsTrue (BaseDataList.IsBindableType (typeof (byte)), "byte");
802                         Assert.IsTrue (BaseDataList.IsBindableType (typeof (sbyte)), "sbyte");
803                         Assert.IsTrue (BaseDataList.IsBindableType (typeof (short)), "short");
804                         Assert.IsTrue (BaseDataList.IsBindableType (typeof (ushort)), "ushort");
805                         Assert.IsTrue (BaseDataList.IsBindableType (typeof (int)), "int");
806                         Assert.IsTrue (BaseDataList.IsBindableType (typeof (uint)), "uint");
807                         Assert.IsTrue (BaseDataList.IsBindableType (typeof (long)), "long");
808                         Assert.IsTrue (BaseDataList.IsBindableType (typeof (ulong)), "ulong");
809                         Assert.IsTrue (BaseDataList.IsBindableType (typeof (char)), "char");
810                         Assert.IsTrue (BaseDataList.IsBindableType (typeof (double)), "double");
811                         Assert.IsTrue (BaseDataList.IsBindableType (typeof (float)), "float");
812                         Assert.IsTrue (BaseDataList.IsBindableType (typeof (DateTime)), "DateTime");
813                         Assert.IsTrue (BaseDataList.IsBindableType (typeof (decimal)), "decimal");
814                         Assert.IsTrue (BaseDataList.IsBindableType (typeof (string)), "string");
815                         // and others (from TypeCode)
816                         Assert.IsFalse (BaseDataList.IsBindableType (typeof (object)), "object");
817                         Assert.IsFalse (BaseDataList.IsBindableType (typeof (DBNull)), "DBNull");
818                         // and junk
819                         Assert.IsFalse (BaseDataList.IsBindableType (this.GetType ()), "this");
820                 }
821         }
822 }