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 ();
93 Assert.AreEqual ("$create(My.Type, null, null, {\"myName1\":\"myCompId1\",\"myName2\":\"myCompId2\"}, $get(\"Element1\"));", script);
96 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
98 public void ScriptBehaviorDescriptor_AddElementProperty () {
99 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
100 scd.AddElementProperty ("myName1", "myElemId1");
101 scd.AddElementProperty ("myName2", "myElemId2");
103 string script = scd.DoGetScript ();
104 Assert.AreEqual ("$create(My.Type, {\"myName1\":$get(\"myElemId1\"),\"myName2\":$get(\"myElemId2\")}, null, null, $get(\"Element1\"));", script);
107 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
109 public void ScriptBehaviorDescriptor_AddProperty () {
110 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
111 scd.AddProperty ("myName1", "myValue1");
112 scd.AddProperty ("myName2", "myValue2");
114 string script = scd.DoGetScript ();
115 Assert.AreEqual ("$create(My.Type, {\"myName1\":\"myValue1\",\"myName2\":\"myValue2\"}, null, null, $get(\"Element1\"));", script);
118 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
120 public void ScriptBehaviorDescriptor_AddProperty_Null () {
121 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
122 scd.AddProperty ("myName1", null);
123 scd.AddProperty ("myName2", null);
125 string script = scd.DoGetScript ();
126 Assert.AreEqual ("$create(My.Type, {\"myName1\":null,\"myName2\":null}, null, null, $get(\"Element1\"));", script);
129 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
131 public void ScriptBehaviorDescriptor_AddEvent () {
132 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
133 scd.AddEvent ("myName1", "myHandler1");
134 scd.AddEvent ("myName2", "myHandler2");
136 string script = scd.DoGetScript ();
137 Assert.AreEqual ("$create(My.Type, null, {\"myName1\":myHandler1,\"myName2\":myHandler2}, null, $get(\"Element1\"));", script);
140 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
142 public void ScriptBehaviorDescriptor_AddScriptProperty () {
143 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
144 scd.AddScriptProperty ("myName1", "myScript1");
145 scd.AddScriptProperty ("myName2", "myScript2");
147 string script = scd.DoGetScript ();
148 Assert.AreEqual ("$create(My.Type, {\"myName1\":myScript1,\"myName2\":myScript2}, null, null, $get(\"Element1\"));", script);
152 [ExpectedException (typeof (ArgumentException))]
153 public void ScriptBehaviorDescriptor_Type_exception_1 () {
154 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
159 [ExpectedException (typeof (ArgumentException))]
160 public void ScriptBehaviorDescriptor_Type_exception_2 () {
161 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
162 scd.Type = String.Empty;
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");
173 public void ScriptBehaviorDescriptor_ID () {
174 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
176 Assert.AreEqual (String.Empty, scd.ID, "#1");
177 scd.ID = String.Empty;
178 Assert.AreEqual (String.Empty, scd.ID, "#2");
180 Assert.AreEqual ("My ID", scd.ID, "#3");
181 Assert.AreEqual ("My ID", scd.ClientID, "#4");
185 public void ScriptBehaviorDescriptor_Name () {
186 PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
188 Assert.AreEqual ("Type", scd.Name, "#1");
189 scd.Name = String.Empty;
190 Assert.AreEqual ("Type", scd.Name, "#2");
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");
197 Assert.AreEqual ("Type", scd.Name, "#6");