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