2 // Tests for System.Web.UI.WebControls.BaseDataBoundControl.cs
5 // Chris Toshok (toshok@ximian.com)
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using NUnit.Framework;
34 using System.Globalization;
37 using System.Web.UI.WebControls;
39 namespace MonoTests.System.Web.UI.WebControls
42 public class BaseDataBoundControlTest {
43 class Poker : BaseDataBoundControl {
45 public bool OnDataPropertyChangedCalled;
46 public bool ValidateDataSourceCalled;
52 public object SaveState () {
53 return SaveViewState ();
56 public void LoadState (object state) {
57 LoadViewState (state);
60 protected override void PerformSelect ()
62 Assert.IsTrue (RequiresDataBinding);
63 //Console.WriteLine ("PerformSelect\n{0}", Environment.StackTrace);
66 protected override void ValidateDataSource (object dataSource)
68 ValidateDataSourceCalled = true;
69 //Console.WriteLine ("PerformSelect\n{0}", Environment.StackTrace);
72 public bool GetIsBoundUsingDataSourceID ()
74 return IsBoundUsingDataSourceID;
77 public bool GetInitialized ()
82 protected override void OnDataPropertyChanged () {
83 base.OnDataPropertyChanged ();
84 OnDataPropertyChangedCalled = true;
87 public void SetRequiresDataBinding (bool val)
89 RequiresDataBinding = val;
92 public bool GetRequiresDataBinding ()
94 return RequiresDataBinding;
97 public override void DataBind ()
99 Assert.IsTrue (RequiresDataBinding);
101 Assert.IsTrue (RequiresDataBinding);
104 public void DoEnsureDataBound ()
106 Assert.IsTrue (RequiresDataBinding);
108 Assert.IsTrue (RequiresDataBinding);
113 public void Defaults ()
115 Poker p = new Poker ();
117 Assert.IsNull (p.DataSource, "A1");
118 Assert.AreEqual ("", p.DataSourceID, "A2");
119 Assert.IsFalse (p.GetIsBoundUsingDataSourceID(), "A3");
120 Assert.IsFalse (p.GetInitialized(), "A4");
124 public void ViewState ()
126 Poker p = new Poker ();
127 Poker copy = new Poker ();
129 p.DataSourceID = "hi";
130 object state = p.SaveState ();
131 copy.LoadState (state);
133 Assert.AreEqual ("hi", copy.DataSourceID, "A1");
137 public void OnDataPropertyChanged ()
139 Poker p = new Poker ();
140 Assert.IsFalse (p.OnDataPropertyChangedCalled);
142 p.DataSourceID = "hi";
143 Assert.IsTrue (p.OnDataPropertyChangedCalled, "OnDataPropertyChanged: DataSourceID");
147 public void OnDataPropertyChanged2 ()
149 Poker p = new Poker ();
150 Assert.IsFalse (p.OnDataPropertyChangedCalled);
153 Assert.IsTrue (p.OnDataPropertyChangedCalled, "OnDataPropertyChanged: DataSource");
157 public void DataBind ()
159 Poker p = new Poker ();
160 p.DataSourceID = "DataSourceID";
161 p.SetRequiresDataBinding (true);
166 public void EnsureDataBound ()
168 Poker p = new Poker ();
169 p.DataSourceID = "DataSourceID";
170 p.SetRequiresDataBinding (true);
171 p.DoEnsureDataBound ();
175 public void DataSource_ValidateDataSource ()
177 Poker p = new Poker ();
179 Assert.AreEqual (false, p.ValidateDataSourceCalled);
180 p.DataSource = new Object();
181 Assert.AreEqual (true, p.ValidateDataSourceCalled);
185 public void SupportsDisabledAttribute ()
187 var ver40 = new Version (4, 0);
188 var ver35 = new Version (3, 5);
189 var p = new Poker ();
190 Assert.AreEqual (ver40, p.RenderingCompatibility, "#A1-1");
191 Assert.IsFalse (p.SupportsDisabledAttribute, "#A1-2");
193 p.RenderingCompatibility = new Version (3, 5);
194 Assert.AreEqual (ver35, p.RenderingCompatibility, "#A2-1");
195 Assert.IsTrue (p.SupportsDisabledAttribute, "#A2-2");