DataSourceControlTest.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. //
  2. // Tests for System.Web.UI.WebControls.DataSourceControlTest.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 PokerDataSource : DataSourceControl
  39. {
  40. // View state Stuff
  41. public PokerDataSource ()
  42. : base ()
  43. {
  44. TrackViewState ();
  45. }
  46. public ICollection DoGetViewNames()
  47. {
  48. return base.GetViewNames();
  49. }
  50. public ControlCollection DoCreateControlCollection ()
  51. {
  52. return base.CreateControlCollection ();
  53. }
  54. public void DoRaiseDataSourceChangedEvent (EventArgs e)
  55. {
  56. base.RaiseDataSourceChangedEvent (e);
  57. }
  58. protected override DataSourceView GetView (string viewName)
  59. {
  60. throw new Exception ("The method or operation is not implemented.");
  61. }
  62. }
  63. [TestFixture]
  64. public class DataSourceControlTest
  65. {
  66. [Test]
  67. public void DataSourceControl_DefaultProperty ()
  68. {
  69. PokerDataSource ds = new PokerDataSource ();
  70. Assert.AreEqual (null, ds.ClientID, "ClientID");
  71. Assert.IsNotNull (ds.Controls, "Controls#1");
  72. Assert.AreEqual ( 0 , ds.Controls.Count , "Controls#2");
  73. Assert.AreEqual (false, ds.Visible, "Visible");
  74. }
  75. [Test]
  76. [NUnit.Framework.Category ("NotWorking")]
  77. public void DataSourceControl_DefaultPropertyNotWorking ()
  78. {
  79. PokerDataSource ds = new PokerDataSource ();
  80. Assert.AreEqual (false, ds.EnableTheming, "EnableTheming");
  81. }
  82. [Test]
  83. public void DataSourceControl_ApplyStyleSheetSkin ()
  84. {
  85. // DataSourceControl EnableTheme property always set to false
  86. // and have no render issue - this method would do nothing
  87. }
  88. [Test]
  89. public void DataSourceControl_FindControl ()
  90. {
  91. // DataSourceControl cannot have child controls on ControlCollection
  92. // this method cannot be applyed
  93. }
  94. [Test]
  95. [NUnit.Framework.Category ("NotWorking")]
  96. [ExpectedException (typeof (NotSupportedException))]
  97. public void DataSourceControl_Focus ()
  98. {
  99. PokerDataSource ds = new PokerDataSource ();
  100. ds.Focus ();
  101. }
  102. [Test]
  103. public void DataSourceControl_HasControls ()
  104. {
  105. //Always return false
  106. PokerDataSource ds = new PokerDataSource ();
  107. Assert.AreEqual (false, ds.HasControls (), "HasControls");
  108. }
  109. [Test]
  110. public void DataSourceControl_CreateControlCollection ()
  111. {
  112. PokerDataSource ds = new PokerDataSource ();
  113. ControlCollection collection = ds.DoCreateControlCollection ();
  114. Assert.IsNotNull (collection, "CreateControlCollection#1");
  115. Assert.AreEqual (0, collection.Count ,"CreateControlCollection#2");
  116. }
  117. [Test]
  118. public void DataSourceControl_GetViewNames ()
  119. {
  120. PokerDataSource ds = new PokerDataSource ();
  121. ICollection viewnames = ds.DoGetViewNames ();
  122. Assert.IsNull (viewnames, "GetViewNames#1");
  123. }
  124. [Test]
  125. [ExpectedException (typeof (HttpException))]
  126. public void DataSourceControl_Controls ()
  127. {
  128. Button bt = new Button ();
  129. bt.ID = "bt";
  130. PokerDataSource ds = new PokerDataSource ();
  131. ds.Controls.Add (bt);
  132. }
  133. [Test]
  134. [NUnit.Framework.Category ("NotWorking")]
  135. [ExpectedException (typeof (NotSupportedException))]
  136. public void DataSourceControl_EnableThemingException ()
  137. {
  138. PokerDataSource ds = new PokerDataSource ();
  139. ds.EnableTheming = true;
  140. }
  141. [Test]
  142. [ExpectedException (typeof (NotSupportedException))]
  143. public void DataSourceControl_VisibleException ()
  144. {
  145. PokerDataSource ds = new PokerDataSource ();
  146. ds.Visible = true;
  147. }
  148. //Events
  149. [Test]
  150. public void DataSourceControl_Events ()
  151. {
  152. PokerDataSource ds = new PokerDataSource ();
  153. ((IDataSource) ds).DataSourceChanged += new EventHandler (Eventchecker);
  154. ds.DoRaiseDataSourceChangedEvent (new EventArgs ());
  155. Eventassert("RaiseDataSourceChangedEventFail");
  156. }
  157. // Helper for event checking
  158. private bool event_checker;
  159. private void Eventchecker (object o, EventArgs e)
  160. {
  161. event_checker = true;
  162. }
  163. private void Eventassert (string message)
  164. {
  165. Assert.IsTrue (event_checker, message);
  166. event_checker = false;
  167. }
  168. }
  169. }
  170. #endif