DataSourceViewTest.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. //
  2. // Tests for System.Web.UI.WebControls.DataSourceViewTest.cs
  3. //
  4. // Author:
  5. // Yoni Klein ([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. #if NET_2_0
  29. using System;
  30. using System.Web;
  31. using System.Web.UI;
  32. using System.Web.UI.WebControls;
  33. using System.Collections;
  34. using System.ComponentModel;
  35. using NUnit.Framework;
  36. namespace MonoTests.System.Web.UI.WebControls
  37. {
  38. public class PokerDataSourceView : DataSourceView
  39. {
  40. // View state Stuff
  41. public PokerDataSourceView (IDataSource owner , string name)
  42. : base(owner, name)
  43. {
  44. }
  45. public EventHandlerList events {
  46. get{
  47. return base.Events;
  48. }
  49. }
  50. public int DoExecuteDelete (IDictionary keys, IDictionary oldValues)
  51. {
  52. return base.ExecuteDelete (keys, oldValues);
  53. }
  54. public int DoExecuteInsert (IDictionary values)
  55. {
  56. return base.ExecuteInsert (values);
  57. }
  58. public int DoExecuteUpdate (IDictionary keys, IDictionary values, IDictionary oldValues)
  59. {
  60. return base.ExecuteUpdate (keys, values, oldValues);
  61. }
  62. public void DoOnDataSourceViewChanged (EventArgs e)
  63. {
  64. base.OnDataSourceViewChanged (e);
  65. }
  66. protected override IEnumerable ExecuteSelect (DataSourceSelectArguments arguments)
  67. {
  68. throw new Exception ("The method or operation is not implemented.");
  69. }
  70. public void DoRaiseUnsupportedCapabilityError (DataSourceCapabilities capability)
  71. {
  72. base.RaiseUnsupportedCapabilityError (capability);
  73. }
  74. }
  75. [TestFixture]
  76. public class DataSourceViewTest
  77. {
  78. [Test]
  79. public void DataSourceView_DefaultProperty ()
  80. {
  81. PokerDataSource ds = new PokerDataSource ();
  82. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  83. Assert.AreEqual (false, view.CanDelete, "CanDelete");
  84. Assert.AreEqual (false, view.CanInsert, "CanInsert");
  85. Assert.AreEqual (false, view.CanPage, "CanPage");
  86. Assert.AreEqual (false, view.CanRetrieveTotalRowCount, "CanRetrieveTotalRowCount");
  87. Assert.AreEqual (false, view.CanSort, "CanSort");
  88. Assert.AreEqual (false, view.CanUpdate, "CanUpdate");
  89. Assert.AreEqual ("View", view.Name, "Name");
  90. //protected properties
  91. EventHandlerList list = view.events;
  92. Assert.IsNotNull (list, "Events");
  93. }
  94. //Events
  95. [Test]
  96. public void DataSourceView_Events ()
  97. {
  98. PokerDataSource ds = new PokerDataSource ();
  99. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  100. view.DataSourceViewChanged += new EventHandler (Eventchecker);
  101. view.DoOnDataSourceViewChanged (new EventArgs ());
  102. Eventassert ("DataSourceViewChanged");
  103. }
  104. [Test]
  105. public void DataSourceView_Events2 () {
  106. PokerDataSource ds = new PokerDataSource ();
  107. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  108. view.DataSourceViewChanged += new EventHandler (Eventchecker);
  109. ds.DoRaiseDataSourceChangedEvent (new EventArgs ());
  110. Eventassert ("DataSourceViewChanged");
  111. }
  112. [Test]
  113. public void DataSourceView_RaiseUnsupportedCapabilityError1 ()
  114. {
  115. PokerDataSource ds = new PokerDataSource ();
  116. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  117. view.DoRaiseUnsupportedCapabilityError (DataSourceCapabilities.None);
  118. }
  119. //Exceptions
  120. [Test]
  121. [ExpectedException(typeof(NotSupportedException))]
  122. public void DataSourceView_RaiseUnsupportedCapabilityError2 ()
  123. {
  124. PokerDataSource ds = new PokerDataSource ();
  125. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  126. view.DoRaiseUnsupportedCapabilityError (DataSourceCapabilities.Page);
  127. }
  128. [Test]
  129. [ExpectedException (typeof (NotSupportedException))]
  130. public void DataSourceView_RaiseUnsupportedCapabilityError3 ()
  131. {
  132. PokerDataSource ds = new PokerDataSource ();
  133. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  134. view.DoRaiseUnsupportedCapabilityError (DataSourceCapabilities.RetrieveTotalRowCount);
  135. }
  136. [Test]
  137. [ExpectedException (typeof (NotSupportedException))]
  138. public void DataSourceView_RaiseUnsupportedCapabilityError4 ()
  139. {
  140. PokerDataSource ds = new PokerDataSource ();
  141. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  142. view.DoRaiseUnsupportedCapabilityError (DataSourceCapabilities.Sort);
  143. }
  144. [Test]
  145. [ExpectedException(typeof(ArgumentNullException))]
  146. public void DataSourceView_Insert ()
  147. {
  148. // ExecuteInsert must be implemented at first
  149. Hashtable table = new Hashtable ();
  150. PokerDataSource ds = new PokerDataSource ();
  151. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  152. table.Add ("ID", "1000");
  153. view.Insert (table, null);
  154. }
  155. [Test]
  156. [ExpectedException (typeof (ArgumentNullException))]
  157. public void DataSourceView_Update ()
  158. {
  159. // ExecuteUpdate must be implemented at first
  160. Hashtable table = new Hashtable ();
  161. PokerDataSource ds = new PokerDataSource ();
  162. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  163. table.Add ("ID", "1000");
  164. view.Update (table, table, null, null);
  165. }
  166. [Test]
  167. [ExpectedException (typeof (ArgumentNullException))]
  168. public void DataSourceView_Delete()
  169. {
  170. // ExecuteDelete must be implemented at first
  171. Hashtable table = new Hashtable ();
  172. PokerDataSource ds = new PokerDataSource ();
  173. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  174. table.Add ("ID", "1000");
  175. view.Delete(table, table, null);
  176. }
  177. [Test]
  178. [ExpectedException (typeof (ArgumentNullException))]
  179. public void DataSourceView_Select ()
  180. {
  181. // ExecuteSelect must be implemented at first
  182. Hashtable table = new Hashtable ();
  183. PokerDataSource ds = new PokerDataSource ();
  184. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  185. table.Add ("ID", "1000");
  186. view.Select(new DataSourceSelectArguments(), null);
  187. }
  188. [Test]
  189. [ExpectedException (typeof (ArgumentNullException))]
  190. public void DataSourceView_ConstractorException ()
  191. {
  192. PokerDataSourceView view = new PokerDataSourceView (null, "View");
  193. }
  194. [Test]
  195. [ExpectedException (typeof (NotSupportedException))]
  196. public void DataSourceView_ExecuteDelete ()
  197. {
  198. PokerDataSource ds = new PokerDataSource ();
  199. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  200. view.DoExecuteDelete (null, null);
  201. }
  202. [Test]
  203. [ExpectedException (typeof (NotSupportedException))]
  204. public void DataSourceView_ExecuteInsert ()
  205. {
  206. PokerDataSource ds = new PokerDataSource ();
  207. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  208. view.DoExecuteInsert (null);
  209. }
  210. [Test]
  211. [ExpectedException (typeof (NotSupportedException))]
  212. public void DataSourceView_ExecuteUpdate ()
  213. {
  214. PokerDataSource ds = new PokerDataSource ();
  215. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  216. view.DoExecuteUpdate (null, null, null);
  217. }
  218. // Helper for event checking
  219. private bool event_checker;
  220. private void Eventchecker (object o, EventArgs e)
  221. {
  222. event_checker = true;
  223. }
  224. private void Eventassert (string message)
  225. {
  226. Assert.IsTrue (event_checker, message);
  227. event_checker = false;
  228. }
  229. }
  230. }
  231. #endif