[resgen] Implement conditional resources (#if/#ifdef)
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / BaseDataBoundControlTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.BaseDataBoundControl.cs 
3 //
4 // Author:
5 //      Chris Toshok (toshok@ximian.com)
6 //
7
8 //
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 using NUnit.Framework;
32 using System;
33 using System.IO;
34 using System.Globalization;
35 using System.Web;
36 using System.Web.UI;
37 using System.Web.UI.WebControls;
38
39 namespace MonoTests.System.Web.UI.WebControls
40 {
41         [TestFixture]   
42         public class BaseDataBoundControlTest { 
43                 class Poker : BaseDataBoundControl {
44                         
45                         public bool OnDataPropertyChangedCalled;
46                         public bool ValidateDataSourceCalled;
47
48                         public Poker () {
49                                 TrackViewState ();
50                         }
51
52                         public object SaveState () {
53                                 return SaveViewState ();
54                         }
55
56                         public void LoadState (object state) {
57                                 LoadViewState (state);
58                         }
59
60                         protected override void PerformSelect () 
61                         {
62                                 Assert.IsTrue (RequiresDataBinding);
63                                 //Console.WriteLine ("PerformSelect\n{0}", Environment.StackTrace);
64                         }
65
66                         protected override void ValidateDataSource (object dataSource)
67                         {
68                                 ValidateDataSourceCalled = true;
69                                 //Console.WriteLine ("PerformSelect\n{0}", Environment.StackTrace);
70                         }
71
72                         public bool GetIsBoundUsingDataSourceID ()
73                         {
74                                 return IsBoundUsingDataSourceID;
75                         }
76
77                         public bool GetInitialized ()
78                         {
79                                 return Initialized;
80                         }
81
82                         protected override void OnDataPropertyChanged () {
83                                 base.OnDataPropertyChanged ();
84                                 OnDataPropertyChangedCalled = true;
85                         }
86
87                         public void SetRequiresDataBinding (bool val)
88                         {
89                                 RequiresDataBinding = val;
90                         }
91
92                         public bool GetRequiresDataBinding ()
93                         {
94                                 return RequiresDataBinding;
95                         }
96                         
97                         public override void DataBind ()
98                         {
99                                 Assert.IsTrue (RequiresDataBinding);
100                                 base.DataBind ();
101                                 Assert.IsTrue (RequiresDataBinding);
102                         }
103
104                         public void DoEnsureDataBound ()
105                         {
106                                 Assert.IsTrue (RequiresDataBinding);
107                                 EnsureDataBound ();
108                                 Assert.IsTrue (RequiresDataBinding);
109                         }
110                 }
111                 
112                 [Test]
113                 public void Defaults ()
114                 {
115                         Poker p = new Poker ();
116
117                         Assert.IsNull (p.DataSource, "A1");
118                         Assert.AreEqual ("", p.DataSourceID, "A2");
119                         Assert.IsFalse (p.GetIsBoundUsingDataSourceID(), "A3");
120                         Assert.IsFalse (p.GetInitialized(), "A4");
121                 }
122
123                 [Test]
124                 public void ViewState ()
125                 {
126                         Poker p = new Poker ();
127                         Poker copy = new Poker ();
128
129                         p.DataSourceID = "hi";
130                         object state = p.SaveState ();
131                         copy.LoadState (state);
132
133                         Assert.AreEqual ("hi", copy.DataSourceID, "A1");
134                 }
135
136                 [Test]
137                 public void OnDataPropertyChanged ()
138                 {
139                         Poker p = new Poker ();
140                         Assert.IsFalse (p.OnDataPropertyChangedCalled);
141
142                         p.DataSourceID = "hi";
143                         Assert.IsTrue (p.OnDataPropertyChangedCalled, "OnDataPropertyChanged: DataSourceID");
144                 }
145
146                 [Test]
147                 public void OnDataPropertyChanged2 ()
148                 {
149                         Poker p = new Poker ();
150                         Assert.IsFalse (p.OnDataPropertyChangedCalled);
151
152                         p.DataSource = null;
153                         Assert.IsTrue (p.OnDataPropertyChangedCalled, "OnDataPropertyChanged: DataSource");
154                 }
155
156                 [Test]
157                 public void DataBind ()
158                 {
159                         Poker p = new Poker ();
160                         p.DataSourceID = "DataSourceID";
161                         p.SetRequiresDataBinding (true);
162                         p.DataBind ();
163                 }
164
165                 [Test]
166                 public void EnsureDataBound ()
167                 {
168                         Poker p = new Poker ();
169                         p.DataSourceID = "DataSourceID";
170                         p.SetRequiresDataBinding (true);
171                         p.DoEnsureDataBound ();
172                 }
173
174                 [Test]
175                 public void DataSource_ValidateDataSource ()
176                 {
177                         Poker p = new Poker ();
178                         p.DataSource = null;
179                         Assert.AreEqual (false, p.ValidateDataSourceCalled);
180                         p.DataSource = new Object();
181                         Assert.AreEqual (true, p.ValidateDataSourceCalled);
182                 }
183 #if NET_4_0
184                 [Test]
185                 public void SupportsDisabledAttribute ()
186                 {
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");
192
193                         p.RenderingCompatibility = new Version (3, 5);
194                         Assert.AreEqual (ver35, p.RenderingCompatibility, "#A2-1");
195                         Assert.IsTrue (p.SupportsDisabledAttribute, "#A2-2");
196                 }
197 #endif
198         }
199 }