ScriptBehaviorDescriptorTest.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. //
  2. // ScriptBehaviorDescriptorTest.cs
  3. //
  4. // Author:
  5. // Igor Zelmanovich <[email protected]>
  6. //
  7. // (C) 2007 Mainsoft, Inc. http://www.mainsoft.com
  8. //
  9. //
  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:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  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.
  28. //
  29. using System;
  30. using System.Collections.Generic;
  31. using System.Text;
  32. using NUnit.Framework;
  33. using System.Web.UI;
  34. namespace Tests.System.Web.UI
  35. {
  36. [TestFixture]
  37. public class ScriptBehaviorDescriptorTest
  38. {
  39. class PokerScriptBehaviorDescriptor : ScriptBehaviorDescriptor
  40. {
  41. public PokerScriptBehaviorDescriptor (string type, string elementID) : base (type, elementID) { }
  42. public string DoGetScript () {
  43. return GetScript ();
  44. }
  45. }
  46. [Test]
  47. public void ScriptBehaviorDescriptor_Defaults ()
  48. {
  49. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  50. Assert.AreEqual ("My.Type", scd.Type, "Type");
  51. Assert.AreEqual ("Type", scd.Name, "Name");
  52. Assert.AreEqual (String.Empty, scd.ID, "ID");
  53. Assert.AreEqual ("Element1$Type", scd.ClientID, "ClientID");
  54. Assert.AreEqual ("Element1", scd.ElementID, "ElementID");
  55. string script = scd.DoGetScript ();
  56. Assert.AreEqual ("$create(My.Type, null, null, null, $get(\"Element1\"));", script, "#A1");
  57. scd.ID = "SomeID";
  58. script = scd.DoGetScript ();
  59. Assert.AreEqual ("$create(My.Type, {\"id\":\"SomeID\"}, null, null, $get(\"Element1\"));", script, "#A2");
  60. scd.Name = "SomeName";
  61. script = scd.DoGetScript ();
  62. Assert.AreEqual ("$create(My.Type, {\"id\":\"SomeID\",\"name\":\"SomeName\"}, null, null, $get(\"Element1\"));", script, "#A3");
  63. }
  64. [Test]
  65. [ExpectedException (typeof (ArgumentException))]
  66. public void ScriptBehaviorDescriptor_ctor_exception_1 () {
  67. ScriptBehaviorDescriptor scd = new ScriptBehaviorDescriptor ("My.Type", null);
  68. }
  69. [Test]
  70. [ExpectedException (typeof (ArgumentException))]
  71. public void ScriptBehaviorDescriptor_ctor_exception_2 () {
  72. ScriptBehaviorDescriptor scd = new ScriptBehaviorDescriptor ("My.Type", String.Empty);
  73. }
  74. [Category("NotWorking")] // One must not depend on the order of keys in dictionary
  75. [Test]
  76. public void ScriptBehaviorDescriptor_AddComponentProperty () {
  77. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  78. scd.AddComponentProperty ("myName1", "myCompId1");
  79. scd.AddComponentProperty ("myName2", "myCompId2");
  80. string script = scd.DoGetScript ();
  81. #if TARGET_JVM
  82. Assert.AreEqual ("$create(My.Type, null, null, {\"myName2\":\"myCompId2\",\"myName1\":\"myCompId1\"}, $get(\"Element1\"));", script);
  83. #else
  84. Assert.AreEqual ("$create(My.Type, null, null, {\"myName1\":\"myCompId1\",\"myName2\":\"myCompId2\"}, $get(\"Element1\"));", script);
  85. #endif
  86. }
  87. [Category("NotWorking")] // One must not depend on the order of keys in dictionary
  88. [Test]
  89. public void ScriptBehaviorDescriptor_AddElementProperty () {
  90. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  91. scd.AddElementProperty ("myName1", "myElemId1");
  92. scd.AddElementProperty ("myName2", "myElemId2");
  93. string script = scd.DoGetScript ();
  94. #if TARGET_JVM
  95. Assert.AreEqual ("$create(My.Type, {\"myName2\":$get(\"myElemId2\"),\"myName1\":$get(\"myElemId1\")}, null, null, $get(\"Element1\"));", script);
  96. #else
  97. Assert.AreEqual ("$create(My.Type, {\"myName1\":$get(\"myElemId1\"),\"myName2\":$get(\"myElemId2\")}, null, null, $get(\"Element1\"));", script);
  98. #endif
  99. }
  100. [Category("NotWorking")] // One must not depend on the order of keys in dictionary
  101. [Test]
  102. public void ScriptBehaviorDescriptor_AddProperty () {
  103. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  104. scd.AddProperty ("myName1", "myValue1");
  105. scd.AddProperty ("myName2", "myValue2");
  106. string script = scd.DoGetScript ();
  107. #if TARGET_JVM
  108. Assert.AreEqual ("$create(My.Type, {\"myName2\":\"myValue2\",\"myName1\":\"myValue1\"}, null, null, $get(\"Element1\"));", script);
  109. #else
  110. Assert.AreEqual ("$create(My.Type, {\"myName1\":\"myValue1\",\"myName2\":\"myValue2\"}, null, null, $get(\"Element1\"));", script);
  111. #endif
  112. }
  113. [Category("NotWorking")] // One must not depend on the order of keys in dictionary
  114. [Test]
  115. public void ScriptBehaviorDescriptor_AddProperty_Null () {
  116. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  117. scd.AddProperty ("myName1", null);
  118. scd.AddProperty ("myName2", null);
  119. string script = scd.DoGetScript ();
  120. #if TARGET_JVM
  121. Assert.AreEqual ("$create(My.Type, {\"myName2\":null,\"myName1\":null}, null, null, $get(\"Element1\"));", script);
  122. #else
  123. Assert.AreEqual ("$create(My.Type, {\"myName1\":null,\"myName2\":null}, null, null, $get(\"Element1\"));", script);
  124. #endif
  125. }
  126. [Category("NotWorking")] // One must not depend on the order of keys in dictionary
  127. [Test]
  128. public void ScriptBehaviorDescriptor_AddEvent () {
  129. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  130. scd.AddEvent ("myName1", "myHandler1");
  131. scd.AddEvent ("myName2", "myHandler2");
  132. string script = scd.DoGetScript ();
  133. #if TARGET_JVM
  134. Assert.AreEqual ("$create(My.Type, null, {\"myName2\":myHandler2,\"myName1\":myHandler1}, null, $get(\"Element1\"));", script);
  135. #else
  136. Assert.AreEqual ("$create(My.Type, null, {\"myName1\":myHandler1,\"myName2\":myHandler2}, null, $get(\"Element1\"));", script);
  137. #endif
  138. }
  139. [Category("NotWorking")] // One must not depend on the order of keys in dictionary
  140. [Test]
  141. public void ScriptBehaviorDescriptor_AddScriptProperty () {
  142. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  143. scd.AddScriptProperty ("myName1", "myScript1");
  144. scd.AddScriptProperty ("myName2", "myScript2");
  145. string script = scd.DoGetScript ();
  146. #if TARGET_JVM
  147. Assert.AreEqual ("$create(My.Type, {\"myName2\":myScript2,\"myName1\":myScript1}, null, null, $get(\"Element1\"));", script);
  148. #else
  149. Assert.AreEqual ("$create(My.Type, {\"myName1\":myScript1,\"myName2\":myScript2}, null, null, $get(\"Element1\"));", script);
  150. #endif
  151. }
  152. [Test]
  153. [ExpectedException (typeof (ArgumentException))]
  154. public void ScriptBehaviorDescriptor_Type_exception_1 () {
  155. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  156. scd.Type = null;
  157. }
  158. [Test]
  159. [ExpectedException (typeof (ArgumentException))]
  160. public void ScriptBehaviorDescriptor_Type_exception_2 () {
  161. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  162. scd.Type = String.Empty;
  163. }
  164. [Test]
  165. public void ScriptBehaviorDescriptor_Type () {
  166. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  167. scd.Type = "New.Type";
  168. Assert.AreEqual ("New.Type", scd.Type, "Type");
  169. }
  170. [Test]
  171. public void ScriptBehaviorDescriptor_ID () {
  172. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  173. scd.ID = null;
  174. Assert.AreEqual (String.Empty, scd.ID, "#1");
  175. scd.ID = String.Empty;
  176. Assert.AreEqual (String.Empty, scd.ID, "#2");
  177. scd.ID = "My ID";
  178. Assert.AreEqual ("My ID", scd.ID, "#3");
  179. Assert.AreEqual ("My ID", scd.ClientID, "#4");
  180. }
  181. [Test]
  182. public void ScriptBehaviorDescriptor_Name () {
  183. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  184. scd.Name = null;
  185. Assert.AreEqual ("Type", scd.Name, "#1");
  186. scd.Name = String.Empty;
  187. Assert.AreEqual ("Type", scd.Name, "#2");
  188. scd.Name = "MyName";
  189. Assert.AreEqual ("MyName", scd.Name, "#3");
  190. Assert.AreEqual ("Element1$MyName", scd.ClientID, "#4");
  191. scd.Name = "MyName.MyType";
  192. Assert.AreEqual ("MyName.MyType", scd.Name, "#5");
  193. scd.Name = null;
  194. Assert.AreEqual ("Type", scd.Name, "#6");
  195. }
  196. }
  197. }