ScriptBehaviorDescriptorTest.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  49. Assert.AreEqual ("My.Type", scd.Type, "Type");
  50. Assert.AreEqual ("Type", scd.Name, "Name");
  51. Assert.AreEqual (String.Empty, scd.ID, "ID");
  52. Assert.AreEqual ("Element1$Type", scd.ClientID, "ClientID");
  53. Assert.AreEqual ("Element1", scd.ElementID, "ElementID");
  54. string script = scd.DoGetScript ();
  55. Assert.AreEqual ("$create(My.Type, null, null, null, $get(\"Element1\"));", script);
  56. }
  57. [Test]
  58. [ExpectedException (typeof (ArgumentException))]
  59. public void ScriptBehaviorDescriptor_ctor_exception_1 () {
  60. ScriptBehaviorDescriptor scd = new ScriptBehaviorDescriptor ("My.Type", null);
  61. }
  62. [Test]
  63. [ExpectedException (typeof (ArgumentException))]
  64. public void ScriptBehaviorDescriptor_ctor_exception_2 () {
  65. ScriptBehaviorDescriptor scd = new ScriptBehaviorDescriptor ("My.Type", String.Empty);
  66. }
  67. [Category("NotWorking")] // One must not depend on the order of keys in dictionary
  68. [Test]
  69. public void ScriptBehaviorDescriptor_AddComponentProperty () {
  70. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  71. scd.AddComponentProperty ("myName1", "myCompId1");
  72. scd.AddComponentProperty ("myName2", "myCompId2");
  73. string script = scd.DoGetScript ();
  74. #if TARGET_JVM
  75. Assert.AreEqual ("$create(My.Type, null, null, {\"myName2\":\"myCompId2\",\"myName1\":\"myCompId1\"}, $get(\"Element1\"));", script);
  76. #else
  77. Assert.AreEqual ("$create(My.Type, null, null, {\"myName1\":\"myCompId1\",\"myName2\":\"myCompId2\"}, $get(\"Element1\"));", script);
  78. #endif
  79. }
  80. [Category("NotWorking")] // One must not depend on the order of keys in dictionary
  81. [Test]
  82. public void ScriptBehaviorDescriptor_AddElementProperty () {
  83. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  84. scd.AddElementProperty ("myName1", "myElemId1");
  85. scd.AddElementProperty ("myName2", "myElemId2");
  86. string script = scd.DoGetScript ();
  87. #if TARGET_JVM
  88. Assert.AreEqual ("$create(My.Type, {\"myName2\":$get(\"myElemId2\"),\"myName1\":$get(\"myElemId1\")}, null, null, $get(\"Element1\"));", script);
  89. #else
  90. Assert.AreEqual ("$create(My.Type, {\"myName1\":$get(\"myElemId1\"),\"myName2\":$get(\"myElemId2\")}, null, null, $get(\"Element1\"));", script);
  91. #endif
  92. }
  93. [Category("NotWorking")] // One must not depend on the order of keys in dictionary
  94. [Test]
  95. public void ScriptBehaviorDescriptor_AddProperty () {
  96. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  97. scd.AddProperty ("myName1", "myValue1");
  98. scd.AddProperty ("myName2", "myValue2");
  99. string script = scd.DoGetScript ();
  100. #if TARGET_JVM
  101. Assert.AreEqual ("$create(My.Type, {\"myName2\":\"myValue2\",\"myName1\":\"myValue1\"}, null, null, $get(\"Element1\"));", script);
  102. #else
  103. Assert.AreEqual ("$create(My.Type, {\"myName1\":\"myValue1\",\"myName2\":\"myValue2\"}, null, null, $get(\"Element1\"));", script);
  104. #endif
  105. }
  106. [Category("NotWorking")] // One must not depend on the order of keys in dictionary
  107. [Test]
  108. public void ScriptBehaviorDescriptor_AddProperty_Null () {
  109. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  110. scd.AddProperty ("myName1", null);
  111. scd.AddProperty ("myName2", null);
  112. string script = scd.DoGetScript ();
  113. #if TARGET_JVM
  114. Assert.AreEqual ("$create(My.Type, {\"myName2\":null,\"myName1\":null}, null, null, $get(\"Element1\"));", script);
  115. #else
  116. Assert.AreEqual ("$create(My.Type, {\"myName1\":null,\"myName2\":null}, null, null, $get(\"Element1\"));", script);
  117. #endif
  118. }
  119. [Category("NotWorking")] // One must not depend on the order of keys in dictionary
  120. [Test]
  121. public void ScriptBehaviorDescriptor_AddEvent () {
  122. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  123. scd.AddEvent ("myName1", "myHandler1");
  124. scd.AddEvent ("myName2", "myHandler2");
  125. string script = scd.DoGetScript ();
  126. #if TARGET_JVM
  127. Assert.AreEqual ("$create(My.Type, null, {\"myName2\":myHandler2,\"myName1\":myHandler1}, null, $get(\"Element1\"));", script);
  128. #else
  129. Assert.AreEqual ("$create(My.Type, null, {\"myName1\":myHandler1,\"myName2\":myHandler2}, null, $get(\"Element1\"));", script);
  130. #endif
  131. }
  132. [Category("NotWorking")] // One must not depend on the order of keys in dictionary
  133. [Test]
  134. public void ScriptBehaviorDescriptor_AddScriptProperty () {
  135. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  136. scd.AddScriptProperty ("myName1", "myScript1");
  137. scd.AddScriptProperty ("myName2", "myScript2");
  138. string script = scd.DoGetScript ();
  139. #if TARGET_JVM
  140. Assert.AreEqual ("$create(My.Type, {\"myName2\":myScript2,\"myName1\":myScript1}, null, null, $get(\"Element1\"));", script);
  141. #else
  142. Assert.AreEqual ("$create(My.Type, {\"myName1\":myScript1,\"myName2\":myScript2}, null, null, $get(\"Element1\"));", script);
  143. #endif
  144. }
  145. [Test]
  146. [ExpectedException (typeof (ArgumentException))]
  147. public void ScriptBehaviorDescriptor_Type_exception_1 () {
  148. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  149. scd.Type = null;
  150. }
  151. [Test]
  152. [ExpectedException (typeof (ArgumentException))]
  153. public void ScriptBehaviorDescriptor_Type_exception_2 () {
  154. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  155. scd.Type = String.Empty;
  156. }
  157. [Test]
  158. public void ScriptBehaviorDescriptor_Type () {
  159. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  160. scd.Type = "New.Type";
  161. Assert.AreEqual ("New.Type", scd.Type, "Type");
  162. }
  163. [Test]
  164. public void ScriptBehaviorDescriptor_ID () {
  165. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  166. scd.ID = null;
  167. Assert.AreEqual (String.Empty, scd.ID, "#1");
  168. scd.ID = String.Empty;
  169. Assert.AreEqual (String.Empty, scd.ID, "#2");
  170. scd.ID = "My ID";
  171. Assert.AreEqual ("My ID", scd.ID, "#3");
  172. Assert.AreEqual ("My ID", scd.ClientID, "#4");
  173. }
  174. [Test]
  175. public void ScriptBehaviorDescriptor_Name () {
  176. PokerScriptBehaviorDescriptor scd = new PokerScriptBehaviorDescriptor ("My.Type", "Element1");
  177. scd.Name = null;
  178. Assert.AreEqual ("Type", scd.Name, "#1");
  179. scd.Name = String.Empty;
  180. Assert.AreEqual ("Type", scd.Name, "#2");
  181. scd.Name = "MyName";
  182. Assert.AreEqual ("MyName", scd.Name, "#3");
  183. Assert.AreEqual ("Element1$MyName", scd.ClientID, "#4");
  184. scd.Name = "MyName.MyType";
  185. Assert.AreEqual ("MyName.MyType", scd.Name, "#5");
  186. scd.Name = null;
  187. Assert.AreEqual ("Type", scd.Name, "#6");
  188. }
  189. }
  190. }