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)
62 public DataSourceSelectArguments GetSelectArguments()
64 return SelectArguments;
67 public DataSourceSelectArguments DoCreateDataSourceSelectArguments ()
69 return base.CreateDataSourceSelectArguments();
72 public new void EnsureDataBound ()
74 base.EnsureDataBound ();
77 public global::System.Collections.IEnumerable DoGetData ()
79 return base.GetData ();
82 public new bool Initialized
84 get { return base.Initialized; }
87 public new bool IsBoundUsingDataSourceID
89 get { return base.IsBoundUsingDataSourceID; }
92 protected override void OnDataPropertyChanged ()
95 base.OnDataPropertyChanged ();
98 public void DoOnDataSourceViewChanged (object sender, EventArgs e)
100 base.OnDataSourceViewChanged (sender, e);
103 public new bool RequiresDataBinding
105 get { return base.RequiresDataBinding; }
106 set { base.RequiresDataBinding = value; }
110 public bool EventChecker
112 get { return eventChecker; }
113 set { throw new NotImplementedException (); }
116 public void clearEvents ()
118 eventChecker = false;
123 public void Repeater_DefaultsSelectArguments ()
125 Poker p = new Poker ();
126 DataSourceSelectArguments args, args2;
128 args = p.GetSelectArguments();
129 args2 = p.DoCreateDataSourceSelectArguments();
131 Assert.AreEqual (args, args2, "call == prop");
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");
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");
141 /* check to see whether multiple calls give us different refs */
142 args = p.DoCreateDataSourceSelectArguments();
144 Assert.AreEqual (args, args2, "multiple calls, same ref");
145 Assert.AreEqual (string.Empty, p.DataSourceID, "DataSourceID");
146 Assert.AreEqual (false, p.RequiresDataBinding, "RequiresDataBinding");
150 public void Repeater_Defaults ()
152 Poker p = new Poker ();
153 Assert.AreEqual (true, p.EnableTheming, "EnableTheming");
159 [Category("NunitWeb")]
160 [ExpectedException(typeof(HttpException))]
161 public void EnsureDataBound ()
163 WebTest t = new WebTest (PageInvoker.CreateOnInit (EnsureDataBound_Init));
164 string html = t.Run ();
167 public static void EnsureDataBound_Init (Page p)
169 Poker r = new Poker ();
170 r.DataSourceID = "Fake";
171 p.Form.Controls.Add (r);
172 r.EnsureDataBound ();
176 public void GetData ()
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");
186 static ArrayList Databound ()
188 ArrayList list = new ArrayList ();
197 [Category ("NunitWeb")]
198 public void Initialized ()
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 ();
208 public static void Initialized_Init (Page p)
210 Poker r = new Poker ();
212 Assert.AreEqual (false, r.Initialized, "Initialized#1");
213 r.DataSource = Databound ();
214 p.Form.Controls.Add (r);
217 public static void Initialized_Load (Page p)
219 Poker r = p.FindControl ("Rep") as Poker;
220 Assert.AreEqual (true, r.Initialized, "Initialized#2");
224 public void IsBoundUsingDataSourceID ()
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");
233 public void OnDataPropertyChanged ()
235 Poker p = new Poker ();
237 p.DataSourceID = "Fake";
238 Assert.AreEqual (true, p.EventChecker, "OnDataPropertyChanged#1");
242 public void OnDataSourceViewChanged ()
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");
250 #region help_class_for_select_args
251 class PokerS : Repeater
254 public void TrackState ()
259 public object SaveState ()
261 return SaveViewState ();
264 public void LoadState (object o)
269 public DataSourceSelectArguments GetSelectArguments ()
271 return SelectArguments;
274 protected override DataSourceSelectArguments CreateDataSourceSelectArguments ()
276 DataSourceSelectArguments arg = new DataSourceSelectArguments ("SortExp");
283 public void GetSelectArguments ()
285 PokerS p = new PokerS ();
286 DataSourceSelectArguments arg = p.GetSelectArguments ();
287 Assert.AreEqual ("SortExp", arg.SortExpression, "GetSelectArguments");
290 [TestFixtureTearDown]
291 public void TearDown ()