2 // Tests for System.Web.UI.WebControls.Repeater.cs
5 // Chris Toshok (toshok@novell.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;
38 using MonoTests.SystemWeb.Framework;
39 using System.Collections;
41 namespace MonoTests.System.Web.UI.WebControls
44 public class RepeaterTest {
45 class Poker : Repeater {
47 public void TrackState ()
52 public object SaveState ()
54 return SaveViewState ();
57 public void LoadState (object o)
63 public DataSourceSelectArguments GetSelectArguments()
65 return SelectArguments;
68 public DataSourceSelectArguments DoCreateDataSourceSelectArguments ()
70 return base.CreateDataSourceSelectArguments();
73 public new void EnsureDataBound ()
75 base.EnsureDataBound ();
78 public global::System.Collections.IEnumerable DoGetData ()
80 return base.GetData ();
83 public new bool Initialized
85 get { return base.Initialized; }
88 public new bool IsBoundUsingDataSourceID
90 get { return base.IsBoundUsingDataSourceID; }
93 protected override void OnDataPropertyChanged ()
96 base.OnDataPropertyChanged ();
99 public void DoOnDataSourceViewChanged (object sender, EventArgs e)
101 base.OnDataSourceViewChanged (sender, e);
104 public new bool RequiresDataBinding
106 get { return base.RequiresDataBinding; }
107 set { base.RequiresDataBinding = value; }
111 public bool EventChecker
113 get { return eventChecker; }
114 set { throw new NotImplementedException (); }
117 public void clearEvents ()
119 eventChecker = false;
126 public void Repeater_DefaultsSelectArguments ()
128 Poker p = new Poker ();
129 DataSourceSelectArguments args, args2;
131 args = p.GetSelectArguments();
132 args2 = p.DoCreateDataSourceSelectArguments();
134 Assert.AreEqual (args, args2, "call == prop");
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");
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");
144 /* check to see whether multiple calls give us different refs */
145 args = p.DoCreateDataSourceSelectArguments();
147 Assert.AreEqual (args, args2, "multiple calls, same ref");
148 Assert.AreEqual (string.Empty, p.DataSourceID, "DataSourceID");
149 Assert.AreEqual (false, p.RequiresDataBinding, "RequiresDataBinding");
153 public void Repeater_Defaults ()
155 Poker p = new Poker ();
156 Assert.AreEqual (true, p.EnableTheming, "EnableTheming");
162 [Category("NunitWeb")]
163 [ExpectedException(typeof(HttpException))]
164 public void EnsureDataBound ()
166 WebTest t = new WebTest (PageInvoker.CreateOnInit (EnsureDataBound_Init));
167 string html = t.Run ();
170 public static void EnsureDataBound_Init (Page p)
172 Poker r = new Poker ();
173 r.DataSourceID = "Fake";
174 p.Form.Controls.Add (r);
175 r.EnsureDataBound ();
179 public void GetData ()
181 Poker p = new Poker ();
182 p.DataSource = Databound ();
183 ArrayList data = (ArrayList)p.DoGetData ();
184 Assert.AreEqual (3, data.Count, "GetData#1");
185 Assert.AreEqual (1, data[0], "GetData#2");
189 static ArrayList Databound ()
191 ArrayList list = new ArrayList ();
200 [Category ("NunitWeb")]
201 public void Initialized ()
203 WebTest t = new WebTest ();
204 PageDelegates pd = new PageDelegates ();
205 pd.Init = new PageDelegate (Initialized_Init);
206 pd.Load = new PageDelegate (Initialized_Load);
207 t.Invoker = new PageInvoker (pd);
208 string html = t.Run ();
211 public static void Initialized_Init (Page p)
213 Poker r = new Poker ();
215 Assert.AreEqual (false, r.Initialized, "Initialized#1");
216 r.DataSource = Databound ();
217 p.Form.Controls.Add (r);
220 public static void Initialized_Load (Page p)
222 Poker r = p.FindControl ("Rep") as Poker;
223 Assert.AreEqual (true, r.Initialized, "Initialized#2");
227 public void IsBoundUsingDataSourceID ()
229 Poker p = new Poker ();
230 Assert.AreEqual (false, p.IsBoundUsingDataSourceID, "IsBoundUsingDataSourceID#1");
231 p.DataSourceID = "Fake";
232 Assert.AreEqual (true, p.IsBoundUsingDataSourceID, "IsBoundUsingDataSourceID#2");
236 public void OnDataPropertyChanged ()
238 Poker p = new Poker ();
240 p.DataSourceID = "Fake";
241 Assert.AreEqual (true, p.EventChecker, "OnDataPropertyChanged#1");
245 public void OnDataSourceViewChanged ()
247 Poker p = new Poker ();
248 Assert.AreEqual (false, p.RequiresDataBinding, "OnDataSourceViewChanged#1");
249 p.DoOnDataSourceViewChanged (p, new EventArgs ());
250 Assert.AreEqual (true, p.RequiresDataBinding, "OnDataSourceViewChanged#2");
253 #region help_class_for_select_args
254 class PokerS : Repeater
257 public void TrackState ()
262 public object SaveState ()
264 return SaveViewState ();
267 public void LoadState (object o)
273 public DataSourceSelectArguments GetSelectArguments ()
275 return SelectArguments;
278 protected override DataSourceSelectArguments CreateDataSourceSelectArguments ()
280 DataSourceSelectArguments arg = new DataSourceSelectArguments ("SortExp");
288 public void GetSelectArguments ()
290 PokerS p = new PokerS ();
291 DataSourceSelectArguments arg = p.GetSelectArguments ();
292 Assert.AreEqual ("SortExp", arg.SortExpression, "GetSelectArguments");
295 [TestFixtureTearDown]
296 public void TearDown ()