[bcl] Remove more NET_2_0 checks from class libs
[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 #if NET_4_0
71                 [Test]
72                 public void DataKey_Equals ()
73                 {
74                         var dict = new OrderedDictionary ();
75                         dict.Add ("key", "value");
76                         dict.Add ("key1", "value1");
77                         var key1 = new DataKey (dict);
78
79                         dict = new OrderedDictionary ();
80                         dict.Add ("key", "value");
81                         dict.Add ("key1", "value1");
82                         var key2 = new DataKey (dict);
83
84                         Assert.IsTrue (key1.Equals (key2), "#A1-1");
85                         Assert.IsTrue (key2.Equals (key1), "#A1-2");
86
87                         dict = new OrderedDictionary ();
88                         dict.Add ("key", "value");
89                         dict.Add ("key1", "value1");
90                         key1 = new DataKey (dict);
91
92                         dict = new OrderedDictionary ();
93                         dict.Add ("key2", "value2");
94                         dict.Add ("key1", "value1");
95                         key2 = new DataKey (dict);
96
97                         Assert.IsFalse (key1.Equals (key2), "#A2-1");
98                         Assert.IsFalse (key2.Equals (key1), "#A2-2");
99
100                         dict = new OrderedDictionary ();
101                         key1 = new DataKey (dict);
102
103                         dict = new OrderedDictionary ();
104                         dict.Add ("key1", "value1");
105                         key2 = new DataKey (dict);
106
107                         Assert.IsFalse (key1.Equals (key2), "#A3-1");
108                         Assert.IsFalse (key2.Equals (key1), "#A3-2");
109
110                         dict = new OrderedDictionary ();
111                         key1 = new DataKey (dict);
112
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");
117
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");
124
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");
129
130                         dict = new OrderedDictionary ();
131                         dict.Add ("key", "value");
132                         dict.Add ("key1", "value1");
133                         key1 = new DataKey (dict, new string[] { "key" });
134
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");
141
142                         Assert.IsFalse (key1.Equals ((DataKey) null), "#A8");
143
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");
152
153                         key1 = new DataKey (null);
154                         Assert.IsFalse (key1.Equals ((DataKey) null), "#A9");
155
156                         dict = new OrderedDictionary ();
157                         key1 = new DataKey (dict, new string [] { "key" });
158
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");
163
164                         dict = new OrderedDictionary ();
165                         dict.Add ("KEY", "value");
166                         dict.Add ("key1", "value1");
167                         key1 = new DataKey (dict);
168
169                         dict = new OrderedDictionary ();
170                         dict.Add ("key", "value");
171                         dict.Add ("key1", "value1");
172                         key2 = new DataKey (dict);
173
174                         Assert.IsFalse (key1.Equals (key2), "#A11-1");
175                         Assert.IsFalse (key2.Equals (key1), "#A11-2");
176
177                         dict = new OrderedDictionary ();
178                         dict.Add ("key", "VALUE");
179                         dict.Add ("key1", "value1");
180                         key1 = new DataKey (dict);
181
182                         dict = new OrderedDictionary ();
183                         dict.Add ("key", "value");
184                         dict.Add ("key1", "value1");
185                         key2 = new DataKey (dict);
186
187                         Assert.IsFalse (key1.Equals (key2), "#A12-1");
188                         Assert.IsFalse (key2.Equals (key1), "#A12-2");
189
190                         dict = new OrderedDictionary ();
191                         dict.Add ("key", "value");
192                         dict.Add ("key1", "value1");
193                         key1 = new DataKey (dict);
194
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");
201
202                         dict = new OrderedDictionary ();
203                         key1 = new DataKey (dict, new string [] { "key" });
204
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");
209                         
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");
214
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");
219
220                         dict = new OrderedDictionary ();
221                         dict.Add ("key", "value");
222                         dict.Add ("key1", "value1");
223                         key2 = new DataKey (dict, new string [] { });
224
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");
231                 }
232 #endif
233         }
234 }