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 ();
83 Assert.AreEqual ("$create(My.Type, null, null, {\"myName1\":\"myCompId1\",\"myName2\":\"myCompId2\"}, $get(\"Element1\"));", script);
86 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
88 public void ScriptControlDescriptor_AddElementProperty () {
89 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
90 scd.AddElementProperty ("myName1", "myElemId1");
91 scd.AddElementProperty ("myName2", "myElemId2");
93 string script = scd.DoGetScript ();
94 Assert.AreEqual ("$create(My.Type, {\"myName1\":$get(\"myElemId1\"),\"myName2\":$get(\"myElemId2\")}, null, null, $get(\"Element1\"));", script);
97 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
99 public void ScriptControlDescriptor_AddProperty () {
100 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
101 scd.AddProperty ("myName1", "myValue1");
102 scd.AddProperty ("myName2", "myValue2");
104 string script = scd.DoGetScript ();
105 Assert.AreEqual ("$create(My.Type, {\"myName1\":\"myValue1\",\"myName2\":\"myValue2\"}, null, null, $get(\"Element1\"));", script);
108 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
110 public void ScriptControlDescriptor_AddProperty_Null () {
111 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
112 scd.AddProperty ("myName1", null);
113 scd.AddProperty ("myName2", null);
115 string script = scd.DoGetScript ();
116 Assert.AreEqual ("$create(My.Type, {\"myName1\":null,\"myName2\":null}, null, null, $get(\"Element1\"));", script);
119 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
121 public void ScriptControlDescriptor_AddEvent () {
122 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
123 scd.AddEvent ("myName1", "myHandler1");
124 scd.AddEvent ("myName2", "myHandler2");
126 string script = scd.DoGetScript ();
127 Assert.AreEqual ("$create(My.Type, null, {\"myName1\":myHandler1,\"myName2\":myHandler2}, null, $get(\"Element1\"));", script);
130 [Category("NotWorking")] // One must not depend on the order of keys in dictionary
132 public void ScriptControlDescriptor_AddScriptProperty () {
133 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
134 scd.AddScriptProperty ("myName1", "myScript1");
135 scd.AddScriptProperty ("myName2", "myScript2");
137 string script = scd.DoGetScript ();
138 Assert.AreEqual ("$create(My.Type, {\"myName1\":myScript1,\"myName2\":myScript2}, null, null, $get(\"Element1\"));", script);
142 [ExpectedException (typeof (ArgumentException))]
143 public void ScriptControlDescriptor_Type_exception_1 () {
144 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
149 [ExpectedException (typeof (ArgumentException))]
150 public void ScriptControlDescriptor_Type_exception_2 () {
151 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
152 scd.Type = String.Empty;
156 public void ScriptControlDescriptor_Type () {
157 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");
158 scd.Type = "New.Type";
159 Assert.AreEqual ("New.Type", scd.Type, "Type");
163 [ExpectedException (typeof (InvalidOperationException))]
164 public void ScriptControlDescriptor_ID_set () {
165 PokerScriptControlDescriptor scd = new PokerScriptControlDescriptor ("My.Type", "Element1");