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.
34 using System.Collections.Generic;
36 using NUnit.Framework;
39 using System.Web.UI.WebControls;
40 using MonoTests.SystemWeb.Framework;
41 using MonoTests.stand_alone.WebHarness;
43 namespace MonoTests.System.Web.UI.WebControls
45 public class SessionParameterPoker : SessionParameter
47 public SessionParameterPoker()
52 public SessionParameterPoker(SessionParameter param)
57 public SessionParameterPoker(string name, string sessionField)
58 : base(name, sessionField)
61 public SessionParameterPoker(string name, TypeCode type, string sessionField)
62 : base(name, type, sessionField)
66 public object DoEvaluate(HttpContext context, Control control)
68 return base.Evaluate(context, control);
71 public Parameter DoClone()
76 public object SaveState()
78 return SaveViewState();
80 public void LoadState(object o)
85 public StateBag StateBag
87 get { return base.ViewState; }
93 public class SessionParameterTest
96 public void SessionParameter_DefaultProperties()
98 SessionParameterPoker sessionParam1 = new SessionParameterPoker();
99 Assert.AreEqual("", sessionParam1.SessionField, "DefaultSessionField");
100 SessionParameterPoker sessionParam2 = new SessionParameterPoker("Name", "id");
101 Assert.AreEqual("Name", sessionParam2.Name, "OverloadConstructorName1");
102 Assert.AreEqual("id", sessionParam2.SessionField, "OverloadConstructorSessionField1");
103 SessionParameterPoker sessionParam3 = new SessionParameterPoker("Name", TypeCode.Int64, "id");
104 Assert.AreEqual("Name", sessionParam3.Name, "OverloadConstructorName2");
105 Assert.AreEqual("id", sessionParam3.SessionField, "OverloadConstructorsessionField2");
106 Assert.AreEqual(TypeCode.Int64, sessionParam3.Type, "OverloadConstructorType2");
107 SessionParameterPoker sessionParam4 = new SessionParameterPoker(sessionParam3);
108 Assert.AreEqual("Name", sessionParam4.Name, "OverloadConstructorName3");
109 Assert.AreEqual("id", sessionParam4.SessionField, "OverloadConstructorSessionField3");
110 Assert.AreEqual(TypeCode.Int64, sessionParam4.Type, "OverloadConstructorType3");
116 public void SessionParameter_AssignToDefaultProperties()
118 SessionParameterPoker sessionParam = new SessionParameterPoker();
119 sessionParam.SessionField = "Test";
120 Assert.AreEqual("Test", sessionParam.SessionField, "AssignToSessionField");
127 public void SessionParameter_Clone()
129 SessionParameterPoker sessionParam = new SessionParameterPoker("EmployeeName", TypeCode.String, "Name");
130 SessionParameter clonedParam = (SessionParameter)sessionParam.DoClone();
131 Assert.AreEqual("EmployeeName", clonedParam.Name, "SessionParameterCloneName");
132 Assert.AreEqual(TypeCode.String, clonedParam.Type, "SessionParameterCloneType");
137 [Category("NunitWeb")]
138 [Category("NotWorking")]
139 public void SessionParameter_Evaluate()
141 SessionParameterPoker sessionParam = new SessionParameterPoker("employee",TypeCode.String ,"id") ;
142 Button b = new Button();
143 string value = (string)sessionParam.DoEvaluate(null, b);
144 Assert.AreEqual(null, value, "EvaluateSessionWhenNullContext");
145 WebTest t = new WebTest();
146 PageDelegates pd = new PageDelegates();
147 pd.Init = InitSesssion;
148 pd.Load = EvaluateSession;
149 t.Invoker = new PageInvoker(pd);
150 string html = t.Run();
156 public static void InitSesssion(Page p)
158 p.Session["key"] = "Key1";
161 public static void EvaluateSession(Page p)
163 SessionParameterPoker sessionParam = new SessionParameterPoker();
164 sessionParam.SessionField = "key";
165 sessionParam.Type = TypeCode.String;
166 TextBox tb = new TextBox();
168 string value = (string)sessionParam.DoEvaluate(HttpContext.Current, tb);
169 Assert.AreEqual("Key1", value, "EvaluateSessionParameter");