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