2 // ScriptBehaviorDescriptorTest.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 ScriptBehaviorDescriptorTest
41 class PokerScriptBehaviorDescriptor : ScriptBehaviorDescriptor
43 public PokerScriptBehaviorDescriptor (string type, string elementID) : base (type, elementID) { }
45 public string DoGetScript () {
51 public void ScriptBehaviorDescriptor_Defaults ()
53 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
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");
61 string script = scd.DoGetScript ();
62 Assert.AreEqual ("$create(My.Type, null, null, null, $get(\"Element1\"));", script, "#A1");
65 script = scd.DoGetScript ();
66 Assert.AreEqual ("$create(My.Type, {\"id\":\"SomeID\"}, null, null, $get(\"Element1\"));", script, "#A2");
68 scd.Name = "SomeName";
69 script = scd.DoGetScript ();
70 Assert.AreEqual ("$create(My.Type, {\"id\":\"SomeID\",\"name\":\"SomeName\"}, null, null, $get(\"Element1\"));", script, "#A3");
74 [ExpectedException (typeof (ArgumentException))]
75 public void ScriptBehaviorDescriptor_ctor_exception_1 () {
76 ScriptBehaviorDescriptor scd = new ScriptBehaviorDescriptor ("My.Type", null);
80 [ExpectedException (typeof (ArgumentException))]
81 public void ScriptBehaviorDescriptor_ctor_exception_2 () {
82 ScriptBehaviorDescriptor scd = new ScriptBehaviorDescriptor ("My.Type", String.Empty);
85 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
87 public void ScriptBehaviorDescriptor_AddComponentProperty () {
88 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
89 scd.AddComponentProperty ("myName1", "myCompId1");
90 scd.AddComponentProperty ("myName2", "myCompId2");
92 string script = scd.DoGetScript ();
94 Assert.AreEqual ("$create(My.Type, null, null, {\"myName2\":\"myCompId2\",\"myName1\":\"myCompId1\"}, $get(\"Element1\"));", script);
96 Assert.AreEqual ("$create(My.Type, null, null, {\"myName1\":\"myCompId1\",\"myName2\":\"myCompId2\"}, $get(\"Element1\"));", script);
100 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
102 public void ScriptBehaviorDescriptor_AddElementProperty () {
103 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
104 scd.AddElementProperty ("myName1", "myElemId1");
105 scd.AddElementProperty ("myName2", "myElemId2");
107 string script = scd.DoGetScript ();
109 Assert.AreEqual ("$create(My.Type, {\"myName2\":$get(\"myElemId2\"),\"myName1\":$get(\"myElemId1\")}, null, null, $get(\"Element1\"));", script);
111 Assert.AreEqual ("$create(My.Type, {\"myName1\":$get(\"myElemId1\"),\"myName2\":$get(\"myElemId2\")}, null, null, $get(\"Element1\"));", script);
115 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
117 public void ScriptBehaviorDescriptor_AddProperty () {
118 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
119 scd.AddProperty ("myName1", "myValue1");
120 scd.AddProperty ("myName2", "myValue2");
122 string script = scd.DoGetScript ();
124 Assert.AreEqual ("$create(My.Type, {\"myName2\":\"myValue2\",\"myName1\":\"myValue1\"}, null, null, $get(\"Element1\"));", script);
126 Assert.AreEqual ("$create(My.Type, {\"myName1\":\"myValue1\",\"myName2\":\"myValue2\"}, null, null, $get(\"Element1\"));", script);
130 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
132 public void ScriptBehaviorDescriptor_AddProperty_Null () {
133 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
134 scd.AddProperty ("myName1", null);
135 scd.AddProperty ("myName2", null);
137 string script = scd.DoGetScript ();
139 Assert.AreEqual ("$create(My.Type, {\"myName2\":null,\"myName1\":null}, null, null, $get(\"Element1\"));", script);
141 Assert.AreEqual ("$create(My.Type, {\"myName1\":null,\"myName2\":null}, null, null, $get(\"Element1\"));", script);
145 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
147 public void ScriptBehaviorDescriptor_AddEvent () {
148 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
149 scd.AddEvent ("myName1", "myHandler1");
150 scd.AddEvent ("myName2", "myHandler2");
152 string script = scd.DoGetScript ();
154 Assert.AreEqual ("$create(My.Type, null, {\"myName2\":myHandler2,\"myName1\":myHandler1}, null, $get(\"Element1\"));", script);
156 Assert.AreEqual ("$create(My.Type, null, {\"myName1\":myHandler1,\"myName2\":myHandler2}, null, $get(\"Element1\"));", script);
160 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
162 public void ScriptBehaviorDescriptor_AddScriptProperty () {
163 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
164 scd.AddScriptProperty ("myName1", "myScript1");
165 scd.AddScriptProperty ("myName2", "myScript2");
167 string script = scd.DoGetScript ();
169 Assert.AreEqual ("$create(My.Type, {\"myName2\":myScript2,\"myName1\":myScript1}, null, null, $get(\"Element1\"));", script);
171 Assert.AreEqual ("$create(My.Type, {\"myName1\":myScript1,\"myName2\":myScript2}, null, null, $get(\"Element1\"));", script);
176 [ExpectedException (typeof (ArgumentException))]
177 public void ScriptBehaviorDescriptor_Type_exception_1 () {
178 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
183 [ExpectedException (typeof (ArgumentException))]
184 public void ScriptBehaviorDescriptor_Type_exception_2 () {
185 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
186 scd.Type = String.Empty;
190 public void ScriptBehaviorDescriptor_Type () {
191 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
192 scd.Type = "New.Type";
193 Assert.AreEqual ("New.Type", scd.Type, "Type");
197 public void ScriptBehaviorDescriptor_ID () {
198 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
200 Assert.AreEqual (String.Empty, scd.ID, "#1");
201 scd.ID = String.Empty;
202 Assert.AreEqual (String.Empty, scd.ID, "#2");
204 Assert.AreEqual ("My ID", scd.ID, "#3");
205 Assert.AreEqual ("My ID", scd.ClientID, "#4");
209 public void ScriptBehaviorDescriptor_Name () {
210 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
212 Assert.AreEqual ("Type", scd.Name, "#1");
213 scd.Name = String.Empty;
214 Assert.AreEqual ("Type", scd.Name, "#2");
216 Assert.AreEqual ("MyName", scd.Name, "#3");
217 Assert.AreEqual ("Element1$MyName", scd.ClientID, "#4");
218 scd.Name = "MyName.MyType";
219 Assert.AreEqual ("MyName.MyType", scd.Name, "#5");
221 Assert.AreEqual ("Type", scd.Name, "#6");