ScriptComponentDescriptorTest.cs 7.3 KB

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