[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / RepeaterTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.Repeater.cs 
3 //
4 // Author:
5 //      Chris Toshok (toshok@novell.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 using MonoTests.SystemWeb.Framework;
39 using System.Collections;
40
41 namespace MonoTests.System.Web.UI.WebControls
42 {
43         [TestFixture]   
44         public class RepeaterTest {     
45                 class Poker : Repeater {
46                         
47                         public void TrackState () 
48                         {
49                                 TrackViewState ();
50                         }
51                         
52                         public object SaveState ()
53                         {
54                                 return SaveViewState ();
55                         }
56                         
57                         public void LoadState (object o)
58                         {
59                                 LoadViewState (o);
60                         }
61
62                         public DataSourceSelectArguments GetSelectArguments()
63                         {
64                                 return SelectArguments;
65                         }
66
67                         public DataSourceSelectArguments DoCreateDataSourceSelectArguments ()
68                         {
69                                 return base.CreateDataSourceSelectArguments();
70                         }
71
72                         public new void EnsureDataBound ()
73                         {
74                                 base.EnsureDataBound ();
75                         }
76
77                         public global::System.Collections.IEnumerable DoGetData ()
78                         {
79                                 return base.GetData ();
80                         }
81
82                         public new bool Initialized
83                         {
84                                 get { return base.Initialized; }
85                         }
86
87                         public new bool IsBoundUsingDataSourceID
88                         {
89                                 get { return base.IsBoundUsingDataSourceID; }
90                         }
91
92                         protected override void OnDataPropertyChanged ()
93                         {
94                                 eventChecker = true;
95                                 base.OnDataPropertyChanged ();
96                         }
97
98                         public void DoOnDataSourceViewChanged (object sender, EventArgs e)
99                         {
100                                 base.OnDataSourceViewChanged (sender, e);
101                         }
102
103                         public new bool RequiresDataBinding
104                         {
105                                 get { return base.RequiresDataBinding; }
106                                 set { base.RequiresDataBinding = value; }
107                         }
108
109                         bool eventChecker;
110                         public bool EventChecker
111                         {
112                                 get { return eventChecker; }
113                                 set { throw new NotImplementedException (); }
114                         }
115
116                         public void clearEvents ()
117                         {
118                                 eventChecker = false;
119                         }
120                 }
121
122                 [Test]
123                 public void Repeater_DefaultsSelectArguments ()
124                 {
125                         Poker p = new Poker ();
126                         DataSourceSelectArguments args, args2;
127
128                         args = p.GetSelectArguments();
129                         args2 = p.DoCreateDataSourceSelectArguments();
130
131                         Assert.AreEqual (args, args2, "call == prop");
132
133                         Assert.IsNotNull (args, "property null check");
134                         Assert.IsTrue    (args != DataSourceSelectArguments.Empty, "property != Empty check");
135                         Assert.IsTrue    (args.Equals (DataSourceSelectArguments.Empty), "property but they are empty check");
136
137                         Assert.IsNotNull (args2, "method null check");
138                         Assert.IsTrue    (args2 != DataSourceSelectArguments.Empty, "method != Empty check");
139                         Assert.IsTrue    (args2.Equals (DataSourceSelectArguments.Empty), "method but they are empty check");
140
141                         /* check to see whether multiple calls give us different refs */
142                         args = p.DoCreateDataSourceSelectArguments();
143                         
144                         Assert.AreEqual (args, args2, "multiple calls, same ref");
145                         Assert.AreEqual (string.Empty, p.DataSourceID, "DataSourceID");
146                         Assert.AreEqual (false, p.RequiresDataBinding, "RequiresDataBinding");
147                 }
148
149                 [Test]
150                 public void Repeater_Defaults ()
151                 {
152                         Poker p = new Poker ();
153                         Assert.AreEqual (true, p.EnableTheming, "EnableTheming");
154                 }
155
156
157                 
158                 [Test]
159                 [Category("NunitWeb")]
160                 [ExpectedException(typeof(HttpException))]
161                 public void  EnsureDataBound ()
162                 {
163                         WebTest t = new WebTest (PageInvoker.CreateOnInit (EnsureDataBound_Init));
164                         string html = t.Run ();
165                 }
166
167                 public static void EnsureDataBound_Init (Page p)
168                 {
169                         Poker r = new Poker ();
170                         r.DataSourceID = "Fake";
171                         p.Form.Controls.Add (r);
172                         r.EnsureDataBound ();
173                 }
174
175                 [Test]
176                 public void GetData ()
177                 {
178                         Poker p = new Poker ();
179                         p.DataSource = Databound ();
180                         ArrayList data = (ArrayList)p.DoGetData ();
181                         Assert.AreEqual (3, data.Count, "GetData#1");
182                         Assert.AreEqual (1, data[0], "GetData#2");
183                 }
184
185                 #region help_class
186                 static ArrayList Databound ()
187                 {
188                         ArrayList list = new ArrayList ();
189                         list.Add (1);
190                         list.Add (2);
191                         list.Add (3);
192                         return list;
193                 }
194                 #endregion
195
196                 [Test]
197                 [Category ("NunitWeb")]
198                 public void Initialized ()
199                 {
200                         WebTest t = new WebTest ();
201                         PageDelegates pd = new PageDelegates ();
202                         pd.Init = new PageDelegate (Initialized_Init);
203                         pd.Load = new PageDelegate (Initialized_Load);
204                         t.Invoker = new PageInvoker (pd);
205                         string html = t.Run ();
206                 }
207
208                 public static void Initialized_Init (Page p)
209                 {
210                         Poker r = new Poker ();
211                         r.ID = "Rep";
212                         Assert.AreEqual (false, r.Initialized, "Initialized#1");
213                         r.DataSource = Databound ();
214                         p.Form.Controls.Add (r);
215                 }
216
217                 public static void Initialized_Load (Page p)
218                 {
219                         Poker r = p.FindControl ("Rep") as Poker; 
220                         Assert.AreEqual (true, r.Initialized, "Initialized#2");
221                 }
222
223                 [Test]
224                 public void IsBoundUsingDataSourceID ()
225                 {
226                         Poker p = new Poker ();
227                         Assert.AreEqual (false, p.IsBoundUsingDataSourceID, "IsBoundUsingDataSourceID#1");
228                         p.DataSourceID = "Fake";
229                         Assert.AreEqual (true, p.IsBoundUsingDataSourceID, "IsBoundUsingDataSourceID#2");
230                 }
231
232                 [Test]
233                 public void OnDataPropertyChanged ()
234                 {
235                         Poker p = new Poker ();
236                         p.clearEvents ();
237                         p.DataSourceID = "Fake";
238                         Assert.AreEqual (true, p.EventChecker, "OnDataPropertyChanged#1");
239                 }
240
241                 [Test]
242                 public void OnDataSourceViewChanged ()
243                 {
244                         Poker p = new Poker ();
245                         Assert.AreEqual (false, p.RequiresDataBinding, "OnDataSourceViewChanged#1");
246                         p.DoOnDataSourceViewChanged (p, new EventArgs ());
247                         Assert.AreEqual (true, p.RequiresDataBinding, "OnDataSourceViewChanged#2");
248                 }
249
250                 #region help_class_for_select_args
251                 class PokerS : Repeater
252                 {
253
254                         public void TrackState ()
255                         {
256                                 TrackViewState ();
257                         }
258
259                         public object SaveState ()
260                         {
261                                 return SaveViewState ();
262                         }
263
264                         public void LoadState (object o)
265                         {
266                                 LoadViewState (o);
267                         }
268
269                         public DataSourceSelectArguments GetSelectArguments ()
270                         {
271                                 return SelectArguments;
272                         }
273
274                         protected override DataSourceSelectArguments CreateDataSourceSelectArguments ()
275                         {
276                                 DataSourceSelectArguments arg = new DataSourceSelectArguments ("SortExp");
277                                 return arg;
278                         }
279                 }
280                 #endregion
281
282                 [Test]
283                 public void GetSelectArguments ()
284                 {
285                         PokerS p = new PokerS ();
286                         DataSourceSelectArguments arg = p.GetSelectArguments ();
287                         Assert.AreEqual ("SortExp", arg.SortExpression, "GetSelectArguments");
288                 }
289
290                 [TestFixtureTearDown]
291                 public void TearDown ()
292                 {
293                         WebTest.Unload ();
294                 }
295         }
296 }