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