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");
72 public void DataKey_Equals ()
74 var dict = new OrderedDictionary ();
75 dict.Add ("key", "value");
76 dict.Add ("key1", "value1");
77 var key1 = new DataKey (dict);
79 dict = new OrderedDictionary ();
80 dict.Add ("key", "value");
81 dict.Add ("key1", "value1");
82 var key2 = new DataKey (dict);
84 Assert.IsTrue (key1.Equals (key2), "#A1-1");
85 Assert.IsTrue (key2.Equals (key1), "#A1-2");
87 dict = new OrderedDictionary ();
88 dict.Add ("key", "value");
89 dict.Add ("key1", "value1");
90 key1 = new DataKey (dict);
92 dict = new OrderedDictionary ();
93 dict.Add ("key2", "value2");
94 dict.Add ("key1", "value1");
95 key2 = new DataKey (dict);
97 Assert.IsFalse (key1.Equals (key2), "#A2-1");
98 Assert.IsFalse (key2.Equals (key1), "#A2-2");
100 dict = new OrderedDictionary ();
101 key1 = new DataKey (dict);
103 dict = new OrderedDictionary ();
104 dict.Add ("key1", "value1");
105 key2 = new DataKey (dict);
107 Assert.IsFalse (key1.Equals (key2), "#A3-1");
108 Assert.IsFalse (key2.Equals (key1), "#A3-2");
110 dict = new OrderedDictionary ();
111 key1 = new DataKey (dict);
113 dict = new OrderedDictionary ();
114 key2 = new DataKey (dict);
115 Assert.IsTrue (key1.Equals (key2), "#A4-1");
116 Assert.IsTrue (key2.Equals (key1), "#A4-2");
118 dict = new OrderedDictionary ();
119 key1 = new DataKey (null);
120 key2 = new DataKey (dict);
121 Assert.IsTrue (key1.Equals (key2), "#A5-1");
122 // Throws NREX on .NET
123 //Assert.IsTrue (key2.Equals (key1), "#A5-2");
125 key1 = new DataKey (null);
126 key2 = new DataKey (null);
127 Assert.IsTrue (key1.Equals (key2), "#A6-1");
128 Assert.IsTrue (key2.Equals (key1), "#A6-2");
130 dict = new OrderedDictionary ();
131 dict.Add ("key", "value");
132 dict.Add ("key1", "value1");
133 key1 = new DataKey (dict, new string[] { "key" });
135 dict = new OrderedDictionary ();
136 dict.Add ("key", "value");
137 dict.Add ("key1", "value1");
138 key2 = new DataKey (dict, new string[] { "key1" });
139 Assert.IsFalse (key1.Equals (key2), "#A7-1");
140 Assert.IsFalse (key2.Equals (key1), "#A7-2");
142 Assert.IsFalse (key1.Equals ((DataKey) null), "#A8");
144 dict = new OrderedDictionary ();
145 dict.Add ("key", "value");
146 dict.Add ("key1", "value1");
147 key1 = new DataKey (dict);
148 key2 = new DataKey (null);
149 // Throws NREX on .NET
150 //Assert.IsFalse (key1.Equals (key2), "#A8-1");
151 Assert.IsTrue (key2.Equals (key1), "#A8-2");
153 key1 = new DataKey (null);
154 Assert.IsFalse (key1.Equals ((DataKey) null), "#A9");
156 dict = new OrderedDictionary ();
157 key1 = new DataKey (dict, new string [] { "key" });
159 dict = new OrderedDictionary ();
160 key2 = new DataKey (dict, new string [] { "key1" });
161 Assert.IsFalse (key1.Equals (key2), "#A10-1");
162 Assert.IsFalse (key2.Equals (key1), "#A10-2");
164 dict = new OrderedDictionary ();
165 dict.Add ("KEY", "value");
166 dict.Add ("key1", "value1");
167 key1 = new DataKey (dict);
169 dict = new OrderedDictionary ();
170 dict.Add ("key", "value");
171 dict.Add ("key1", "value1");
172 key2 = new DataKey (dict);
174 Assert.IsFalse (key1.Equals (key2), "#A11-1");
175 Assert.IsFalse (key2.Equals (key1), "#A11-2");
177 dict = new OrderedDictionary ();
178 dict.Add ("key", "VALUE");
179 dict.Add ("key1", "value1");
180 key1 = new DataKey (dict);
182 dict = new OrderedDictionary ();
183 dict.Add ("key", "value");
184 dict.Add ("key1", "value1");
185 key2 = new DataKey (dict);
187 Assert.IsFalse (key1.Equals (key2), "#A12-1");
188 Assert.IsFalse (key2.Equals (key1), "#A12-2");
190 dict = new OrderedDictionary ();
191 dict.Add ("key", "value");
192 dict.Add ("key1", "value1");
193 key1 = new DataKey (dict);
195 dict = new OrderedDictionary ();
196 dict.Add ("key", "value");
197 dict.Add ("key1", "value1");
198 key2 = new DataKey (dict, new string [] { "key1" });
199 Assert.IsFalse (key1.Equals (key2), "#A13-1");
200 Assert.IsFalse (key2.Equals (key1), "#A13-2");
202 dict = new OrderedDictionary ();
203 key1 = new DataKey (dict, new string [] { "key" });
205 dict = new OrderedDictionary ();
206 key2 = new DataKey (dict, new string [] { "KEY" });
207 Assert.IsFalse (key1.Equals (key2), "#A14-1");
208 Assert.IsFalse (key2.Equals (key1), "#A14-2");
210 key1 = new DataKey (null, new string [] { "key" });
211 key2 = new DataKey (null, new string [] { "key" });
212 Assert.IsTrue (key1.Equals (key2), "#A15-1");
213 Assert.IsTrue (key2.Equals (key1), "#A15-2");
215 key1 = new DataKey (null, new string [] { "KEY" });
216 key2 = new DataKey (null, new string [] { "key" });
217 Assert.IsFalse (key1.Equals (key2), "#A16-1");
218 Assert.IsFalse (key2.Equals (key1), "#A16-2");
220 dict = new OrderedDictionary ();
221 dict.Add ("key", "value");
222 dict.Add ("key1", "value1");
223 key2 = new DataKey (dict, new string [] { });
225 dict = new OrderedDictionary ();
226 dict.Add ("key", "value");
227 dict.Add ("key1", "value1");
228 key1 = new DataKey (dict);
229 Assert.IsFalse (key1.Equals (key2), "#A17-1");
230 Assert.IsFalse (key2.Equals (key1), "#A17-2");