Merge pull request #1936 from esdrubal/DotNetRelativeOrAbsolute
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / DataKeyTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.DataKeyTest.cs
3 //
4 // Author:
5 //      Yoni Klein (yonik@mainsoft.com)
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
29
30
31 using System;
32 using System.Collections.Generic;
33 using System.Text;
34 using System.Web;
35 using System.Web.UI;
36 using System.Web.UI.WebControls;
37 using System.IO;
38 using System.Collections;
39 using System.Collections.Specialized;
40 using NUnit.Framework;
41 using System.Data;
42 using System.ComponentModel;
43
44 namespace MonoTests.System.Web.UI.WebControls
45 {
46         [TestFixture]
47         public class DataKeyTest
48         {
49                 // Keys and values can be assigned only from constractor 
50
51                 [Test]
52                 public void DataKey_Functionality()
53                 {
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");
69                 }
70                 [Test]
71                 public void DataKey_Equals ()
72                 {
73                         var dict = new OrderedDictionary ();
74                         dict.Add ("key", "value");
75                         dict.Add ("key1", "value1");
76                         var key1 = new DataKey (dict);
77
78                         dict = new OrderedDictionary ();
79                         dict.Add ("key", "value");
80                         dict.Add ("key1", "value1");
81                         var key2 = new DataKey (dict);
82
83                         Assert.IsTrue (key1.Equals (key2), "#A1-1");
84                         Assert.IsTrue (key2.Equals (key1), "#A1-2");
85
86                         dict = new OrderedDictionary ();
87                         dict.Add ("key", "value");
88                         dict.Add ("key1", "value1");
89                         key1 = new DataKey (dict);
90
91                         dict = new OrderedDictionary ();
92                         dict.Add ("key2", "value2");
93                         dict.Add ("key1", "value1");
94                         key2 = new DataKey (dict);
95
96                         Assert.IsFalse (key1.Equals (key2), "#A2-1");
97                         Assert.IsFalse (key2.Equals (key1), "#A2-2");
98
99                         dict = new OrderedDictionary ();
100                         key1 = new DataKey (dict);
101
102                         dict = new OrderedDictionary ();
103                         dict.Add ("key1", "value1");
104                         key2 = new DataKey (dict);
105
106                         Assert.IsFalse (key1.Equals (key2), "#A3-1");
107                         Assert.IsFalse (key2.Equals (key1), "#A3-2");
108
109                         dict = new OrderedDictionary ();
110                         key1 = new DataKey (dict);
111
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");
116
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");
123
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");
128
129                         dict = new OrderedDictionary ();
130                         dict.Add ("key", "value");
131                         dict.Add ("key1", "value1");
132                         key1 = new DataKey (dict, new string[] { "key" });
133
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");
140
141                         Assert.IsFalse (key1.Equals ((DataKey) null), "#A8");
142
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");
151
152                         key1 = new DataKey (null);
153                         Assert.IsFalse (key1.Equals ((DataKey) null), "#A9");
154
155                         dict = new OrderedDictionary ();
156                         key1 = new DataKey (dict, new string [] { "key" });
157
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");
162
163                         dict = new OrderedDictionary ();
164                         dict.Add ("KEY", "value");
165                         dict.Add ("key1", "value1");
166                         key1 = new DataKey (dict);
167
168                         dict = new OrderedDictionary ();
169                         dict.Add ("key", "value");
170                         dict.Add ("key1", "value1");
171                         key2 = new DataKey (dict);
172
173                         Assert.IsFalse (key1.Equals (key2), "#A11-1");
174                         Assert.IsFalse (key2.Equals (key1), "#A11-2");
175
176                         dict = new OrderedDictionary ();
177                         dict.Add ("key", "VALUE");
178                         dict.Add ("key1", "value1");
179                         key1 = new DataKey (dict);
180
181                         dict = new OrderedDictionary ();
182                         dict.Add ("key", "value");
183                         dict.Add ("key1", "value1");
184                         key2 = new DataKey (dict);
185
186                         Assert.IsFalse (key1.Equals (key2), "#A12-1");
187                         Assert.IsFalse (key2.Equals (key1), "#A12-2");
188
189                         dict = new OrderedDictionary ();
190                         dict.Add ("key", "value");
191                         dict.Add ("key1", "value1");
192                         key1 = new DataKey (dict);
193
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");
200
201                         dict = new OrderedDictionary ();
202                         key1 = new DataKey (dict, new string [] { "key" });
203
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");
208                         
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");
213
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");
218
219                         dict = new OrderedDictionary ();
220                         dict.Add ("key", "value");
221                         dict.Add ("key1", "value1");
222                         key2 = new DataKey (dict, new string [] { });
223
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");
230                 }
231         }
232 }