2 // Tests for System.Web.UI.WebControls.DataKeyTest.cs
5 // Yoni Klein (yonik@mainsoft.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
32 using System.Collections.Generic;
36 using System.Web.UI.WebControls;
38 using System.Collections;
39 using System.Collections.Specialized;
40 using NUnit.Framework;
42 using System.ComponentModel;
44 namespace MonoTests.System.Web.UI.WebControls
47 public class DataKeyTest
49 // Keys and values can be assigned only from constractor
52 public void DataKey_Functionality()
54 OrderedDictionary dictionary = new OrderedDictionary ();
55 IOrderedDictionary iDictionary;
56 dictionary.Add ("key", "value");
57 DataKey key = new DataKey (dictionary);
58 Assert.AreEqual ("value", key[0].ToString(), "DataKeyItemIndex");
59 Assert.AreEqual ("value", key["key"].ToString (), "DataKeyItemKeyName");
60 Assert.AreEqual ("value", key.Value, "FirstIndexValue");
61 iDictionary = key.Values;
62 Assert.AreEqual (1, iDictionary.Count, "AllValuesReferringToKey");
63 Assert.AreEqual ("value", iDictionary[0], "ValueReferringToKey");
64 dictionary.Add("key1", "value1");
65 key = new DataKey (dictionary);
66 iDictionary = key.Values;
67 Assert.AreEqual (2, iDictionary.Count, "AllValuesReferringToKey#1");
68 Assert.AreEqual ("value1", iDictionary[1], "ValueReferringToKey#1");
71 public void DataKey_Equals ()
73 var dict = new OrderedDictionary ();
74 dict.Add ("key", "value");
75 dict.Add ("key1", "value1");
76 var key1 = new DataKey (dict);
78 dict = new OrderedDictionary ();
79 dict.Add ("key", "value");
80 dict.Add ("key1", "value1");
81 var key2 = new DataKey (dict);
83 Assert.IsTrue (key1.Equals (key2), "#A1-1");
84 Assert.IsTrue (key2.Equals (key1), "#A1-2");
86 dict = new OrderedDictionary ();
87 dict.Add ("key", "value");
88 dict.Add ("key1", "value1");
89 key1 = new DataKey (dict);
91 dict = new OrderedDictionary ();
92 dict.Add ("key2", "value2");
93 dict.Add ("key1", "value1");
94 key2 = new DataKey (dict);
96 Assert.IsFalse (key1.Equals (key2), "#A2-1");
97 Assert.IsFalse (key2.Equals (key1), "#A2-2");
99 dict = new OrderedDictionary ();
100 key1 = new DataKey (dict);
102 dict = new OrderedDictionary ();
103 dict.Add ("key1", "value1");
104 key2 = new DataKey (dict);
106 Assert.IsFalse (key1.Equals (key2), "#A3-1");
107 Assert.IsFalse (key2.Equals (key1), "#A3-2");
109 dict = new OrderedDictionary ();
110 key1 = new DataKey (dict);
112 dict = new OrderedDictionary ();
113 key2 = new DataKey (dict);
114 Assert.IsTrue (key1.Equals (key2), "#A4-1");
115 Assert.IsTrue (key2.Equals (key1), "#A4-2");
117 dict = new OrderedDictionary ();
118 key1 = new DataKey (null);
119 key2 = new DataKey (dict);
120 Assert.IsTrue (key1.Equals (key2), "#A5-1");
121 // Throws NREX on .NET
122 //Assert.IsTrue (key2.Equals (key1), "#A5-2");
124 key1 = new DataKey (null);
125 key2 = new DataKey (null);
126 Assert.IsTrue (key1.Equals (key2), "#A6-1");
127 Assert.IsTrue (key2.Equals (key1), "#A6-2");
129 dict = new OrderedDictionary ();
130 dict.Add ("key", "value");
131 dict.Add ("key1", "value1");
132 key1 = new DataKey (dict, new string[] { "key" });
134 dict = new OrderedDictionary ();
135 dict.Add ("key", "value");
136 dict.Add ("key1", "value1");
137 key2 = new DataKey (dict, new string[] { "key1" });
138 Assert.IsFalse (key1.Equals (key2), "#A7-1");
139 Assert.IsFalse (key2.Equals (key1), "#A7-2");
141 Assert.IsFalse (key1.Equals ((DataKey) null), "#A8");
143 dict = new OrderedDictionary ();
144 dict.Add ("key", "value");
145 dict.Add ("key1", "value1");
146 key1 = new DataKey (dict);
147 key2 = new DataKey (null);
148 // Throws NREX on .NET
149 //Assert.IsFalse (key1.Equals (key2), "#A8-1");
150 Assert.IsTrue (key2.Equals (key1), "#A8-2");
152 key1 = new DataKey (null);
153 Assert.IsFalse (key1.Equals ((DataKey) null), "#A9");
155 dict = new OrderedDictionary ();
156 key1 = new DataKey (dict, new string [] { "key" });
158 dict = new OrderedDictionary ();
159 key2 = new DataKey (dict, new string [] { "key1" });
160 Assert.IsFalse (key1.Equals (key2), "#A10-1");
161 Assert.IsFalse (key2.Equals (key1), "#A10-2");
163 dict = new OrderedDictionary ();
164 dict.Add ("KEY", "value");
165 dict.Add ("key1", "value1");
166 key1 = new DataKey (dict);
168 dict = new OrderedDictionary ();
169 dict.Add ("key", "value");
170 dict.Add ("key1", "value1");
171 key2 = new DataKey (dict);
173 Assert.IsFalse (key1.Equals (key2), "#A11-1");
174 Assert.IsFalse (key2.Equals (key1), "#A11-2");
176 dict = new OrderedDictionary ();
177 dict.Add ("key", "VALUE");
178 dict.Add ("key1", "value1");
179 key1 = new DataKey (dict);
181 dict = new OrderedDictionary ();
182 dict.Add ("key", "value");
183 dict.Add ("key1", "value1");
184 key2 = new DataKey (dict);
186 Assert.IsFalse (key1.Equals (key2), "#A12-1");
187 Assert.IsFalse (key2.Equals (key1), "#A12-2");
189 dict = new OrderedDictionary ();
190 dict.Add ("key", "value");
191 dict.Add ("key1", "value1");
192 key1 = new DataKey (dict);
194 dict = new OrderedDictionary ();
195 dict.Add ("key", "value");
196 dict.Add ("key1", "value1");
197 key2 = new DataKey (dict, new string [] { "key1" });
198 Assert.IsFalse (key1.Equals (key2), "#A13-1");
199 Assert.IsFalse (key2.Equals (key1), "#A13-2");
201 dict = new OrderedDictionary ();
202 key1 = new DataKey (dict, new string [] { "key" });
204 dict = new OrderedDictionary ();
205 key2 = new DataKey (dict, new string [] { "KEY" });
206 Assert.IsFalse (key1.Equals (key2), "#A14-1");
207 Assert.IsFalse (key2.Equals (key1), "#A14-2");
209 key1 = new DataKey (null, new string [] { "key" });
210 key2 = new DataKey (null, new string [] { "key" });
211 Assert.IsTrue (key1.Equals (key2), "#A15-1");
212 Assert.IsTrue (key2.Equals (key1), "#A15-2");
214 key1 = new DataKey (null, new string [] { "KEY" });
215 key2 = new DataKey (null, new string [] { "key" });
216 Assert.IsFalse (key1.Equals (key2), "#A16-1");
217 Assert.IsFalse (key2.Equals (key1), "#A16-2");
219 dict = new OrderedDictionary ();
220 dict.Add ("key", "value");
221 dict.Add ("key1", "value1");
222 key2 = new DataKey (dict, new string [] { });
224 dict = new OrderedDictionary ();
225 dict.Add ("key", "value");
226 dict.Add ("key1", "value1");
227 key1 = new DataKey (dict);
228 Assert.IsFalse (key1.Equals (key2), "#A17-1");
229 Assert.IsFalse (key2.Equals (key1), "#A17-2");