8df2646880e70b375bae750b05c2bb8bade28992
[mono.git] / mcs / class / System.Web.Extensions / Test / System.Web.UI / ScriptControlDescriptorTest.cs
1 //
2 // ScriptControlDescriptorTest.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 ScriptControlDescriptorTest
40         {
41                 class PokerScriptControlDescriptor : ScriptControlDescriptor
42                 {
43                         public PokerScriptControlDescriptor (string type, string elementID) : base (type, elementID) { }
44
45                         public string DoGetScript () {
46                                 return GetScript ();
47                         }
48                 }
49
50                 [Test]
51                 public void ScriptControlDescriptor_Defaults () {
52                         PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
53
54                         Assert.AreEqual ("My.Type", scd.Type, "Type");
55                         Assert.AreEqual (String.Empty, scd.ID, "ID");
56                         Assert.AreEqual ("Element1", scd.ClientID, "ClientID");
57                         Assert.AreEqual ("Element1", scd.ElementID, "ElementID");
58
59                         string script = scd.DoGetScript ();
60                         Assert.AreEqual ("$create(My.Type, null, null, null, $get(\"Element1\"));", script);
61                 }
62
63                 [Test]
64                 [ExpectedException (typeof (ArgumentException))]
65                 public void ScriptControlDescriptor_ctor_exception_1 () {
66                         ScriptControlDescriptor scd = new ScriptControlDescriptor ("My.Type", null);
67                 }
68
69                 [Test]
70                 [ExpectedException (typeof (ArgumentException))]
71                 public void ScriptControlDescriptor_ctor_exception_2 () {
72                         ScriptControlDescriptor scd = new ScriptControlDescriptor ("My.Type", String.Empty);
73                 }
74
75                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
76                 [Test]
77                 public void ScriptControlDescriptor_AddComponentProperty () {
78                         PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
79                         scd.AddComponentProperty ("myName1", "myCompId1");
80                         scd.AddComponentProperty ("myName2", "myCompId2");
81
82                         string script = scd.DoGetScript ();
83 #if TARGET_JVM
84                         Assert.AreEqual ("$create(My.Type, null, null, {\"myName2\":\"myCompId2\",\"myName1\":\"myCompId1\"}, $get(\"Element1\"));", script);
85 #else
86                         Assert.AreEqual ("$create(My.Type, null, null, {\"myName1\":\"myCompId1\",\"myName2\":\"myCompId2\"}, $get(\"Element1\"));", script);
87 #endif
88                 }
89
90                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
91                 [Test]
92                 public void ScriptControlDescriptor_AddElementProperty () {
93                         PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
94                         scd.AddElementProperty ("myName1", "myElemId1");
95                         scd.AddElementProperty ("myName2", "myElemId2");
96
97                         string script = scd.DoGetScript ();
98 #if TARGET_JVM
99                         Assert.AreEqual ("$create(My.Type, {\"myName2\":$get(\"myElemId2\"),\"myName1\":$get(\"myElemId1\")}, null, null, $get(\"Element1\"));", script);
100 #else
101                         Assert.AreEqual ("$create(My.Type, {\"myName1\":$get(\"myElemId1\"),\"myName2\":$get(\"myElemId2\")}, null, null, $get(\"Element1\"));", script);
102 #endif
103                 }
104
105                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
106                 [Test]
107                 public void ScriptControlDescriptor_AddProperty () {
108                         PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
109                         scd.AddProperty ("myName1", "myValue1");
110                         scd.AddProperty ("myName2", "myValue2");
111
112                         string script = scd.DoGetScript ();
113 #if TARGET_JVM
114                         Assert.AreEqual ("$create(My.Type, {\"myName2\":\"myValue2\",\"myName1\":\"myValue1\"}, null, null, $get(\"Element1\"));", script);
115 #else
116                         Assert.AreEqual ("$create(My.Type, {\"myName1\":\"myValue1\",\"myName2\":\"myValue2\"}, null, null, $get(\"Element1\"));", script);
117 #endif
118                 }
119
120                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
121                 [Test]
122                 public void ScriptControlDescriptor_AddProperty_Null () {
123                         PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
124                         scd.AddProperty ("myName1", null);
125                         scd.AddProperty ("myName2", null);
126
127                         string script = scd.DoGetScript ();
128 #if TARGET_JVM
129                         Assert.AreEqual ("$create(My.Type, {\"myName2\":null,\"myName1\":null}, null, null, $get(\"Element1\"));", script);
130 #else
131                         Assert.AreEqual ("$create(My.Type, {\"myName1\":null,\"myName2\":null}, null, null, $get(\"Element1\"));", script);
132 #endif
133                 }
134
135                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
136                 [Test]
137                 public void ScriptControlDescriptor_AddEvent () {
138                         PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
139                         scd.AddEvent ("myName1", "myHandler1");
140                         scd.AddEvent ("myName2", "myHandler2");
141
142                         string script = scd.DoGetScript ();
143 #if TARGET_JVM
144                         Assert.AreEqual ("$create(My.Type, null, {\"myName2\":myHandler2,\"myName1\":myHandler1}, null, $get(\"Element1\"));", script);
145 #else
146                         Assert.AreEqual ("$create(My.Type, null, {\"myName1\":myHandler1,\"myName2\":myHandler2}, null, $get(\"Element1\"));", script);
147 #endif
148                 }
149
150                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
151                 [Test]
152                 public void ScriptControlDescriptor_AddScriptProperty () {
153                         PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
154                         scd.AddScriptProperty ("myName1", "myScript1");
155                         scd.AddScriptProperty ("myName2", "myScript2");
156
157                         string script = scd.DoGetScript ();
158 #if TARGET_JVM
159                         Assert.AreEqual ("$create(My.Type, {\"myName2\":myScript2,\"myName1\":myScript1}, null, null, $get(\"Element1\"));", script);
160 #else
161                         Assert.AreEqual ("$create(My.Type, {\"myName1\":myScript1,\"myName2\":myScript2}, null, null, $get(\"Element1\"));", script);
162 #endif
163                 }
164
165                 [Test]
166                 [ExpectedException (typeof (ArgumentException))]
167                 public void ScriptControlDescriptor_Type_exception_1 () {
168                         PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
169                         scd.Type = null;
170                 }
171
172                 [Test]
173                 [ExpectedException (typeof (ArgumentException))]
174                 public void ScriptControlDescriptor_Type_exception_2 () {
175                         PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
176                         scd.Type = String.Empty;
177                 }
178
179                 [Test]
180                 public void ScriptControlDescriptor_Type () {
181                         PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
182                         scd.Type = "New.Type";
183                         Assert.AreEqual ("New.Type", scd.Type, "Type");
184                 }
185
186                 [Test]
187                 [ExpectedException (typeof (InvalidOperationException))]
188                 public void ScriptControlDescriptor_ID_set () {
189                         PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
190                         scd.ID = "My ID";
191                 }
192         }
193 }