69d065ec5fda66585783c29dd59a6a4a876a46a0
[mono.git] / mcs / class / System.Web.Extensions / Test / System.Web.UI / ScriptBehaviorDescriptorTest.cs
1 //
2 // ScriptBehaviorDescriptorTest.cs
3 //
4 // Author:
5 //   Igor Zelmanovich <igorz@mainsoft.com>
6 //
7 // (C) 2007 Mainsoft, Inc.  http://www.mainsoft.com
8 //
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 System.Web.UI;
35
36 namespace Tests.System.Web.UI
37 {
38         [TestFixture]
39         public class ScriptBehaviorDescriptorTest
40         {
41                 class PokerScriptBehaviorDescriptor : ScriptBehaviorDescriptor
42                 {
43                         public PokerScriptBehaviorDescriptor (string type, string elementID) : base (type, elementID) { }
44
45                         public string DoGetScript () {
46                                 return GetScript ();
47                         }
48                 }
49
50                 [Test]
51                 public void ScriptBehaviorDescriptor_Defaults ()
52                 {
53                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
54
55                         Assert.AreEqual ("My.Type", scd.Type, "Type");
56                         Assert.AreEqual ("Type", scd.Name, "Name");
57                         Assert.AreEqual (String.Empty, scd.ID, "ID");
58                         Assert.AreEqual ("Element1$Type", scd.ClientID, "ClientID");
59                         Assert.AreEqual ("Element1", scd.ElementID, "ElementID");
60
61                         string script = scd.DoGetScript ();
62                         Assert.AreEqual ("$create(My.Type, null, null, null, $get(\"Element1\"));", script, "#A1");
63
64                         scd.ID = "SomeID";
65                         script = scd.DoGetScript ();
66                         Assert.AreEqual ("$create(My.Type, {\"id\":\"SomeID\"}, null, null, $get(\"Element1\"));", script, "#A2");
67
68                         scd.Name = "SomeName";
69                         script = scd.DoGetScript ();
70                         Assert.AreEqual ("$create(My.Type, {\"id\":\"SomeID\",\"name\":\"SomeName\"}, null, null, $get(\"Element1\"));", script, "#A3");
71                 }
72
73                 [Test]
74                 [ExpectedException (typeof (ArgumentException))]
75                 public void ScriptBehaviorDescriptor_ctor_exception_1 () {
76                         ScriptBehaviorDescriptor scd = new ScriptBehaviorDescriptor ("My.Type", null);
77                 }
78
79                 [Test]
80                 [ExpectedException (typeof (ArgumentException))]
81                 public void ScriptBehaviorDescriptor_ctor_exception_2 () {
82                         ScriptBehaviorDescriptor scd = new ScriptBehaviorDescriptor ("My.Type", String.Empty);
83                 }
84
85                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
86                 [Test]
87                 public void ScriptBehaviorDescriptor_AddComponentProperty () {
88                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
89                         scd.AddComponentProperty ("myName1", "myCompId1");
90                         scd.AddComponentProperty ("myName2", "myCompId2");
91
92                         string script = scd.DoGetScript ();
93 #if TARGET_JVM
94                         Assert.AreEqual ("$create(My.Type, null, null, {\"myName2\":\"myCompId2\",\"myName1\":\"myCompId1\"}, $get(\"Element1\"));", script);
95 #else
96                         Assert.AreEqual ("$create(My.Type, null, null, {\"myName1\":\"myCompId1\",\"myName2\":\"myCompId2\"}, $get(\"Element1\"));", script);
97 #endif
98                 }
99
100                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
101                 [Test]
102                 public void ScriptBehaviorDescriptor_AddElementProperty () {
103                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
104                         scd.AddElementProperty ("myName1", "myElemId1");
105                         scd.AddElementProperty ("myName2", "myElemId2");
106
107                         string script = scd.DoGetScript ();
108 #if TARGET_JVM
109                         Assert.AreEqual ("$create(My.Type, {\"myName2\":$get(\"myElemId2\"),\"myName1\":$get(\"myElemId1\")}, null, null, $get(\"Element1\"));", script);
110 #else
111                         Assert.AreEqual ("$create(My.Type, {\"myName1\":$get(\"myElemId1\"),\"myName2\":$get(\"myElemId2\")}, null, null, $get(\"Element1\"));", script);
112 #endif
113                 }
114
115                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
116                 [Test]
117                 public void ScriptBehaviorDescriptor_AddProperty () {
118                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
119                         scd.AddProperty ("myName1", "myValue1");
120                         scd.AddProperty ("myName2", "myValue2");
121
122                         string script = scd.DoGetScript ();
123 #if TARGET_JVM
124                         Assert.AreEqual ("$create(My.Type, {\"myName2\":\"myValue2\",\"myName1\":\"myValue1\"}, null, null, $get(\"Element1\"));", script);
125 #else
126                         Assert.AreEqual ("$create(My.Type, {\"myName1\":\"myValue1\",\"myName2\":\"myValue2\"}, null, null, $get(\"Element1\"));", script);
127 #endif
128                 }
129
130                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
131                 [Test]
132                 public void ScriptBehaviorDescriptor_AddProperty_Null () {
133                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
134                         scd.AddProperty ("myName1", null);
135                         scd.AddProperty ("myName2", null);
136
137                         string script = scd.DoGetScript ();
138 #if TARGET_JVM
139                         Assert.AreEqual ("$create(My.Type, {\"myName2\":null,\"myName1\":null}, null, null, $get(\"Element1\"));", script);
140 #else
141                         Assert.AreEqual ("$create(My.Type, {\"myName1\":null,\"myName2\":null}, null, null, $get(\"Element1\"));", script);
142 #endif
143                 }
144
145                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
146                 [Test]
147                 public void ScriptBehaviorDescriptor_AddEvent () {
148                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
149                         scd.AddEvent ("myName1", "myHandler1");
150                         scd.AddEvent ("myName2", "myHandler2");
151
152                         string script = scd.DoGetScript ();
153 #if TARGET_JVM
154                         Assert.AreEqual ("$create(My.Type, null, {\"myName2\":myHandler2,\"myName1\":myHandler1}, null, $get(\"Element1\"));", script);
155 #else
156                         Assert.AreEqual ("$create(My.Type, null, {\"myName1\":myHandler1,\"myName2\":myHandler2}, null, $get(\"Element1\"));", script);
157 #endif
158                 }
159
160                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
161                 [Test]
162                 public void ScriptBehaviorDescriptor_AddScriptProperty () {
163                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
164                         scd.AddScriptProperty ("myName1", "myScript1");
165                         scd.AddScriptProperty ("myName2", "myScript2");
166
167                         string script = scd.DoGetScript ();
168 #if TARGET_JVM
169                         Assert.AreEqual ("$create(My.Type, {\"myName2\":myScript2,\"myName1\":myScript1}, null, null, $get(\"Element1\"));", script);
170 #else
171                         Assert.AreEqual ("$create(My.Type, {\"myName1\":myScript1,\"myName2\":myScript2}, null, null, $get(\"Element1\"));", script);
172 #endif
173                 }
174
175                 [Test]
176                 [ExpectedException (typeof (ArgumentException))]
177                 public void ScriptBehaviorDescriptor_Type_exception_1 () {
178                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
179                         scd.Type = null;
180                 }
181
182                 [Test]
183                 [ExpectedException (typeof (ArgumentException))]
184                 public void ScriptBehaviorDescriptor_Type_exception_2 () {
185                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
186                         scd.Type = String.Empty;
187                 }
188
189                 [Test]
190                 public void ScriptBehaviorDescriptor_Type () {
191                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
192                         scd.Type = "New.Type";
193                         Assert.AreEqual ("New.Type", scd.Type, "Type");
194                 }
195
196                 [Test]
197                 public void ScriptBehaviorDescriptor_ID () {
198                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
199                         scd.ID = null;
200                         Assert.AreEqual (String.Empty, scd.ID, "#1");
201                         scd.ID = String.Empty;
202                         Assert.AreEqual (String.Empty, scd.ID, "#2");
203                         scd.ID = "My ID";
204                         Assert.AreEqual ("My ID", scd.ID, "#3");
205                         Assert.AreEqual ("My ID", scd.ClientID, "#4");
206                 }
207
208                 [Test]
209                 public void ScriptBehaviorDescriptor_Name () {
210                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
211                         scd.Name = null;
212                         Assert.AreEqual ("Type", scd.Name, "#1");
213                         scd.Name = String.Empty;
214                         Assert.AreEqual ("Type", scd.Name, "#2");
215                         scd.Name = "MyName";
216                         Assert.AreEqual ("MyName", scd.Name, "#3");
217                         Assert.AreEqual ("Element1$MyName", scd.ClientID, "#4");
218                         scd.Name = "MyName.MyType";
219                         Assert.AreEqual ("MyName.MyType", scd.Name, "#5");
220                         scd.Name = null;
221                         Assert.AreEqual ("Type", scd.Name, "#6");
222                 }
223         }
224 }