[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / CallBackTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.CallBackTest.cs
3 //
4 // Author:
5 //      Yoni Klein (yonik@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 using System;
31 using System.Collections.Generic;
32 using System.Text;
33 using NUnit.Framework;
34 using MonoTests.SystemWeb.Framework;
35 using System.Web.UI;
36 using System.Threading;
37
38 namespace MonoTests.System.Web.UI.WebControls
39 {
40
41
42         [TestFixture]
43         public class CallBackTest
44         {
45                 [TestFixtureSetUp]
46                 public void Set_Up ()
47                 {
48                         WebTest.CopyResource (GetType (), "CallbackTest1.aspx", "CallbackTest1.aspx");
49                         WebTest.CopyResource (GetType (), "CallbackTest2.aspx", "CallbackTest2.aspx");
50                 }
51
52                 [SetUp]
53                 public void SetupTestCase ()
54                 {
55                         Thread.Sleep (100);
56                 }
57
58                 [Test]
59                 [Category("NunitWeb")]
60                 [Category ("NotDotNet")] // for dot-net use __CALLBACKID insted __CALLBACKTARGET and __CALLBACKARGUMENT insted __CALLBACKPARAM
61                 public void CallBackResulrValues ()
62                 {
63                         WebTest t = new WebTest ("CallbackTest1.aspx");
64                         string html = t.Run ();
65                         PageDelegates pd = new PageDelegates ();
66                         pd.Load = Load;
67                         t.Invoker = new PageInvoker (pd);
68
69                         FormRequest fr = new FormRequest (t.Response, "form1");
70                         fr.Controls.Add ("__EVENTTARGET");
71                         fr.Controls.Add ("__EVENTARGUMENT");
72                         fr.Controls.Add ("__CALLBACKID");
73                         fr.Controls.Add ("__CALLBACKPARAM");
74                         fr.Controls["__EVENTTARGET"].Value = "";
75                         fr.Controls["__EVENTARGUMENT"].Value = "";
76                         fr.Controls ["__CALLBACKID"].Value = "__Page";
77                         fr.Controls ["__CALLBACKPARAM"].Value = "monitor";
78
79                         t.Request = fr;
80                         html = t.Run ();
81                         
82                         // Into result string the last 2 variables shows if events been done
83                         // first - RaiseCallbackEvent
84                         // second - GetCallbackResult
85
86                         if (html.IndexOf ("12|true|true") < 0)
87                                 Assert.Fail ("CallBack#1");
88
89                         fr.Controls["__EVENTTARGET"].Value = "";
90                         fr.Controls["__EVENTARGUMENT"].Value = "";
91                         fr.Controls ["__CALLBACKID"].Value = "__Page";
92                         fr.Controls ["__CALLBACKPARAM"].Value = "laptop";
93
94                         t.Request = fr;
95                         html = t.Run ();
96
97                         // Into result string the last 2 variables shows if events been done
98                         // first - RaiseCallbackEvent
99                         // second - GetCallbackResult
100
101                         if (html.IndexOf ("10|true|true") < 0)
102                                 Assert.Fail ("CallBack#2");
103                 }
104
105                 public static void Load (Page p)
106                 {
107                         Assert.AreEqual (true, p.IsCallback, "IsCallbackDoneFail");
108                 }
109
110                 [Test]
111                 [Category ("NunitWeb")]
112                 [Category ("NotDotNet")] // for dot-net use __CALLBACKID insted __CALLBACKTARGET and __CALLBACKARGUMENT insted __CALLBACKPARAM
113                 public void CallBackFlow ()
114                 {
115                         WebTest t = new WebTest ("CallbackTest2.aspx");
116                         string html = t.Run ();
117
118                         PageDelegates pd = new PageDelegates ();
119                         pd.Load = callBackFlow_Load;
120                         t.Invoker = new PageInvoker (pd);
121
122                         FormRequest fr = new FormRequest (t.Response, "form1");
123                         fr.Controls.Add ("__EVENTTARGET");
124                         fr.Controls.Add ("__EVENTARGUMENT");
125                         fr.Controls.Add ("__CALLBACKID");
126                         fr.Controls.Add ("__CALLBACKPARAM");
127                         fr.Controls["__EVENTTARGET"].Value = "";
128                         fr.Controls["__EVENTARGUMENT"].Value = "";
129                         fr.Controls ["__CALLBACKID"].Value = "__Page";
130                         fr.Controls ["__CALLBACKPARAM"].Value = "";
131                         t.Request = fr;
132                         
133                         html = t.Run ();
134
135                         // GetCallbackResult return string contained all flow functions name
136
137                         if (html.IndexOf ("|PreInit|Init|InitComplete|PreLoad|Load|LoadComplete|RaiseCallbackEvent|GetCallbackResult") < 0)
138                                 Assert.Fail ("CallBackPageFlow");
139                 }
140
141                 public static void callBackFlow_Load (Page p)
142                 {
143                         Assert.AreEqual (true, p.IsCallback, "IsCallbackDoneFail");
144                 }
145
146                 [TestFixtureTearDown]
147                 public void Unload ()
148                 {
149                         WebTest.Unload ();
150                 }
151         }
152 }