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