DataSourceViewTest.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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_RaiseUnsupportedCapabilityError1 ()
  106. {
  107. PokerDataSource ds = new PokerDataSource ();
  108. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  109. view.DoRaiseUnsupportedCapabilityError (DataSourceCapabilities.None);
  110. }
  111. //Exceptions
  112. [Test]
  113. [ExpectedException(typeof(NotSupportedException))]
  114. public void DataSourceView_RaiseUnsupportedCapabilityError2 ()
  115. {
  116. PokerDataSource ds = new PokerDataSource ();
  117. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  118. view.DoRaiseUnsupportedCapabilityError (DataSourceCapabilities.Page);
  119. }
  120. [Test]
  121. [ExpectedException (typeof (NotSupportedException))]
  122. public void DataSourceView_RaiseUnsupportedCapabilityError3 ()
  123. {
  124. PokerDataSource ds = new PokerDataSource ();
  125. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  126. view.DoRaiseUnsupportedCapabilityError (DataSourceCapabilities.RetrieveTotalRowCount);
  127. }
  128. [Test]
  129. [ExpectedException (typeof (NotSupportedException))]
  130. public void DataSourceView_RaiseUnsupportedCapabilityError4 ()
  131. {
  132. PokerDataSource ds = new PokerDataSource ();
  133. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  134. view.DoRaiseUnsupportedCapabilityError (DataSourceCapabilities.Sort);
  135. }
  136. [Test]
  137. [ExpectedException(typeof(ArgumentNullException))]
  138. public void DataSourceView_Insert ()
  139. {
  140. // ExecuteInsert must be implemented at first
  141. Hashtable table = new Hashtable ();
  142. PokerDataSource ds = new PokerDataSource ();
  143. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  144. table.Add ("ID", "1000");
  145. view.Insert (table, null);
  146. }
  147. [Test]
  148. [ExpectedException (typeof (ArgumentNullException))]
  149. public void DataSourceView_Update ()
  150. {
  151. // ExecuteUpdate must be implemented at first
  152. Hashtable table = new Hashtable ();
  153. PokerDataSource ds = new PokerDataSource ();
  154. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  155. table.Add ("ID", "1000");
  156. view.Update (table, table, null, null);
  157. }
  158. [Test]
  159. [ExpectedException (typeof (ArgumentNullException))]
  160. public void DataSourceView_Delete()
  161. {
  162. // ExecuteDelete must be implemented at first
  163. Hashtable table = new Hashtable ();
  164. PokerDataSource ds = new PokerDataSource ();
  165. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  166. table.Add ("ID", "1000");
  167. view.Delete(table, table, null);
  168. }
  169. [Test]
  170. [ExpectedException (typeof (ArgumentNullException))]
  171. public void DataSourceView_Select ()
  172. {
  173. // ExecuteSelect must be implemented at first
  174. Hashtable table = new Hashtable ();
  175. PokerDataSource ds = new PokerDataSource ();
  176. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  177. table.Add ("ID", "1000");
  178. view.Select(new DataSourceSelectArguments(), null);
  179. }
  180. [Test]
  181. [NUnit.Framework.Category ("NotWorking")]
  182. [ExpectedException (typeof (ArgumentNullException))]
  183. public void DataSourceView_ConstractorException ()
  184. {
  185. PokerDataSourceView view = new PokerDataSourceView (null, "View");
  186. }
  187. [Test]
  188. [ExpectedException (typeof (NotSupportedException))]
  189. public void DataSourceView_ExecuteDelete ()
  190. {
  191. PokerDataSource ds = new PokerDataSource ();
  192. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  193. view.DoExecuteDelete (null, null);
  194. }
  195. [Test]
  196. [ExpectedException (typeof (NotSupportedException))]
  197. public void DataSourceView_ExecuteInsert ()
  198. {
  199. PokerDataSource ds = new PokerDataSource ();
  200. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  201. view.DoExecuteInsert (null);
  202. }
  203. [Test]
  204. [ExpectedException (typeof (NotSupportedException))]
  205. public void DataSourceView_ExecuteUpdate ()
  206. {
  207. PokerDataSource ds = new PokerDataSource ();
  208. PokerDataSourceView view = new PokerDataSourceView (ds, "View");
  209. view.DoExecuteUpdate (null, null, null);
  210. }
  211. // Helper for event checking
  212. private bool event_checker;
  213. private void Eventchecker (object o, EventArgs e)
  214. {
  215. event_checker = true;
  216. }
  217. private void Eventassert (string message)
  218. {
  219. Assert.IsTrue (event_checker, message);
  220. event_checker = false;
  221. }
  222. }
  223. }
  224. #endif