Merge pull request #1304 from slluis/mac-proxy-autoconfig
[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                 {
53                         PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
54
55                         Assert.AreEqual ("My.Type", scd.Type, "Type");
56                         Assert.AreEqual (String.Empty, scd.ID, "ID");
57                         Assert.AreEqual (String.Empty, scd.ClientID, "ClientID");
58
59                         string script = scd.DoGetScript ();
60                         Assert.AreEqual ("$create(My.Type, null, null, null);", script, "#A1");
61
62                         scd.ID = "SomeID";
63                         script = scd.DoGetScript ();
64                         Assert.AreEqual ("$create(My.Type, {\"id\":\"SomeID\"}, null, null);", script, "#A2");
65                 }
66
67                 [Test]
68                 [ExpectedException (typeof (ArgumentException))]
69                 public void ScriptComponentDescriptor_ctor_exception_1 () {
70                         ScriptComponentDescriptor scd = new ScriptComponentDescriptor (null);
71                 }
72
73                 [Test]
74                 [ExpectedException (typeof (ArgumentException))]
75                 public void ScriptComponentDescriptor_ctor_exception_2 () {
76                         ScriptComponentDescriptor scd = new ScriptComponentDescriptor (String.Empty);
77                 }
78
79                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
80                 [Test]
81                 public void ScriptComponentDescriptor_AddComponentProperty () {
82                         PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
83                         scd.AddComponentProperty ("myName1", "myCompId1");
84                         scd.AddComponentProperty ("myName2", "myCompId2");
85
86                         string script = scd.DoGetScript ();
87                         Assert.AreEqual ("$create(My.Type, null, null, {\"myName1\":\"myCompId1\",\"myName2\":\"myCompId2\"});", script);
88                 }
89
90                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
91                 [Test]
92                 public void ScriptComponentDescriptor_AddElementProperty () {
93                         PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
94                         scd.AddElementProperty ("myName1", "myElemId1");
95                         scd.AddElementProperty ("myName2", "myElemId2");
96
97                         string script = scd.DoGetScript ();
98                         Assert.AreEqual ("$create(My.Type, {\"myName1\":$get(\"myElemId1\"),\"myName2\":$get(\"myElemId2\")}, null, null);", script);
99                 }
100
101                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
102                 [Test]
103                 public void ScriptComponentDescriptor_AddProperty () {
104                         PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
105                         scd.AddProperty ("myName1", "myValue1");
106                         scd.AddProperty ("myName2", "myValue2");
107
108                         string script = scd.DoGetScript ();
109                         Assert.AreEqual ("$create(My.Type, {\"myName1\":\"myValue1\",\"myName2\":\"myValue2\"}, null, null);", script);
110                 }
111
112                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
113                 [Test]
114                 public void ScriptComponentDescriptor_AddProperty_Null () {
115                         PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
116                         scd.AddProperty ("myName1", null);
117                         scd.AddProperty ("myName2", null);
118
119                         string script = scd.DoGetScript ();
120                         Assert.AreEqual ("$create(My.Type, {\"myName1\":null,\"myName2\":null}, null, null);", script);
121                 }
122
123                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
124                 [Test]
125                 public void ScriptComponentDescriptor_AddEvent () {
126                         PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
127                         scd.AddEvent ("myName1", "myHandler1");
128                         scd.AddEvent ("myName2", "myHandler2");
129
130                         string script = scd.DoGetScript ();
131                         Assert.AreEqual ("$create(My.Type, null, {\"myName1\":myHandler1,\"myName2\":myHandler2}, null);", script);
132                 }
133
134                 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
135                 [Test]
136                 public void ScriptComponentDescriptor_AddScriptProperty () {
137                         PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
138                         scd.AddScriptProperty ("myName1", "myScript1");
139                         scd.AddScriptProperty ("myName2", "myScript2");
140
141                         string script = scd.DoGetScript ();
142                         Assert.AreEqual ("$create(My.Type, {\"myName1\":myScript1,\"myName2\":myScript2}, null, null);", script);
143                 }
144
145                 [Test]
146                 [ExpectedException (typeof (ArgumentException))]
147                 public void ScriptComponentDescriptor_Type_exception_1 () {
148                         PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
149                         scd.Type = null;
150                 }
151
152                 [Test]
153                 [ExpectedException (typeof (ArgumentException))]
154                 public void ScriptComponentDescriptor_Type_exception_2 () {
155                         PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
156                         scd.Type = String.Empty;
157                 }
158
159                 [Test]
160                 public void ScriptComponentDescriptor_Type () {
161                         PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
162                         scd.Type = "New.Type";
163                         Assert.AreEqual ("New.Type", scd.Type, "Type");
164                 }
165
166                 [Test]
167                 public void ScriptComponentDescriptor_ID () {
168                         PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
169                         scd.ID = null;
170                         Assert.AreEqual (String.Empty, scd.ID, "#1");
171                         scd.ID = String.Empty;
172                         Assert.AreEqual (String.Empty, scd.ID, "#2");
173                         scd.ID = "My ID";
174                         Assert.AreEqual ("My ID", scd.ID, "#3");
175                         Assert.AreEqual ("My ID", scd.ClientID, "#4");
176                 }
177         }
178 }