[Cleanup] Removed TARGET_JVM
[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                         Assert.AreEqual ("$create(My.Type, null, null, {\"myName1\":\"myCompId1\",\"myName2\":\"myCompId2\"}, $get(\"Element1\"));", script);
94                 }
95
96                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
97                 [Test]
98                 public void ScriptBehaviorDescriptor_AddElementProperty () {
99                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
100                         scd.AddElementProperty ("myName1", "myElemId1");
101                         scd.AddElementProperty ("myName2", "myElemId2");
102
103                         string script = scd.DoGetScript ();
104                         Assert.AreEqual ("$create(My.Type, {\"myName1\":$get(\"myElemId1\"),\"myName2\":$get(\"myElemId2\")}, null, null, $get(\"Element1\"));", script);
105                 }
106
107                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
108                 [Test]
109                 public void ScriptBehaviorDescriptor_AddProperty () {
110                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
111                         scd.AddProperty ("myName1", "myValue1");
112                         scd.AddProperty ("myName2", "myValue2");
113
114                         string script = scd.DoGetScript ();
115                         Assert.AreEqual ("$create(My.Type, {\"myName1\":\"myValue1\",\"myName2\":\"myValue2\"}, null, null, $get(\"Element1\"));", script);
116                 }
117
118                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
119                 [Test]
120                 public void ScriptBehaviorDescriptor_AddProperty_Null () {
121                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
122                         scd.AddProperty ("myName1", null);
123                         scd.AddProperty ("myName2", null);
124
125                         string script = scd.DoGetScript ();
126                         Assert.AreEqual ("$create(My.Type, {\"myName1\":null,\"myName2\":null}, null, null, $get(\"Element1\"));", script);
127                 }
128
129                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
130                 [Test]
131                 public void ScriptBehaviorDescriptor_AddEvent () {
132                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
133                         scd.AddEvent ("myName1", "myHandler1");
134                         scd.AddEvent ("myName2", "myHandler2");
135
136                         string script = scd.DoGetScript ();
137                         Assert.AreEqual ("$create(My.Type, null, {\"myName1\":myHandler1,\"myName2\":myHandler2}, null, $get(\"Element1\"));", script);
138                 }
139
140                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
141                 [Test]
142                 public void ScriptBehaviorDescriptor_AddScriptProperty () {
143                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
144                         scd.AddScriptProperty ("myName1", "myScript1");
145                         scd.AddScriptProperty ("myName2", "myScript2");
146
147                         string script = scd.DoGetScript ();
148                         Assert.AreEqual ("$create(My.Type, {\"myName1\":myScript1,\"myName2\":myScript2}, null, null, $get(\"Element1\"));", script);
149                 }
150
151                 [Test]
152                 [ExpectedException (typeof (ArgumentException))]
153                 public void ScriptBehaviorDescriptor_Type_exception_1 () {
154                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
155                         scd.Type = null;
156                 }
157
158                 [Test]
159                 [ExpectedException (typeof (ArgumentException))]
160                 public void ScriptBehaviorDescriptor_Type_exception_2 () {
161                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
162                         scd.Type = String.Empty;
163                 }
164
165                 [Test]
166                 public void ScriptBehaviorDescriptor_Type () {
167                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
168                         scd.Type = "New.Type";
169                         Assert.AreEqual ("New.Type", scd.Type, "Type");
170                 }
171
172                 [Test]
173                 public void ScriptBehaviorDescriptor_ID () {
174                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
175                         scd.ID = null;
176                         Assert.AreEqual (String.Empty, scd.ID, "#1");
177                         scd.ID = String.Empty;
178                         Assert.AreEqual (String.Empty, scd.ID, "#2");
179                         scd.ID = "My ID";
180                         Assert.AreEqual ("My ID", scd.ID, "#3");
181                         Assert.AreEqual ("My ID", scd.ClientID, "#4");
182                 }
183
184                 [Test]
185                 public void ScriptBehaviorDescriptor_Name () {
186                         PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
187                         scd.Name = null;
188                         Assert.AreEqual ("Type", scd.Name, "#1");
189                         scd.Name = String.Empty;
190                         Assert.AreEqual ("Type", scd.Name, "#2");
191                         scd.Name = "MyName";
192                         Assert.AreEqual ("MyName", scd.Name, "#3");
193                         Assert.AreEqual ("Element1$MyName", scd.ClientID, "#4");
194                         scd.Name = "MyName.MyType";
195                         Assert.AreEqual ("MyName.MyType", scd.Name, "#5");
196                         scd.Name = null;
197                         Assert.AreEqual ("Type", scd.Name, "#6");
198                 }
199         }
200 }