2 // ScriptComponentDescriptorTest.cs
5 // Igor Zelmanovich <igorz@mainsoft.com>
7 // (C) 2007 Mainsoft, Inc. http://www.mainsoft.com
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
31 using System.Collections.Generic;
33 using NUnit.Framework;
36 namespace Tests.System.Web.UI
39 public class ScriptComponentDescriptorTest
41 class PokerScriptComponentDescriptor : ScriptComponentDescriptor
43 public PokerScriptComponentDescriptor (string type) : base (type) { }
45 public string DoGetScript () {
51 public void ScriptComponentDescriptor_Defaults () {
52 PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
54 Assert.AreEqual ("My.Type", scd.Type, "Type");
55 Assert.AreEqual (String.Empty, scd.ID, "ID");
56 Assert.AreEqual (String.Empty, scd.ClientID, "ClientID");
58 string script = scd.DoGetScript ();
59 Assert.AreEqual ("$create(My.Type, null, null, null);", script);
63 [ExpectedException (typeof (ArgumentException))]
64 public void ScriptComponentDescriptor_ctor_exception_1 () {
65 ScriptComponentDescriptor scd = new ScriptComponentDescriptor (null);
69 [ExpectedException (typeof (ArgumentException))]
70 public void ScriptComponentDescriptor_ctor_exception_2 () {
71 ScriptComponentDescriptor scd = new ScriptComponentDescriptor (String.Empty);
74 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
76 public void ScriptComponentDescriptor_AddComponentProperty () {
77 PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
78 scd.AddComponentProperty ("myName1", "myCompId1");
79 scd.AddComponentProperty ("myName2", "myCompId2");
81 string script = scd.DoGetScript ();
83 Assert.AreEqual ("$create(My.Type, null, null, {\"myName2\":\"myCompId2\",\"myName1\":\"myCompId1\"});", script);
85 Assert.AreEqual ("$create(My.Type, null, null, {\"myName1\":\"myCompId1\",\"myName2\":\"myCompId2\"});", script);
89 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
91 public void ScriptComponentDescriptor_AddElementProperty () {
92 PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
93 scd.AddElementProperty ("myName1", "myElemId1");
94 scd.AddElementProperty ("myName2", "myElemId2");
96 string script = scd.DoGetScript ();
98 Assert.AreEqual ("$create(My.Type, {\"myName2\":$get(\"myElemId2\"),\"myName1\":$get(\"myElemId1\")}, null, null);", script);
100 Assert.AreEqual ("$create(My.Type, {\"myName1\":$get(\"myElemId1\"),\"myName2\":$get(\"myElemId2\")}, null, null);", script);
104 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
106 public void ScriptComponentDescriptor_AddProperty () {
107 PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
108 scd.AddProperty ("myName1", "myValue1");
109 scd.AddProperty ("myName2", "myValue2");
111 string script = scd.DoGetScript ();
113 Assert.AreEqual ("$create(My.Type, {\"myName2\":\"myValue2\",\"myName1\":\"myValue1\"}, null, null);", script);
115 Assert.AreEqual ("$create(My.Type, {\"myName1\":\"myValue1\",\"myName2\":\"myValue2\"}, null, null);", script);
119 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
121 public void ScriptComponentDescriptor_AddProperty_Null () {
122 PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
123 scd.AddProperty ("myName1", null);
124 scd.AddProperty ("myName2", null);
126 string script = scd.DoGetScript ();
128 Assert.AreEqual ("$create(My.Type, {\"myName2\":null,\"myName1\":null}, null, null);", script);
130 Assert.AreEqual ("$create(My.Type, {\"myName1\":null,\"myName2\":null}, null, null);", script);
134 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
136 public void ScriptComponentDescriptor_AddEvent () {
137 PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
138 scd.AddEvent ("myName1", "myHandler1");
139 scd.AddEvent ("myName2", "myHandler2");
141 string script = scd.DoGetScript ();
143 Assert.AreEqual ("$create(My.Type, null, {\"myName2\":myHandler2,\"myName1\":myHandler1}, null);", script);
145 Assert.AreEqual ("$create(My.Type, null, {\"myName1\":myHandler1,\"myName2\":myHandler2}, null);", script);
149 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
151 public void ScriptComponentDescriptor_AddScriptProperty () {
152 PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
153 scd.AddScriptProperty ("myName1", "myScript1");
154 scd.AddScriptProperty ("myName2", "myScript2");
156 string script = scd.DoGetScript ();
158 Assert.AreEqual ("$create(My.Type, {\"myName2\":myScript2,\"myName1\":myScript1}, null, null);", script);
160 Assert.AreEqual ("$create(My.Type, {\"myName1\":myScript1,\"myName2\":myScript2}, null, null);", script);
165 [ExpectedException (typeof (ArgumentException))]
166 public void ScriptComponentDescriptor_Type_exception_1 () {
167 PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
172 [ExpectedException (typeof (ArgumentException))]
173 public void ScriptComponentDescriptor_Type_exception_2 () {
174 PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
175 scd.Type = String.Empty;
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");
186 public void ScriptComponentDescriptor_ID () {
187 PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
189 Assert.AreEqual (String.Empty, scd.ID, "#1");
190 scd.ID = String.Empty;
191 Assert.AreEqual (String.Empty, scd.ID, "#2");
193 Assert.AreEqual ("My ID", scd.ID, "#3");
194 Assert.AreEqual ("My ID", scd.ClientID, "#4");