[Cleanup] Removed TARGET_JVM
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / SessionParameterTest.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 System;
33 using System.IO;
34 using System.Collections.Generic;
35 using System.Text;
36 using NUnit.Framework;
37 using System.Web;
38 using System.Web.UI;
39 using System.Web.UI.WebControls;
40 using MonoTests.SystemWeb.Framework;
41 using MonoTests.stand_alone.WebHarness;
42
43 namespace MonoTests.System.Web.UI.WebControls
44 {
45         public class SessionParameterPoker : SessionParameter
46         {
47                 public SessionParameterPoker()
48                 {
49                         TrackViewState();
50                 }
51
52                 public SessionParameterPoker(SessionParameter param)
53                         : base(param)
54                 {
55                 }
56
57                 public SessionParameterPoker(string name, string sessionField)
58                         : base(name, sessionField)
59                 {
60                 }
61                 public SessionParameterPoker(string name, TypeCode type, string sessionField)
62                         : base(name, type, sessionField)
63                 {
64                 }
65
66                 public object DoEvaluate(HttpContext context, Control control)
67                 {
68                         return base.Evaluate(context, control);
69                 }
70
71                 public Parameter DoClone()
72                 {
73                         return base.Clone();
74                 }
75
76                 public object SaveState()
77                 {
78                         return SaveViewState();
79                 }
80                 public void LoadState(object o)
81                 {
82                         LoadViewState(o);
83                 }
84
85                 public StateBag StateBag
86                 {
87                         get { return base.ViewState; }
88                 }
89
90         }
91
92         [TestFixture]
93         public class SessionParameterTest
94         {
95                 [Test]
96                 public void SessionParameter_DefaultProperties()
97                 {
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");
111
112
113                 }
114
115                 [Test]
116                 public void SessionParameter_AssignToDefaultProperties()
117                 {
118                         SessionParameterPoker sessionParam = new SessionParameterPoker();
119                         sessionParam.SessionField = "Test";
120                         Assert.AreEqual("Test", sessionParam.SessionField, "AssignToSessionField");
121
122                 }
123
124                 //Protected Methods
125
126                 [Test]
127                 public void SessionParameter_Clone()
128                 {
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");
133                         
134                 }
135
136                 [Test]
137                 [Category("NunitWeb")]
138                 [Category("NotWorking")]
139                 public void SessionParameter_Evaluate()
140                 {
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();
151                         WebTest.Unload(); 
152                         
153
154                 }
155
156                 public static void InitSesssion(Page p)
157                 {
158                         p.Session["key"] = "Key1"; 
159                 }
160
161                 public static void EvaluateSession(Page p)
162                 {
163                         SessionParameterPoker sessionParam = new SessionParameterPoker();
164                         sessionParam.SessionField = "key";
165                         sessionParam.Type = TypeCode.String;
166                         TextBox tb = new TextBox();
167                         p.Controls.Add(tb); 
168                         string value = (string)sessionParam.DoEvaluate(HttpContext.Current, tb);
169                         Assert.AreEqual("Key1", value, "EvaluateSessionParameter");
170                 }
171
172         }
173 }
174 #endif