ParameterTest.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. //
  2. // Tests for System.Web.UI.WebControls.FormView.cs
  3. //
  4. // Author:
  5. // Merav Sudri ([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. #if NET_2_0
  30. using NUnit.Framework;
  31. using System;
  32. using System.Data;
  33. using System.Collections;
  34. using System.IO;
  35. using System.Drawing;
  36. using System.Collections.Specialized ;
  37. using System.Globalization;
  38. using System.Web;
  39. using System.Web.UI;
  40. using System.Web.UI.WebControls;
  41. using MonoTests.SystemWeb.Framework;
  42. using MonoTests.stand_alone.WebHarness;
  43. namespace MonoTests.System.Web.UI.WebControls
  44. {
  45. public class ParameterPoker:Parameter
  46. {
  47. public bool parameterChanged = false;
  48. public ParameterPoker () // constructor
  49. {
  50. TrackViewState ();
  51. }
  52. public ParameterPoker (Parameter p)
  53. : base (p)
  54. {
  55. }
  56. public ParameterPoker (String name)
  57. : base (name)
  58. {
  59. }
  60. public ParameterPoker (string name, TypeCode type)
  61. : base (name, type)
  62. {
  63. }
  64. public ParameterPoker (string name,TypeCode type, string defaultValue):base(name,type,defaultValue)
  65. {
  66. }
  67. public object SaveState ()
  68. {
  69. return SaveViewState ();
  70. }
  71. public void LoadState (object o)
  72. {
  73. LoadViewState (o);
  74. }
  75. public StateBag StateBag
  76. {
  77. get { return base.ViewState; }
  78. }
  79. public Parameter DoClone()
  80. {
  81. return base.Clone ();
  82. }
  83. public object DoEvaluate(HttpContext context, Control control)
  84. {
  85. return base.Evaluate (context,control );
  86. }
  87. //protected override void OnParameterChanged ()
  88. //{
  89. // parameterChanged = true;
  90. // base.OnParameterChanged ();
  91. //}
  92. public void DoSetDirty ()
  93. {
  94. base.SetDirty ();
  95. }
  96. public bool IsTrackingViewStatePoker
  97. {
  98. get {return base.IsTrackingViewState;}
  99. }
  100. }
  101. [TestFixture]
  102. public class ParameterTest
  103. {
  104. [Test]
  105. public void Parameter_DefaultProperties ()
  106. {
  107. ParameterPoker param = new ParameterPoker ();
  108. Assert.AreEqual (0, param.StateBag.Count, "ViewState.Count");
  109. Assert.AreEqual (true, param.ConvertEmptyStringToNull, "ConvertEmptyStringToNull");
  110. Assert.AreEqual (null, param.DefaultValue, "DefaultValue");
  111. Assert.AreEqual (ParameterDirection.Input,param.Direction,"Direction");
  112. Assert.AreEqual ("", param.Name, "Name");
  113. Assert.AreEqual (0, param.Size, "Size");
  114. Assert.AreEqual (TypeCode.Empty, param.Type, "Type");
  115. }
  116. [Test]
  117. public void Parameter_AssignToDefaultProperties ()
  118. {
  119. ParameterPoker param = new ParameterPoker ();
  120. param.ConvertEmptyStringToNull = false;
  121. Assert.AreEqual (false, param.ConvertEmptyStringToNull, "ConvertEmptyStringToNull");
  122. param.DefaultValue = "LName";
  123. Assert.AreEqual ("LName", param.DefaultValue, "DefaultValue");
  124. param.Direction = ParameterDirection.InputOutput;
  125. Assert.AreEqual (ParameterDirection.InputOutput, param.Direction, "DirectionInputOutput");
  126. param.Direction = ParameterDirection.Output;
  127. Assert.AreEqual (ParameterDirection.Output, param.Direction, "DirectionOutput");
  128. param.Direction = ParameterDirection.ReturnValue;
  129. Assert.AreEqual (ParameterDirection.ReturnValue, param.Direction, "DirectionReturnValue");
  130. param.Name = "paramName";
  131. Assert.AreEqual ("paramName", param.Name, "Name");
  132. param.Size = 10;
  133. Assert.AreEqual (10, param.Size, "Size");
  134. param.Type = TypeCode.Boolean;
  135. Assert.AreEqual (TypeCode.Boolean, param.Type, "BooleanType");
  136. param.Type = TypeCode.Byte;
  137. Assert.AreEqual (TypeCode.Byte, param.Type, "ByteType");
  138. param.Type = TypeCode.Char ;
  139. Assert.AreEqual (TypeCode.Char, param.Type, "CharType");
  140. param.Type = TypeCode.DateTime ;
  141. Assert.AreEqual (TypeCode.DateTime, param.Type, "DateTimeType");
  142. param.Type = TypeCode.DBNull ;
  143. Assert.AreEqual (TypeCode.DBNull, param.Type, "DBNullType");
  144. param.Type = TypeCode.Decimal;
  145. Assert.AreEqual (TypeCode.Decimal, param.Type, "DecimalType");
  146. param.Type = TypeCode.Double;
  147. Assert.AreEqual (TypeCode.Double, param.Type, "DoubleType");
  148. param.Type = TypeCode.Int16;
  149. Assert.AreEqual (TypeCode.Int16, param.Type, "Int16Type");
  150. param.Type = TypeCode.Int32;
  151. Assert.AreEqual (TypeCode.Int32, param.Type, "Int32Type");
  152. param.Type = TypeCode.Int64;
  153. Assert.AreEqual (TypeCode.Int64, param.Type, "Int64Type");
  154. param.Type = TypeCode.Object;
  155. Assert.AreEqual (TypeCode.Object, param.Type, "ObjectType");
  156. param.Type = TypeCode.SByte ;
  157. Assert.AreEqual (TypeCode.SByte, param.Type, "SByteType");
  158. param.Type = TypeCode.Single;
  159. Assert.AreEqual (TypeCode.Single, param.Type, "SingleType");
  160. param.Type = TypeCode.String;
  161. Assert.AreEqual (TypeCode.String, param.Type, "StringType");
  162. param.Type = TypeCode.UInt16;
  163. Assert.AreEqual (TypeCode.UInt16, param.Type, "UInt16Type");
  164. param.Type = TypeCode.UInt32;
  165. Assert.AreEqual (TypeCode.UInt32, param.Type, "UInt32Type");
  166. param.Type = TypeCode.UInt64;
  167. Assert.AreEqual (TypeCode.UInt64, param.Type, "UInt64Type");
  168. Assert.AreEqual (6, param.StateBag.Count, "ViewStateCount");
  169. }
  170. [Test]
  171. public void Parameter_ConvertEmptyStringToNull ()
  172. {
  173. ParameterPoker param = new ParameterPoker ("ID", TypeCode.String, "1001");
  174. param.ConvertEmptyStringToNull = false;
  175. }
  176. [Test]
  177. public void Parameter_DefaultProtectedProperties ()
  178. {
  179. ParameterPoker param = new ParameterPoker ();
  180. Assert.AreEqual (true, param.IsTrackingViewStatePoker, "IsTrackingViewState");
  181. }
  182. //Public methods
  183. [Test]
  184. public void Parameter_ToString ()
  185. {
  186. ParameterPoker param = new ParameterPoker ("ID",TypeCode.String ,"1001");
  187. Assert.AreEqual ("ID", param.ToString (), "ToString");
  188. }
  189. //Protected Methods
  190. [Test]
  191. public void Parameter_Clone ()
  192. {
  193. ParameterPoker param = new ParameterPoker ("ID", TypeCode.String, "1001");
  194. param.Size = 10;
  195. param.Direction = ParameterDirection.Output;
  196. Parameter p = param.DoClone ();
  197. Assert.AreEqual ("ID", p.Name, "Clone1");
  198. Assert.AreEqual (TypeCode.String, p.Type, "Clone2");
  199. Assert.AreEqual ("1001", p.DefaultValue, "Clone3");
  200. Assert.AreEqual (10, param.Size, "Clone4");
  201. Assert.AreEqual (ParameterDirection.Output, param.Direction, "Clone5");
  202. }
  203. [Test]
  204. [Category ("NunitWeb")]
  205. public void Parameter_Evaluate ()
  206. {
  207. string html = new WebTest (PageInvoker.CreateOnLoad (
  208. new PageDelegate (Evaluate))).Run ();
  209. WebTest.Unload ();
  210. }
  211. public static void Evaluate (Page p)
  212. {
  213. ParameterPoker param = new ParameterPoker ("ID", TypeCode.String, "1001");
  214. TextBox tb = new TextBox ();
  215. p.Controls.Add (tb);
  216. Object eval = param.DoEvaluate (HttpContext.Current, tb);
  217. //The default Evaluate method returns null in all cases
  218. Assert.AreEqual (null, eval, "ParameterEvaluate");
  219. }
  220. [Test]
  221. public void Parameter_DoSetDirty ()
  222. {
  223. ParameterPoker param = new ParameterPoker ("ID", TypeCode.String, "1001");
  224. object state = param.SaveState ();
  225. Assert.AreEqual (null, state, "BeforeSetDirtyMethod");
  226. param.DoSetDirty ();
  227. state = param.SaveState ();
  228. Assert.IsTrue (null != state, "AfterSetDirtyMethod1");
  229. }
  230. [Test]
  231. public void Parameter_ViewState ()
  232. {
  233. ParameterPoker param = new ParameterPoker ("ID", TypeCode.String, "1001");
  234. ParameterPoker copy = new ParameterPoker ();
  235. param.Size = 100;
  236. param.Direction = ParameterDirection.InputOutput;
  237. param.DoSetDirty ();
  238. object state = param.SaveState ();
  239. copy.LoadState (state);
  240. Assert.AreEqual ("1001", copy.DefaultValue, "DefaultValue");
  241. Assert.AreEqual (ParameterDirection.InputOutput, copy.Direction, "Direction");
  242. Assert.AreEqual (100, copy.Size, "Size");
  243. Assert.AreEqual (TypeCode.String, copy.Type, "Type");
  244. Assert.AreEqual ("ID", copy.Name, "Name");
  245. }
  246. }
  247. }
  248. #endif