2 // Tests for System.Web.UI.WebControls.FormView.cs
5 // Merav Sudri (meravs@mainsoft.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
33 using System.Collections.Generic;
35 using NUnit.Framework;
38 using System.Web.UI.WebControls;
40 namespace MonoTests.System.Web.UI.WebControls
42 public class ControlParameterPoker : ControlParameter
44 public ControlParameterPoker (ControlParameter control)
49 public ControlParameterPoker (string name,TypeCode type, string controlID,string propertyName)
50 :base(name,type,controlID,propertyName)
54 public ControlParameterPoker (string name, string controlId, string propertyName)
55 : base (name, controlId, propertyName)
60 public ControlParameterPoker (string name, string controlId)
61 : base (name, controlId)
65 public ControlParameterPoker() // constructor
70 public object DoEvaluate (HttpContext context,Control control)
72 return base.Evaluate (context,control);
75 public Parameter DoClone ()
80 public object SaveState ()
82 return SaveViewState ();
86 public void LoadState (object o)
91 public StateBag StateBag
93 get { return base.ViewState; }
99 public class ControlParameterTest
102 public void ControlParameter_DefaultProperties ()
104 ControlParameterPoker ctrlParam1 = new ControlParameterPoker ();
105 Assert.AreEqual ("",ctrlParam1.ControlID, "ControlIdDefault");
106 Assert.AreEqual ("", ctrlParam1.PropertyName, "PropertyNameDefault");
107 ControlParameterPoker ctrlParam2 = new ControlParameterPoker ("ControlTest","ControlID");
108 Assert.AreEqual ("ControlID", ctrlParam2.ControlID, "OverloadConstructorControlId1");
109 Assert.AreEqual ("ControlTest", ctrlParam2.Name, "OverloadConstructorPropertyName1");
110 ControlParameterPoker ctrlParam3 = new ControlParameterPoker ("Age",TypeCode.Int32,"Label1","Text");
111 Assert.AreEqual ("Age", ctrlParam3.Name, "OverloadConstructorName2");
112 Assert.AreEqual (TypeCode.Int32, ctrlParam3.Type, "OverloadConstructorType2");
113 Assert.AreEqual ("Label1", ctrlParam3.ControlID, "OverloadConstructorControlID2");
114 Assert.AreEqual ("Text", ctrlParam3.PropertyName, "OverloadConstructorPropertyName2");
115 ControlParameterPoker ctrlParam4 = new ControlParameterPoker ("Age","Label1","Text");
116 Assert.AreEqual ("Age", ctrlParam4.Name, "OverloadConstructorName3");
117 Assert.AreEqual ("Label1", ctrlParam4.ControlID, "OverloadConstructorControlID3");
118 Assert.AreEqual ("Text", ctrlParam4.PropertyName, "OverloadConstructorPropertyName3");
119 ControlParameterPoker ctrlParam5 = new ControlParameterPoker (ctrlParam3);
120 Assert.AreEqual ("Age", ctrlParam3.Name, "OverloadConstructorName4");
121 Assert.AreEqual (TypeCode.Int32, ctrlParam3.Type, "OverloadConstructorType4");
122 Assert.AreEqual ("Label1", ctrlParam3.ControlID, "OverloadConstructorControlID4");
123 Assert.AreEqual ("Text", ctrlParam3.PropertyName, "OverloadConstructorPropertyName4");
127 public void ControlParameter_AssignToDefaultProperties ()
129 ControlParameterPoker ctrlParam = new ControlParameterPoker ();
130 ctrlParam.PropertyName = "Text";
131 Assert.AreEqual ("Text",ctrlParam.PropertyName ,"AssignToPropertyName");
132 ctrlParam.ControlID ="Label";
133 Assert.AreEqual ("Label",ctrlParam.ControlID ,"AssignToPropertyName");
139 public void ControlParameter_Clone ()
141 ControlParameterPoker ctrlParam = new ControlParameterPoker ("Salary", TypeCode.Int64, "TextBox1", "Text");
142 ControlParameter clonedParam = (ControlParameter)ctrlParam.DoClone ();
143 Assert.AreEqual ("Salary", clonedParam.Name, "ClonedParamName");
144 Assert.AreEqual (TypeCode.Int64, clonedParam.Type, "ClonedParamType");
145 Assert.AreEqual ("TextBox1", clonedParam.ControlID, "ClonedParamControlID");
146 Assert.AreEqual ("Text", clonedParam.PropertyName, "ClonedParamPropertyName");
150 public void ControlParameter_Evaluate ()
152 ControlParameterPoker ctrlParam = new ControlParameterPoker ("Salary",TypeCode.Int64,"Label1","Text");
153 Page page = new Page ();
154 Label label1 = new Label ();
155 label1.ID = "Label1";
156 label1.Text = "2000";
157 page.Controls.Add (label1);
158 string value=(string)ctrlParam.DoEvaluate (HttpContext.Current,label1);
159 Assert.AreEqual ("2000", value, "EvaluateValue1");
160 label1.Text = "TestNewValue";
161 ctrlParam.Type = TypeCode.String;
162 value = (string) ctrlParam.DoEvaluate (HttpContext.Current, label1);
163 Assert.AreEqual ("TestNewValue", value, "EvaluateValue2");
167 [ExpectedException (typeof (ArgumentException))]
168 public void EvaluateArgumemtException ()
170 ControlParameterPoker ctrlParam = new ControlParameterPoker ();
171 TextBox textBox1 = new TextBox ();
172 textBox1.ID = "textbox1";
173 Page page = new Page ();
174 page.Controls.Add (textBox1);
175 ctrlParam.DoEvaluate (HttpContext.Current, textBox1);
178 [ExpectedException (typeof (InvalidOperationException))]
179 public void EvaluateInvalidOperationException ()
181 ControlParameterPoker ctrlParam = new ControlParameterPoker ("age", "Button", "parameter");
182 Button b = new Button ();
183 Page page = new Page ();
184 page.Controls.Add (b);
185 ctrlParam.DoEvaluate (HttpContext.Current, b);