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