2
0

ScriptComponentDescriptorTest.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //
  2. // ScriptComponentDescriptorTest.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 ScriptComponentDescriptorTest
  38. {
  39. class PokerScriptComponentDescriptor : ScriptComponentDescriptor
  40. {
  41. public PokerScriptComponentDescriptor (string type) : base (type) { }
  42. public string DoGetScript () {
  43. return GetScript ();
  44. }
  45. }
  46. [Test]
  47. public void ScriptComponentDescriptor_Defaults ()
  48. {
  49. PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
  50. Assert.AreEqual ("My.Type", scd.Type, "Type");
  51. Assert.AreEqual (String.Empty, scd.ID, "ID");
  52. Assert.AreEqual (String.Empty, scd.ClientID, "ClientID");
  53. string script = scd.DoGetScript ();
  54. Assert.AreEqual ("$create(My.Type, null, null, null);", script, "#A1");
  55. scd.ID = "SomeID";
  56. script = scd.DoGetScript ();
  57. Assert.AreEqual ("$create(My.Type, {\"id\":\"SomeID\"}, null, null);", script, "#A2");
  58. }
  59. [Test]
  60. [ExpectedException (typeof (ArgumentException))]
  61. public void ScriptComponentDescriptor_ctor_exception_1 () {
  62. ScriptComponentDescriptor scd = new ScriptComponentDescriptor (null);
  63. }
  64. [Test]
  65. [ExpectedException (typeof (ArgumentException))]
  66. public void ScriptComponentDescriptor_ctor_exception_2 () {
  67. ScriptComponentDescriptor scd = new ScriptComponentDescriptor (String.Empty);
  68. }
  69. [Category("NotWorking")] // One must not depend on the order of keys in dictionary
  70. [Test]
  71. public void ScriptComponentDescriptor_AddComponentProperty () {
  72. PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
  73. scd.AddComponentProperty ("myName1", "myCompId1");
  74. scd.AddComponentProperty ("myName2", "myCompId2");
  75. string script = scd.DoGetScript ();
  76. #if TARGET_JVM
  77. Assert.AreEqual ("$create(My.Type, null, null, {\"myName2\":\"myCompId2\",\"myName1\":\"myCompId1\"});", script);
  78. #else
  79. Assert.AreEqual ("$create(My.Type, null, null, {\"myName1\":\"myCompId1\",\"myName2\":\"myCompId2\"});", script);
  80. #endif
  81. }
  82. [Category("NotWorking")] // One must not depend on the order of keys in dictionary
  83. [Test]
  84. public void ScriptComponentDescriptor_AddElementProperty () {
  85. PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
  86. scd.AddElementProperty ("myName1", "myElemId1");
  87. scd.AddElementProperty ("myName2", "myElemId2");
  88. string script = scd.DoGetScript ();
  89. #if TARGET_JVM
  90. Assert.AreEqual ("$create(My.Type, {\"myName2\":$get(\"myElemId2\"),\"myName1\":$get(\"myElemId1\")}, null, null);", script);
  91. #else
  92. Assert.AreEqual ("$create(My.Type, {\"myName1\":$get(\"myElemId1\"),\"myName2\":$get(\"myElemId2\")}, null, null);", script);
  93. #endif
  94. }
  95. [Category("NotWorking")] // One must not depend on the order of keys in dictionary
  96. [Test]
  97. public void ScriptComponentDescriptor_AddProperty () {
  98. PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
  99. scd.AddProperty ("myName1", "myValue1");
  100. scd.AddProperty ("myName2", "myValue2");
  101. string script = scd.DoGetScript ();
  102. #if TARGET_JVM
  103. Assert.AreEqual ("$create(My.Type, {\"myName2\":\"myValue2\",\"myName1\":\"myValue1\"}, null, null);", script);
  104. #else
  105. Assert.AreEqual ("$create(My.Type, {\"myName1\":\"myValue1\",\"myName2\":\"myValue2\"}, null, null);", script);
  106. #endif
  107. }
  108. [Category("NotWorking")] // One must not depend on the order of keys in dictionary
  109. [Test]
  110. public void ScriptComponentDescriptor_AddProperty_Null () {
  111. PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
  112. scd.AddProperty ("myName1", null);
  113. scd.AddProperty ("myName2", null);
  114. string script = scd.DoGetScript ();
  115. #if TARGET_JVM
  116. Assert.AreEqual ("$create(My.Type, {\"myName2\":null,\"myName1\":null}, null, null);", script);
  117. #else
  118. Assert.AreEqual ("$create(My.Type, {\"myName1\":null,\"myName2\":null}, null, null);", script);
  119. #endif
  120. }
  121. [Category("NotWorking")] // One must not depend on the order of keys in dictionary
  122. [Test]
  123. public void ScriptComponentDescriptor_AddEvent () {
  124. PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
  125. scd.AddEvent ("myName1", "myHandler1");
  126. scd.AddEvent ("myName2", "myHandler2");
  127. string script = scd.DoGetScript ();
  128. #if TARGET_JVM
  129. Assert.AreEqual ("$create(My.Type, null, {\"myName2\":myHandler2,\"myName1\":myHandler1}, null);", script);
  130. #else
  131. Assert.AreEqual ("$create(My.Type, null, {\"myName1\":myHandler1,\"myName2\":myHandler2}, null);", script);
  132. #endif
  133. }
  134. [Category("NotWorking")] // One must not depend on the order of keys in dictionary
  135. [Test]
  136. public void ScriptComponentDescriptor_AddScriptProperty () {
  137. PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
  138. scd.AddScriptProperty ("myName1", "myScript1");
  139. scd.AddScriptProperty ("myName2", "myScript2");
  140. string script = scd.DoGetScript ();
  141. #if TARGET_JVM
  142. Assert.AreEqual ("$create(My.Type, {\"myName2\":myScript2,\"myName1\":myScript1}, null, null);", script);
  143. #else
  144. Assert.AreEqual ("$create(My.Type, {\"myName1\":myScript1,\"myName2\":myScript2}, null, null);", script);
  145. #endif
  146. }
  147. [Test]
  148. [ExpectedException (typeof (ArgumentException))]
  149. public void ScriptComponentDescriptor_Type_exception_1 () {
  150. PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
  151. scd.Type = null;
  152. }
  153. [Test]
  154. [ExpectedException (typeof (ArgumentException))]
  155. public void ScriptComponentDescriptor_Type_exception_2 () {
  156. PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
  157. scd.Type = String.Empty;
  158. }
  159. [Test]
  160. public void ScriptComponentDescriptor_Type () {
  161. PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
  162. scd.Type = "New.Type";
  163. Assert.AreEqual ("New.Type", scd.Type, "Type");
  164. }
  165. [Test]
  166. public void ScriptComponentDescriptor_ID () {
  167. PokerScriptComponentDescriptor scd = new PokerScriptComponentDescriptor ("My.Type");
  168. scd.ID = null;
  169. Assert.AreEqual (String.Empty, scd.ID, "#1");
  170. scd.ID = String.Empty;
  171. Assert.AreEqual (String.Empty, scd.ID, "#2");
  172. scd.ID = "My ID";
  173. Assert.AreEqual ("My ID", scd.ID, "#3");
  174. Assert.AreEqual ("My ID", scd.ClientID, "#4");
  175. }
  176. }
  177. }