ScriptControlDescriptorTest.cs 7.5 KB

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