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