RepeaterTest.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. //
  2. // Tests for System.Web.UI.WebControls.Repeater.cs
  3. //
  4. // Author:
  5. // Chris Toshok ([email protected])
  6. //
  7. //
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using NUnit.Framework;
  30. using System;
  31. using System.IO;
  32. using System.Globalization;
  33. using System.Web;
  34. using System.Web.UI;
  35. using System.Web.UI.WebControls;
  36. using MonoTests.SystemWeb.Framework;
  37. using System.Collections;
  38. namespace MonoTests.System.Web.UI.WebControls
  39. {
  40. [TestFixture]
  41. public class RepeaterTest {
  42. class Poker : Repeater {
  43. public void TrackState ()
  44. {
  45. TrackViewState ();
  46. }
  47. public object SaveState ()
  48. {
  49. return SaveViewState ();
  50. }
  51. public void LoadState (object o)
  52. {
  53. LoadViewState (o);
  54. }
  55. #if NET_2_0
  56. public DataSourceSelectArguments GetSelectArguments()
  57. {
  58. return SelectArguments;
  59. }
  60. public DataSourceSelectArguments DoCreateDataSourceSelectArguments ()
  61. {
  62. return base.CreateDataSourceSelectArguments();
  63. }
  64. public new void EnsureDataBound ()
  65. {
  66. base.EnsureDataBound ();
  67. }
  68. public global::System.Collections.IEnumerable DoGetData ()
  69. {
  70. return base.GetData ();
  71. }
  72. public new bool Initialized
  73. {
  74. get { return base.Initialized; }
  75. }
  76. public new bool IsBoundUsingDataSourceID
  77. {
  78. get { return base.IsBoundUsingDataSourceID; }
  79. }
  80. protected override void OnDataPropertyChanged ()
  81. {
  82. eventChecker = true;
  83. base.OnDataPropertyChanged ();
  84. }
  85. public void DoOnDataSourceViewChanged (object sender, EventArgs e)
  86. {
  87. base.OnDataSourceViewChanged (sender, e);
  88. }
  89. public new bool RequiresDataBinding
  90. {
  91. get { return base.RequiresDataBinding; }
  92. set { base.RequiresDataBinding = value; }
  93. }
  94. bool eventChecker;
  95. public bool EventChecker
  96. {
  97. get { return eventChecker; }
  98. set { throw new NotImplementedException (); }
  99. }
  100. public void clearEvents ()
  101. {
  102. eventChecker = false;
  103. }
  104. #endif
  105. }
  106. #if NET_2_0
  107. [Test]
  108. public void Repeater_DefaultsSelectArguments ()
  109. {
  110. Poker p = new Poker ();
  111. DataSourceSelectArguments args, args2;
  112. args = p.GetSelectArguments();
  113. args2 = p.DoCreateDataSourceSelectArguments();
  114. Assert.AreEqual (args, args2, "call == prop");
  115. Assert.IsNotNull (args, "property null check");
  116. Assert.IsTrue (args != DataSourceSelectArguments.Empty, "property != Empty check");
  117. Assert.IsTrue (args.Equals (DataSourceSelectArguments.Empty), "property but they are empty check");
  118. Assert.IsNotNull (args2, "method null check");
  119. Assert.IsTrue (args2 != DataSourceSelectArguments.Empty, "method != Empty check");
  120. Assert.IsTrue (args2.Equals (DataSourceSelectArguments.Empty), "method but they are empty check");
  121. /* check to see whether multiple calls give us different refs */
  122. args = p.DoCreateDataSourceSelectArguments();
  123. Assert.AreEqual (args, args2, "multiple calls, same ref");
  124. Assert.AreEqual (string.Empty, p.DataSourceID, "DataSourceID");
  125. Assert.AreEqual (false, p.RequiresDataBinding, "RequiresDataBinding");
  126. }
  127. [Test]
  128. [Category ("NotWorking")]
  129. public void Repeater_DefaultsNotWorking ()
  130. {
  131. Poker p = new Poker ();
  132. Assert.AreEqual (true, p.EnableTheming, "EnableTheming");
  133. }
  134. [Test]
  135. [Category("NunitWeb")]
  136. [ExpectedException(typeof(HttpException))]
  137. public void EnsureDataBound ()
  138. {
  139. WebTest t = new WebTest (PageInvoker.CreateOnInit (EnsureDataBound_Init));
  140. string html = t.Run ();
  141. }
  142. public static void EnsureDataBound_Init (Page p)
  143. {
  144. Poker r = new Poker ();
  145. r.DataSourceID = "Fake";
  146. p.Form.Controls.Add (r);
  147. r.EnsureDataBound ();
  148. }
  149. [Test]
  150. [Category ("NotWorking")]
  151. public void GetData ()
  152. {
  153. Poker p = new Poker ();
  154. p.DataSource = Databound ();
  155. ArrayList data = (ArrayList)p.DoGetData ();
  156. Assert.AreEqual (3, data.Count, "GetData#1");
  157. Assert.AreEqual (1, data[0], "GetData#2");
  158. }
  159. #region help_class
  160. static ArrayList Databound ()
  161. {
  162. ArrayList list = new ArrayList ();
  163. list.Add (1);
  164. list.Add (2);
  165. list.Add (3);
  166. return list;
  167. }
  168. #endregion
  169. [Test]
  170. [Category ("NotWorking")]
  171. [Category ("NunitWeb")]
  172. public void Initialized ()
  173. {
  174. WebTest t = new WebTest ();
  175. PageDelegates pd = new PageDelegates ();
  176. pd.Init = new PageDelegate (Initialized_Init);
  177. pd.Load = new PageDelegate (Initialized_Load);
  178. t.Invoker = new PageInvoker (pd);
  179. string html = t.Run ();
  180. }
  181. public static void Initialized_Init (Page p)
  182. {
  183. Poker r = new Poker ();
  184. r.ID = "Rep";
  185. Assert.AreEqual (false, r.Initialized, "Initialized#1");
  186. r.DataSource = Databound ();
  187. p.Form.Controls.Add (r);
  188. }
  189. public static void Initialized_Load (Page p)
  190. {
  191. Poker r = p.FindControl ("Rep") as Poker;
  192. Assert.AreEqual (true, r.Initialized, "Initialized#2");
  193. }
  194. [Test]
  195. public void IsBoundUsingDataSourceID ()
  196. {
  197. Poker p = new Poker ();
  198. Assert.AreEqual (false, p.IsBoundUsingDataSourceID, "IsBoundUsingDataSourceID#1");
  199. p.DataSourceID = "Fake";
  200. Assert.AreEqual (true, p.IsBoundUsingDataSourceID, "IsBoundUsingDataSourceID#2");
  201. }
  202. [Test]
  203. public void OnDataPropertyChanged ()
  204. {
  205. Poker p = new Poker ();
  206. p.clearEvents ();
  207. p.DataSourceID = "Fake";
  208. Assert.AreEqual (true, p.EventChecker, "OnDataPropertyChanged#1");
  209. }
  210. [Test]
  211. public void OnDataSourceViewChanged ()
  212. {
  213. Poker p = new Poker ();
  214. Assert.AreEqual (false, p.RequiresDataBinding, "OnDataSourceViewChanged#1");
  215. p.DoOnDataSourceViewChanged (p, new EventArgs ());
  216. Assert.AreEqual (true, p.RequiresDataBinding, "OnDataSourceViewChanged#2");
  217. }
  218. #region help_class_for_select_args
  219. class PokerS : Repeater
  220. {
  221. public void TrackState ()
  222. {
  223. TrackViewState ();
  224. }
  225. public object SaveState ()
  226. {
  227. return SaveViewState ();
  228. }
  229. public void LoadState (object o)
  230. {
  231. LoadViewState (o);
  232. }
  233. #if NET_2_0
  234. public DataSourceSelectArguments GetSelectArguments ()
  235. {
  236. return SelectArguments;
  237. }
  238. protected override DataSourceSelectArguments CreateDataSourceSelectArguments ()
  239. {
  240. DataSourceSelectArguments arg = new DataSourceSelectArguments ("SortExp");
  241. return arg;
  242. }
  243. #endif
  244. }
  245. #endregion
  246. [Test]
  247. [Category ("NotWorking")]
  248. public void GetSelectArguments ()
  249. {
  250. PokerS p = new PokerS ();
  251. DataSourceSelectArguments arg = p.GetSelectArguments ();
  252. Assert.AreEqual ("SortExp", arg.SortExpression, "GetSelectArguments");
  253. }
  254. [TestFixtureTearDown]
  255. public void TearDown ()
  256. {
  257. WebTest.Unload ();
  258. }
  259. #endif
  260. }
  261. }