3 // - Unit tests for System.Web.UI.WebControls.BaseDataList
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
31 using System.Collections;
32 using System.Collections.Specialized;
33 using System.ComponentModel;
37 using System.Web.UI.WebControls;
39 using NUnit.Framework;
41 namespace MonoTests.System.Web.UI.WebControls {
43 public class TestBaseDataList : BaseDataList {
45 private bool dataBindingCalled;
48 public TestBaseDataList ()
54 get { return base.TagName; }
57 public StateBag StateBag {
58 get { return base.ViewState; }
60 public bool IsDataBoundByDataSourceId {
61 get { return base.IsBoundUsingDataSourceID; }
64 public bool IsInitialized {
65 get { return base.Initialized; }
68 public bool RequiresDataBind {
69 get { return base.RequiresDataBinding; }
72 public DataSourceSelectArguments Arguments {
73 get { return base.SelectArguments; }
75 public void Add (object o)
77 base.AddParsedSubObject (o);
80 public string Render ()
82 StringWriter sw = new StringWriter ();
84 HtmlTextWriter writer = new HtmlTextWriter (sw);
86 return writer.InnerWriter.ToString ();
89 protected override void CreateControlHierarchy (bool useDataSource)
93 protected override void PrepareControlHierarchy ()
97 public void DoSelectedIndexChanged (EventArgs e)
99 OnSelectedIndexChanged (e);
101 public DataSourceSelectArguments CreateArguments ()
103 return base.CreateDataSourceSelectArguments ();
106 public IEnumerable Data ()
108 return base.GetData ();
111 public void DataBindBool (bool raise)
116 public void Ensure ()
118 base.EnsureDataBound ();
120 public bool DataBindingCalled {
121 get { return dataBindingCalled; }
122 set { dataBindingCalled = value; }
125 protected override void OnDataBinding (EventArgs e)
127 dataBindingCalled = true;
128 base.OnDataBinding (e);
130 private bool dataPropertyChangedCalled;
131 private bool dataSourceViewChangedCalled;
132 private bool initCalled;
133 private bool loadCalled;
134 private bool preRenderCalled;
136 public bool DataPropertyChangedCalled {
137 get { return dataPropertyChangedCalled; }
138 set { dataPropertyChangedCalled = value; }
141 protected override void OnDataPropertyChanged ()
143 dataPropertyChangedCalled = true;
144 base.OnDataPropertyChanged ();
147 public bool DataSourceViewChangedCalled {
148 get { return dataSourceViewChangedCalled; }
149 set { dataSourceViewChangedCalled = value; }
152 protected override void OnDataSourceViewChanged (object sender, EventArgs e)
154 dataSourceViewChangedCalled = true;
155 base.OnDataSourceViewChanged (sender, e);
158 public void BaseOnDataSourceViewChanged (object sender, EventArgs e)
160 base.OnDataSourceViewChanged (sender, e);
163 public bool InitCalled {
164 get { return initCalled; }
165 set { initCalled = value; }
168 protected internal override void OnInit (EventArgs e)
174 public void BaseOnInit (EventArgs e)
179 public bool LoadCalled {
180 get { return loadCalled; }
181 set { loadCalled = value; }
184 protected internal override void OnLoad (EventArgs e)
190 public void BaseOnLoad (EventArgs e)
195 public bool PreRenderCalled {
196 get { return preRenderCalled; }
197 set { preRenderCalled = value; }
200 protected internal override void OnPreRender (EventArgs e)
202 preRenderCalled = true;
203 base.OnPreRender (e);
206 public void BaseOnPreRender (EventArgs e)
208 base.OnPreRender (e);
212 public class TestDataSource : IListSource {
214 private ArrayList list;
217 public TestDataSource (ArrayList al)
223 public bool ContainsListCollection {
227 public IList GetList ()
233 public class Test2DataSource : WebControl, IDataSource {
235 public DataSourceView GetView (string viewName)
237 return new Test2DataSourceView (this, String.Empty);
240 public ICollection GetViewNames ()
245 public event EventHandler DataSourceChanged;
248 public class Test2DataSourceView : DataSourceView {
250 public Test2DataSourceView (IDataSource owner, string viewName)
251 : base (owner, viewName)
255 protected internal override IEnumerable ExecuteSelect (DataSourceSelectArguments arguments)
257 ArrayList al = new ArrayList (3);
258 for (int i=0; i < 3; i++)
265 public class BaseDataListTest {
267 private HtmlTextWriter GetWriter ()
269 StringWriter sw = new StringWriter ();
271 return new HtmlTextWriter (sw);
274 // IEnumerable (and IList) based
275 private IEnumerable GetData (int n)
277 ArrayList al = new ArrayList ();
278 for (int i = 0; i < n; i++) {
279 al.Add (i.ToString ());
281 return (IEnumerable) al;
285 private TestDataSource GetDataSource (int n)
287 return new TestDataSource ((ArrayList)GetData (n));
291 public void DefaultProperties ()
293 TestBaseDataList bdl = new TestBaseDataList ();
294 Assert.AreEqual ("span", bdl.Tag, "TagName");
296 Assert.AreEqual (0, bdl.Attributes.Count, "Attributes.Count-1");
297 Assert.AreEqual (0, bdl.StateBag.Count, "ViewState.Count-1");
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");
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");
322 public void NullProperties ()
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");
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");
334 // many properties can't be set without causing a InvalidCastException
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");
351 public void CleanProperties ()
353 TestBaseDataList bdl = new TestBaseDataList ();
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");
369 Assert.AreEqual (0, bdl.Attributes.Count, "Attributes.Count-1");
370 Assert.AreEqual (5, bdl.StateBag.Count, "ViewState.Count-1");
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");
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");
392 public void TableCaption ()
394 TestBaseDataList bdl = new TestBaseDataList ();
395 foreach (TableCaptionAlign tca in Enum.GetValues (typeof (TableCaptionAlign))) {
396 bdl.CaptionAlign = tca;
401 [ExpectedException (typeof (ArgumentOutOfRangeException))]
402 public void TableCaption_Int32MaxValue ()
404 TestBaseDataList bdl = new TestBaseDataList ();
405 bdl.CaptionAlign = (TableCaptionAlign)Int32.MaxValue;
409 public void DataSource_IEnumerable ()
411 TestBaseDataList bdl = new TestBaseDataList ();
412 bdl.DataSource = GetData (2);
413 Assert.IsNotNull (bdl.DataSource, "DataSource");
417 public void DataSource_IListSource ()
419 TestBaseDataList bdl = new TestBaseDataList ();
420 bdl.DataSource = GetDataSource (3);
421 Assert.IsNotNull (bdl.DataSource, "DataSource");
425 [ExpectedException (typeof (ArgumentException))]
426 public void DataSource_Other ()
428 TestBaseDataList bdl = new TestBaseDataList ();
429 bdl.DataSource = new object ();
432 // CreateControlStyle isn't overriden so we can't assign it's properties
435 [ExpectedException (typeof (InvalidCastException))]
436 public void CellPadding_InvalidCastException ()
438 TestBaseDataList bdl = new TestBaseDataList ();
439 Assert.AreEqual (-1, bdl.CellPadding, "CellPadding");
440 bdl.CellPadding = -1;
444 [ExpectedException (typeof (InvalidCastException))]
445 public void CellSpacing_InvalidCastException ()
447 TestBaseDataList bdl = new TestBaseDataList ();
448 Assert.AreEqual (0, bdl.CellSpacing, "CellSpacing");
453 [ExpectedException (typeof (InvalidCastException))]
454 public void GridLines_InvalidCastException ()
456 TestBaseDataList bdl = new TestBaseDataList ();
457 Assert.AreEqual (GridLines.Both, bdl.GridLines, "GridLines");
458 bdl.GridLines = GridLines.Both;
462 [ExpectedException (typeof (InvalidCastException))]
463 public void HorizontalAlign_InvalidCastException ()
465 TestBaseDataList bdl = new TestBaseDataList ();
466 Assert.AreEqual (HorizontalAlign.NotSet, bdl.HorizontalAlign, "HorizontalAlign");
467 bdl.HorizontalAlign = HorizontalAlign.NotSet;
471 [ExpectedException (typeof (NullReferenceException))]
472 public void IsBindableType_Null ()
474 BaseDataList.IsBindableType (null);
478 public void AddParsedSubObject ()
480 TestBaseDataList bdl = new TestBaseDataList ();
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");
491 public void Render_Empty ()
493 TestBaseDataList bdl = new TestBaseDataList ();
494 Assert.AreEqual (String.Empty, bdl.Render ());
498 public void Render ()
500 TestBaseDataList bdl = new TestBaseDataList ();
501 bdl.DataSource = GetDataSource (3);
503 Assert.AreEqual (String.Empty, bdl.Render ());
506 private bool selectedIndexChangedEvent;
508 private void SelectedIndexChangedHandler (object sender, EventArgs e)
510 selectedIndexChangedEvent = true;
514 public void Events ()
516 TestBaseDataList bdl = new TestBaseDataList ();
517 selectedIndexChangedEvent = false;
518 bdl.SelectedIndexChanged += new EventHandler (SelectedIndexChangedHandler);
519 bdl.DoSelectedIndexChanged (new EventArgs ());
520 Assert.IsTrue (selectedIndexChangedEvent, "selectedIndexChangedEvent");
524 public void OnDataBinding ()
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);
532 Assert.IsTrue (bdl.DataBindingCalled, "After DataBind");
535 public void DataSourceID ()
537 TestBaseDataList bdl = new TestBaseDataList ();
538 Assert.IsFalse (bdl.IsDataBoundByDataSourceId, "IsBoundUsingDataSourceID-1");
539 bdl.DataSourceID = "mono";
540 Assert.IsTrue (bdl.IsDataBoundByDataSourceId, "IsBoundUsingDataSourceID-2");
542 Assert.IsTrue (bdl.IsDataBoundByDataSourceId, "IsBoundUsingDataSourceID-3");
546 // LAMESPEC ??? [ExpectedException (typeof (HttpException))]
547 [ExpectedException (typeof (InvalidOperationException))]
548 public void DataSourceID_WithDataSource ()
550 Page p = new Page ();
551 TestBaseDataList bdl = new TestBaseDataList ();
553 bdl.DataSource = GetDataSource (1);
555 Test2DataSource ds = new Test2DataSource ();
559 p.Controls.Add (bdl);
560 bdl.DataSourceID = "mono";
561 Assert.IsNotNull (bdl.Data (), "GetData");
565 [ExpectedException (typeof (HttpException))]
566 [Ignore ("LAMESPEC -and/or- bad test")]
567 public void DataSource_WithDataSourceID ()
569 Test2DataSource ds = new Test2DataSource ();
571 TestBaseDataList bdl = new TestBaseDataList ();
572 Page p = new Page ();
576 p.Controls.Add (bdl);
577 bdl.DataSourceID = "mono";
578 Assert.IsNotNull (bdl.Data (), "GetData");
580 bdl.DataSource = GetDataSource (1);
585 public void EnsureDataBound_WithoutDataSourceID ()
587 TestBaseDataList bdl = new TestBaseDataList ();
588 Assert.IsFalse (bdl.DataBindingCalled, "Before EnsureDataBound");
590 Assert.IsFalse (bdl.DataBindingCalled, "After EnsureDataBound");
594 public void EnsureDataBound_WithDataSourceID ()
596 XmlDataSource ds = new XmlDataSource ();
599 TestBaseDataList bdl = new TestBaseDataList ();
600 Page p = new Page ();
603 p.Controls.Add (bdl);
604 bdl.DataSourceID = "mono";
606 Assert.IsFalse (bdl.DataBindingCalled, "Before EnsureDataBound");
608 Assert.IsFalse (bdl.DataBindingCalled, "After EnsureDataBound");
610 bdl.BaseOnLoad (EventArgs.Empty);
612 Assert.IsTrue (bdl.DataBindingCalled, "After BaseOnLoad|RequiresDataBinding");
616 public void GetData ()
618 Test2DataSource ds = new Test2DataSource ();
620 TestBaseDataList bdl = new TestBaseDataList ();
621 Page p = new Page ();
625 p.Controls.Add (bdl);
626 bdl.DataSourceID = "mono";
627 Assert.IsNotNull (bdl.Data (), "GetData");
631 public void GetData_WithoutDataSourceID ()
633 TestBaseDataList bdl = new TestBaseDataList ();
634 Assert.IsNull (bdl.Data (), "GetData");
638 [ExpectedException (typeof (HttpException))]
639 public void GetData_WithUnexistingDataSourceID ()
641 TestBaseDataList bdl = new TestBaseDataList ();
642 bdl.Page = new Page ();
643 bdl.DataSourceID = "mono";
648 public void OnDataBinding_True ()
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");
658 public void OnDataBinding_False ()
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");
668 public void OnDataPropertyChanged ()
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");
676 bdl.DataPropertyChangedCalled = false;
677 bdl.DataSource = null;
678 Assert.IsTrue (bdl.DataPropertyChangedCalled, "OnDataPropertyChanged-DataSource");
679 Assert.IsFalse (bdl.IsInitialized, "Initialized-DataSource");
681 bdl.DataPropertyChangedCalled = false;
682 bdl.DataSourceID = String.Empty;
683 Assert.IsTrue (bdl.DataPropertyChangedCalled, "OnDataPropertyChanged-DataSourceID");
684 Assert.IsFalse (bdl.IsInitialized, "Initialized-DataSourceID");
688 public void OnInit ()
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
698 public void OnDataSourceViewChanged ()
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");
707 public void OnLoad_WithoutPage ()
709 TestBaseDataList bdl = new TestBaseDataList ();
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");
720 public void OnLoad_WithoutPageWithoutViewState ()
722 TestBaseDataList bdl = new TestBaseDataList ();
723 bdl.EnableViewState = false;
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");
734 public void OnLoad_WithPage ()
736 TestBaseDataList bdl = new TestBaseDataList ();
737 Page p = new Page ();
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");
748 public void OnLoad_WithPageWithoutViewState ()
750 TestBaseDataList bdl = new TestBaseDataList ();
751 Page p = new Page ();
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");
763 public void OnLoad_WithDataSource ()
765 XmlDataSource ds = new XmlDataSource ();
767 TestBaseDataList bdl = new TestBaseDataList ();
768 Page p = new Page ();
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");
781 public void IsBindableType ()
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");
803 Assert.IsFalse (BaseDataList.IsBindableType (this.GetType ()), "this");
807 public void SupportsDisabledAttribute ()
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");
815 p.RenderingCompatibility = new Version (3, 5);
816 Assert.AreEqual (ver35, p.RenderingCompatibility, "#A2-1");
817 Assert.IsTrue (p.SupportsDisabledAttribute, "#A2-2");