DataSourceControlTest.cs 5.0 KB

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