DataKeyTest.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. //
  2. // Tests for System.Web.UI.WebControls.DataKeyTest.cs
  3. //
  4. // Author:
  5. // Yoni Klein ([email protected])
  6. //
  7. //
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  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. using System;
  29. using System.Collections.Generic;
  30. using System.Text;
  31. using System.Web;
  32. using System.Web.UI;
  33. using System.Web.UI.WebControls;
  34. using System.IO;
  35. using System.Collections;
  36. using System.Collections.Specialized;
  37. using NUnit.Framework;
  38. using System.Data;
  39. using System.ComponentModel;
  40. namespace MonoTests.System.Web.UI.WebControls
  41. {
  42. [TestFixture]
  43. public class DataKeyTest
  44. {
  45. // Keys and values can be assigned only from constractor
  46. [Test]
  47. public void DataKey_Functionality()
  48. {
  49. OrderedDictionary dictionary = new OrderedDictionary ();
  50. IOrderedDictionary iDictionary;
  51. dictionary.Add ("key", "value");
  52. DataKey key = new DataKey (dictionary);
  53. Assert.AreEqual ("value", key[0].ToString(), "DataKeyItemIndex");
  54. Assert.AreEqual ("value", key["key"].ToString (), "DataKeyItemKeyName");
  55. Assert.AreEqual ("value", key.Value, "FirstIndexValue");
  56. iDictionary = key.Values;
  57. Assert.AreEqual (1, iDictionary.Count, "AllValuesReferringToKey");
  58. Assert.AreEqual ("value", iDictionary[0], "ValueReferringToKey");
  59. dictionary.Add("key1", "value1");
  60. key = new DataKey (dictionary);
  61. iDictionary = key.Values;
  62. Assert.AreEqual (2, iDictionary.Count, "AllValuesReferringToKey#1");
  63. Assert.AreEqual ("value1", iDictionary[1], "ValueReferringToKey#1");
  64. }
  65. [Test]
  66. public void DataKey_Equals ()
  67. {
  68. var dict = new OrderedDictionary ();
  69. dict.Add ("key", "value");
  70. dict.Add ("key1", "value1");
  71. var key1 = new DataKey (dict);
  72. dict = new OrderedDictionary ();
  73. dict.Add ("key", "value");
  74. dict.Add ("key1", "value1");
  75. var key2 = new DataKey (dict);
  76. Assert.IsTrue (key1.Equals (key2), "#A1-1");
  77. Assert.IsTrue (key2.Equals (key1), "#A1-2");
  78. dict = new OrderedDictionary ();
  79. dict.Add ("key", "value");
  80. dict.Add ("key1", "value1");
  81. key1 = new DataKey (dict);
  82. dict = new OrderedDictionary ();
  83. dict.Add ("key2", "value2");
  84. dict.Add ("key1", "value1");
  85. key2 = new DataKey (dict);
  86. Assert.IsFalse (key1.Equals (key2), "#A2-1");
  87. Assert.IsFalse (key2.Equals (key1), "#A2-2");
  88. dict = new OrderedDictionary ();
  89. key1 = new DataKey (dict);
  90. dict = new OrderedDictionary ();
  91. dict.Add ("key1", "value1");
  92. key2 = new DataKey (dict);
  93. Assert.IsFalse (key1.Equals (key2), "#A3-1");
  94. Assert.IsFalse (key2.Equals (key1), "#A3-2");
  95. dict = new OrderedDictionary ();
  96. key1 = new DataKey (dict);
  97. dict = new OrderedDictionary ();
  98. key2 = new DataKey (dict);
  99. Assert.IsTrue (key1.Equals (key2), "#A4-1");
  100. Assert.IsTrue (key2.Equals (key1), "#A4-2");
  101. dict = new OrderedDictionary ();
  102. key1 = new DataKey (null);
  103. key2 = new DataKey (dict);
  104. Assert.IsTrue (key1.Equals (key2), "#A5-1");
  105. // Throws NREX on .NET
  106. //Assert.IsTrue (key2.Equals (key1), "#A5-2");
  107. key1 = new DataKey (null);
  108. key2 = new DataKey (null);
  109. Assert.IsTrue (key1.Equals (key2), "#A6-1");
  110. Assert.IsTrue (key2.Equals (key1), "#A6-2");
  111. dict = new OrderedDictionary ();
  112. dict.Add ("key", "value");
  113. dict.Add ("key1", "value1");
  114. key1 = new DataKey (dict, new string[] { "key" });
  115. dict = new OrderedDictionary ();
  116. dict.Add ("key", "value");
  117. dict.Add ("key1", "value1");
  118. key2 = new DataKey (dict, new string[] { "key1" });
  119. Assert.IsFalse (key1.Equals (key2), "#A7-1");
  120. Assert.IsFalse (key2.Equals (key1), "#A7-2");
  121. Assert.IsFalse (key1.Equals ((DataKey) null), "#A8");
  122. dict = new OrderedDictionary ();
  123. dict.Add ("key", "value");
  124. dict.Add ("key1", "value1");
  125. key1 = new DataKey (dict);
  126. key2 = new DataKey (null);
  127. // Throws NREX on .NET
  128. //Assert.IsFalse (key1.Equals (key2), "#A8-1");
  129. Assert.IsTrue (key2.Equals (key1), "#A8-2");
  130. key1 = new DataKey (null);
  131. Assert.IsFalse (key1.Equals ((DataKey) null), "#A9");
  132. dict = new OrderedDictionary ();
  133. key1 = new DataKey (dict, new string [] { "key" });
  134. dict = new OrderedDictionary ();
  135. key2 = new DataKey (dict, new string [] { "key1" });
  136. Assert.IsFalse (key1.Equals (key2), "#A10-1");
  137. Assert.IsFalse (key2.Equals (key1), "#A10-2");
  138. dict = new OrderedDictionary ();
  139. dict.Add ("KEY", "value");
  140. dict.Add ("key1", "value1");
  141. key1 = new DataKey (dict);
  142. dict = new OrderedDictionary ();
  143. dict.Add ("key", "value");
  144. dict.Add ("key1", "value1");
  145. key2 = new DataKey (dict);
  146. Assert.IsFalse (key1.Equals (key2), "#A11-1");
  147. Assert.IsFalse (key2.Equals (key1), "#A11-2");
  148. dict = new OrderedDictionary ();
  149. dict.Add ("key", "VALUE");
  150. dict.Add ("key1", "value1");
  151. key1 = new DataKey (dict);
  152. dict = new OrderedDictionary ();
  153. dict.Add ("key", "value");
  154. dict.Add ("key1", "value1");
  155. key2 = new DataKey (dict);
  156. Assert.IsFalse (key1.Equals (key2), "#A12-1");
  157. Assert.IsFalse (key2.Equals (key1), "#A12-2");
  158. dict = new OrderedDictionary ();
  159. dict.Add ("key", "value");
  160. dict.Add ("key1", "value1");
  161. key1 = new DataKey (dict);
  162. dict = new OrderedDictionary ();
  163. dict.Add ("key", "value");
  164. dict.Add ("key1", "value1");
  165. key2 = new DataKey (dict, new string [] { "key1" });
  166. Assert.IsFalse (key1.Equals (key2), "#A13-1");
  167. Assert.IsFalse (key2.Equals (key1), "#A13-2");
  168. dict = new OrderedDictionary ();
  169. key1 = new DataKey (dict, new string [] { "key" });
  170. dict = new OrderedDictionary ();
  171. key2 = new DataKey (dict, new string [] { "KEY" });
  172. Assert.IsFalse (key1.Equals (key2), "#A14-1");
  173. Assert.IsFalse (key2.Equals (key1), "#A14-2");
  174. key1 = new DataKey (null, new string [] { "key" });
  175. key2 = new DataKey (null, new string [] { "key" });
  176. Assert.IsTrue (key1.Equals (key2), "#A15-1");
  177. Assert.IsTrue (key2.Equals (key1), "#A15-2");
  178. key1 = new DataKey (null, new string [] { "KEY" });
  179. key2 = new DataKey (null, new string [] { "key" });
  180. Assert.IsFalse (key1.Equals (key2), "#A16-1");
  181. Assert.IsFalse (key2.Equals (key1), "#A16-2");
  182. dict = new OrderedDictionary ();
  183. dict.Add ("key", "value");
  184. dict.Add ("key1", "value1");
  185. key2 = new DataKey (dict, new string [] { });
  186. dict = new OrderedDictionary ();
  187. dict.Add ("key", "value");
  188. dict.Add ("key1", "value1");
  189. key1 = new DataKey (dict);
  190. Assert.IsFalse (key1.Equals (key2), "#A17-1");
  191. Assert.IsFalse (key2.Equals (key1), "#A17-2");
  192. }
  193. }
  194. }