2 // ScriptControlDescriptorTest.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 ScriptControlDescriptorTest
41 class PokerScriptControlDescriptor : ScriptControlDescriptor
43 public PokerScriptControlDescriptor (string type, string elementID) : base (type, elementID) { }
45 public string DoGetScript () {
51 public void ScriptControlDescriptor_Defaults () {
52 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
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");
59 string script = scd.DoGetScript ();
60 Assert.AreEqual ("$create(My.Type, null, null, null, $get(\"Element1\"));", script);
64 [ExpectedException (typeof (ArgumentException))]
65 public void ScriptControlDescriptor_ctor_exception_1 () {
66 ScriptControlDescriptor scd = new ScriptControlDescriptor ("My.Type", null);
70 [ExpectedException (typeof (ArgumentException))]
71 public void ScriptControlDescriptor_ctor_exception_2 () {
72 ScriptControlDescriptor scd = new ScriptControlDescriptor ("My.Type", String.Empty);
75 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
77 public void ScriptControlDescriptor_AddComponentProperty () {
78 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
79 scd.AddComponentProperty ("myName1", "myCompId1");
80 scd.AddComponentProperty ("myName2", "myCompId2");
82 string script = scd.DoGetScript ();
84 Assert.AreEqual ("$create(My.Type, null, null, {\"myName2\":\"myCompId2\",\"myName1\":\"myCompId1\"}, $get(\"Element1\"));", script);
86 Assert.AreEqual ("$create(My.Type, null, null, {\"myName1\":\"myCompId1\",\"myName2\":\"myCompId2\"}, $get(\"Element1\"));", script);
90 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
92 public void ScriptControlDescriptor_AddElementProperty () {
93 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
94 scd.AddElementProperty ("myName1", "myElemId1");
95 scd.AddElementProperty ("myName2", "myElemId2");
97 string script = scd.DoGetScript ();
99 Assert.AreEqual ("$create(My.Type, {\"myName2\":$get(\"myElemId2\"),\"myName1\":$get(\"myElemId1\")}, null, null, $get(\"Element1\"));", script);
101 Assert.AreEqual ("$create(My.Type, {\"myName1\":$get(\"myElemId1\"),\"myName2\":$get(\"myElemId2\")}, null, null, $get(\"Element1\"));", script);
105 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
107 public void ScriptControlDescriptor_AddProperty () {
108 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
109 scd.AddProperty ("myName1", "myValue1");
110 scd.AddProperty ("myName2", "myValue2");
112 string script = scd.DoGetScript ();
114 Assert.AreEqual ("$create(My.Type, {\"myName2\":\"myValue2\",\"myName1\":\"myValue1\"}, null, null, $get(\"Element1\"));", script);
116 Assert.AreEqual ("$create(My.Type, {\"myName1\":\"myValue1\",\"myName2\":\"myValue2\"}, null, null, $get(\"Element1\"));", script);
120 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
122 public void ScriptControlDescriptor_AddProperty_Null () {
123 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
124 scd.AddProperty ("myName1", null);
125 scd.AddProperty ("myName2", null);
127 string script = scd.DoGetScript ();
129 Assert.AreEqual ("$create(My.Type, {\"myName2\":null,\"myName1\":null}, null, null, $get(\"Element1\"));", script);
131 Assert.AreEqual ("$create(My.Type, {\"myName1\":null,\"myName2\":null}, null, null, $get(\"Element1\"));", script);
135 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
137 public void ScriptControlDescriptor_AddEvent () {
138 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
139 scd.AddEvent ("myName1", "myHandler1");
140 scd.AddEvent ("myName2", "myHandler2");
142 string script = scd.DoGetScript ();
144 Assert.AreEqual ("$create(My.Type, null, {\"myName2\":myHandler2,\"myName1\":myHandler1}, null, $get(\"Element1\"));", script);
146 Assert.AreEqual ("$create(My.Type, null, {\"myName1\":myHandler1,\"myName2\":myHandler2}, null, $get(\"Element1\"));", script);
150 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
152 public void ScriptControlDescriptor_AddScriptProperty () {
153 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
154 scd.AddScriptProperty ("myName1", "myScript1");
155 scd.AddScriptProperty ("myName2", "myScript2");
157 string script = scd.DoGetScript ();
159 Assert.AreEqual ("$create(My.Type, {\"myName2\":myScript2,\"myName1\":myScript1}, null, null, $get(\"Element1\"));", script);
161 Assert.AreEqual ("$create(My.Type, {\"myName1\":myScript1,\"myName2\":myScript2}, null, null, $get(\"Element1\"));", script);
166 [ExpectedException (typeof (ArgumentException))]
167 public void ScriptControlDescriptor_Type_exception_1 () {
168 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
173 [ExpectedException (typeof (ArgumentException))]
174 public void ScriptControlDescriptor_Type_exception_2 () {
175 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
176 scd.Type = String.Empty;
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");
187 [ExpectedException (typeof (InvalidOperationException))]
188 public void ScriptControlDescriptor_ID_set () {
189 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");