2004-04-12 Roopa Wilson (RoWilson@novell.com)
[mono.git] / mcs / class / System.Data / Test / System.Data / DataRowCollectionTest.cs
1 // DataRowCollectionTest.cs - NUnit Test Cases for System.DataRowCollection
2 //
3 // Authors:
4 //   Franklin Wise (gracenote@earthlink.net)
5 //   Martin Willemoes Hansen (mwh@sysrq.dk)
6 //
7 // (C) Copyright 2002 Franklin Wise
8 // (C) Copyright 2003 Martin Willemoes Hansen
9 // 
10
11
12 using NUnit.Framework;
13 using System;
14 using System.Data;
15
16 namespace MonoTests.System.Data
17 {
18         [TestFixture]
19         public class DataRowCollectionTest : Assertion
20         {
21                 private DataTable _tbl; 
22
23                 [SetUp]
24                 public void GetReady()
25                 {
26                         _tbl = new DataTable();
27                 }
28
29                 [Test]
30                 public void AutoIncrement()
31                 {
32                         DataColumn col = new DataColumn("Auto");
33                         col.AutoIncrement = true;
34                         col.AutoIncrementSeed = 0;
35                         col.AutoIncrementStep = 1;
36                         
37                         _tbl.Columns.Add(col);
38                         _tbl.Rows.Add(_tbl.NewRow());
39
40                         AssertEquals("test#01" , 0, Convert.ToInt32(_tbl.Rows[0]["Auto"] ));
41                                 
42                         _tbl.Rows.Add(_tbl.NewRow());
43                         AssertEquals("test#02" , 1, Convert.ToInt32(_tbl.Rows[1]["Auto"] ));
44                         
45                         col.AutoIncrement = false;
46                         AssertEquals("test#03" , 1, Convert.ToInt32(_tbl.Rows[1]["Auto"] ));
47
48                         _tbl.Rows.Add(_tbl.NewRow());
49                         AssertEquals("test#04" , DBNull.Value, _tbl.Rows[2]["Auto"]);
50
51                         col.AutoIncrement = true;
52                         col.AutoIncrementSeed = 10;
53                         col.AutoIncrementStep = 2;
54                         
55                         _tbl.Rows.Add(_tbl.NewRow());
56                         AssertEquals("test#05" , 10, Convert.ToInt32(_tbl.Rows[3]["Auto"] ));
57                         _tbl.Rows.Add(_tbl.NewRow());
58                         AssertEquals("test#06" , 12, Convert.ToInt32(_tbl.Rows[4]["Auto"] ));
59
60                         col = new DataColumn ("Auto2");
61                         col.DataType = typeof(string);
62                         col.AutoIncrement = true;
63                         col.AutoIncrementSeed = 0;
64                         col.AutoIncrementStep = 1;
65                         _tbl.Columns.Add (col);
66                         
67                         _tbl.Rows.Add(_tbl.NewRow());
68                         AssertEquals ("test#07", typeof (int), _tbl.Columns [1].DataType);
69                         AssertEquals ("test#08" , typeof (int), _tbl.Rows[5]["Auto2"].GetType ());
70
71                         col = new DataColumn ("Auto3");
72                         col.AutoIncrement = true;
73                         col.AutoIncrementSeed = 0;
74                         col.AutoIncrementStep = 1;
75                         col.DataType = typeof(string);
76                         AssertEquals ("test#09", typeof (string), col.DataType);
77                         AssertEquals ("test#10", false, col.AutoIncrement);
78                 }
79
80                 [Test]
81                 public void Add ()
82                 {
83                         _tbl.Columns.Add ();
84                         _tbl.Columns.Add ();
85                         DataRow Row = _tbl.NewRow ();
86                         DataRowCollection Rows = _tbl.Rows;
87                         
88                         Rows.Add (Row);
89                         AssertEquals ("test#01", 1, Rows.Count);
90                         AssertEquals ("test#02", false, Rows.IsReadOnly);
91                         AssertEquals ("test#03", false, Rows.IsSynchronized);
92                         AssertEquals ("test#04", "System.Data.DataRowCollection", Rows.ToString ());
93                         
94                         string [] cols = new string [2];
95                         cols [0] = "first";
96                         cols [1] = "second";
97                         
98                         Rows.Add (cols);
99                         cols [0] = "something";
100                         cols [1] = "else";
101                         Rows.Add (cols);
102                         
103                         AssertEquals ("test#05", 3, Rows.Count);
104                         AssertEquals ("test#06", "System.Data.DataRow",  Rows [0].ToString ());
105                         AssertEquals ("test#07", DBNull.Value, Rows [0] [0]);
106                         AssertEquals ("test#08", DBNull.Value, Rows [0] [1]);
107                         AssertEquals ("test#09", "first", Rows [1] [0]);
108                         AssertEquals ("test#10", "something", Rows [2] [0]);
109                         AssertEquals ("test#11", "second", Rows [1] [1]);
110                         AssertEquals ("test#12", "else", Rows [2] [1]);
111                         
112                         try {
113                                 Rows.Add (Row);
114                                 Fail ("test#13");
115                         } catch (Exception e) {
116                                 AssertEquals ("test#14", typeof (ArgumentException), e.GetType ());
117                                 AssertEquals ("test#15", "This row already belongs to this table.", e.Message);
118                         }
119                         
120                         try {
121                                 Row = null;
122                                 Rows.Add (Row);
123                                 Fail ("test#16");
124                         } catch (Exception e) {
125                                 AssertEquals ("test#17", typeof (ArgumentNullException), e.GetType ());
126                                 //AssertEquals ("test#18", "'row' argument cannot be null.\r\nParameter name: row", e.Message);
127                         }
128                         
129                         DataColumn Column = new DataColumn ("not_null");
130                         Column.AllowDBNull = false;
131                         _tbl.Columns.Add (Column);
132                         
133                         cols = new string [3];
134                         cols [0] = "first";
135                         cols [1] = "second";
136                         cols [2] = null;
137                         
138                         try {
139                                 Rows.Add (cols);
140                                 Fail ("test#19");
141                         } catch (Exception e) {
142                                 AssertEquals ("test#20", typeof (NoNullAllowedException), e.GetType ());
143                                 //AssertEquals ("test#21", "Column 'not_null' does not allow nulls.", e.Message);
144                         }
145                         
146                         Column = _tbl.Columns [0];                      
147                         Column.Unique = true;
148
149                         cols = new string [3];
150                         cols [0] = "first";
151                         cols [1] = "second";
152                         cols [2] = "blabal";
153                         
154                         try {
155                                 Rows.Add (cols);
156                                 Fail ("test#22");
157                         } catch (Exception e) {
158                                 AssertEquals ("test#23", typeof (ConstraintException), e.GetType ());
159                                 AssertEquals ("test#24", "Column 'Column1' is constrained to be unique.  Value 'first' is already present.", e.Message);
160                         }
161                        
162                         Column = new DataColumn ("integer");
163                         Column.DataType = typeof (short);
164                         _tbl.Columns.Add (Column);
165                         
166                         object [] obs = new object [4];
167                         obs [0] = "_first";
168                         obs [1] = "second";
169                         obs [2] = "blabal";
170                         obs [3] = "ads";
171                         
172                         try {
173                                 Rows.Add (obs);
174                                 Fail ("test#25");
175                         } catch (Exception e) {
176                                 // LAMESPEC: MSDN says this exception is InvalidCastException
177                                 AssertEquals ("test#26", typeof (ArgumentException), e.GetType ());
178                         }
179
180                         object [] obs1 = new object [5];
181                         obs1 [0] = "A";
182                         obs1 [1] = "B";
183                         obs1 [2] = "C";
184                         obs1 [3] = 38;
185                         obs1 [4] = "Extra";
186                         try {
187                                 Rows.Add (obs1);
188                                 Fail ("test#27");
189                         } catch (Exception e) {
190                                 AssertEquals ("test#28", typeof(ArgumentException), e.GetType ());
191                         }
192                 }
193                 
194                 [Test]
195                 public void Clear ()
196                 {
197                         DataRowCollection Rows = _tbl.Rows;
198                         DataTable Table = new DataTable ("child");
199                         Table.Columns.Add ("first", typeof (int));
200                         Table.Columns.Add ("second", typeof (string));
201                         
202                         _tbl.Columns.Add ("first", typeof (int));
203                         _tbl.Columns.Add ("second", typeof (float));
204
205                         string [] cols = new string [2];
206                         cols [0] = "1";
207                         cols [1] = "1,1";
208                         Rows.Add (cols);
209                         
210                         cols [0] = "2";
211                         cols [1] = "2,1";
212                         Rows.Add (cols);
213                         
214                         cols [0] = "3";
215                         cols [1] = "3,1";
216                         Rows.Add (cols);
217                         
218                         AssertEquals ("test#01", 3, Rows.Count);
219                         Rows.Clear ();
220                         
221                         // hmm... TODO: better tests
222                         AssertEquals ("test#02", 0, Rows.Count);
223                         
224                         cols [0] = "1";
225                         cols [1] = "1,1";
226                         Rows.Add (cols);
227                         
228                         cols [0] = "2";
229                         cols [1] = "2,1";
230                         Rows.Add (cols);
231                         
232                         cols [0] = "3";
233                         cols [1] = "3,1";
234                         Rows.Add (cols);
235
236                         cols [0] = "1";
237                         cols [1] = "test";
238                         Table.Rows.Add (cols);
239                         
240                         cols [0] = "2";
241                         cols [1] = "test2";
242                         Table.Rows.Add (cols);
243                         
244                         cols [0] = "3";
245                         cols [1] = "test3";
246                         Table.Rows.Add (cols);                  
247                         
248                         DataRelation Rel = new DataRelation ("REL", _tbl.Columns [0], Table.Columns [0]);
249                         DataSet Set = new DataSet ();
250                         Set.Tables.Add (_tbl);
251                         Set.Tables.Add (Table);
252                         Set.Relations.Add (Rel);
253                         
254                         try {
255                                 Rows.Clear ();
256                                 Fail ("test#03");
257                         } catch (Exception e) {
258                                 AssertEquals ("test#04", typeof (InvalidConstraintException), e.GetType ());
259                                 AssertEquals ("test#05", "Cannot clear table Table1 because ForeignKeyConstraint REL enforces constraints and there are child rows in child.", e.Message);
260                         }
261                         
262                         AssertEquals ("test#06", 3, Table.Rows.Count);
263                         Table.Rows.Clear ();
264                         AssertEquals ("test#07", 0, Table.Rows.Count);
265                 }
266                 
267                 [Test]
268                 public void Contains ()
269                 {
270                         DataColumn C = new DataColumn ("key");
271                         C.Unique = true;                        
272                         C.DataType = typeof (int);
273                         C.AutoIncrement = true;
274                         C.AutoIncrementSeed = 0;
275                         C.AutoIncrementStep = 1;
276                         _tbl.Columns.Add (C);
277                         _tbl.Columns.Add ("first", typeof (string));
278                         _tbl.Columns.Add ("second", typeof (decimal));
279                         
280                         DataRowCollection Rows = _tbl.Rows;
281                         
282                         DataRow Row = _tbl.NewRow ();
283                         _tbl.Rows.Add (Row);
284                         Row = _tbl.NewRow ();
285                         _tbl.Rows.Add (Row);
286                         Row = _tbl.NewRow ();
287                         _tbl.Rows.Add (Row);
288                         Row = _tbl.NewRow ();
289                         _tbl.Rows.Add (Row);
290                         
291                         Rows [0] [1] = "test0";
292                         Rows [0] [2] = 0;
293                         Rows [1] [1] = "test1";
294                         Rows [1] [2] = 1;
295                         Rows [2] [1] = "test2";
296                         Rows [2] [2] = 2;
297                         Rows [3] [1] = "test3";
298                         Rows [3] [2] = 3;
299                         
300                         AssertEquals ("test#01", 3, _tbl.Columns.Count);
301                         AssertEquals ("test#02", 4, _tbl.Rows.Count);
302                         AssertEquals ("test#03", 0, _tbl.Rows [0] [0]);
303                         AssertEquals ("test#04", 1, _tbl.Rows [1] [0]);
304                         AssertEquals ("test#05", 2, _tbl.Rows [2] [0]);
305                         AssertEquals ("test#06", 3, _tbl.Rows [3] [0]);
306                         
307                         try {
308                                 Rows.Contains (1);
309                                 Fail ("test#07");
310                         } catch (Exception e) {
311                                 AssertEquals ("test#08", typeof (MissingPrimaryKeyException), e.GetType ());
312                                 AssertEquals ("test#09", "Table doesn't have a primary key.", e.Message);                       
313                         }
314                         
315                         _tbl.PrimaryKey = new DataColumn [] {_tbl.Columns [0]};
316                         AssertEquals ("test#10", true, Rows.Contains (1));
317                         AssertEquals ("test#11", true, Rows.Contains (2));
318                         AssertEquals ("test#12", false, Rows.Contains (4));
319                         
320                         try {
321                                 Rows.Contains (new object [] {64, "test0"});
322                                 Fail ("test#13");
323                         } catch (Exception e) {
324                                 AssertEquals ("test#14", typeof (ArgumentException), e.GetType ());
325                                 AssertEquals ("test#15", "Expecting 1 value(s) for the key being indexed, but received 2 value(s).", e.Message);
326                         }
327                         
328                         _tbl.PrimaryKey = new DataColumn [] {_tbl.Columns [0], _tbl.Columns [1]};
329                         AssertEquals ("test#16", false, Rows.Contains (new object [] {64, "test0"}));
330                         AssertEquals ("test#17", false, Rows.Contains (new object [] {0, "test1"}));
331                         AssertEquals ("test#18", true, Rows.Contains (new object [] {1, "test1"}));
332                         AssertEquals ("test#19", true, Rows.Contains (new object [] {2, "test2"}));
333                         
334                         try {
335                                 Rows.Contains (new object [] {2});
336                                 Fail ("test#20");
337                         } catch (Exception e) {
338                                 AssertEquals ("test#21", typeof (ArgumentException), e.GetType ());
339                                 AssertEquals ("test#22", "Expecting 2 value(s) for the key being indexed, but received 1 value(s).", e.Message);
340                         }
341                 }
342                 
343                 [Test]
344                 public void CopyTo ()
345                 {
346                         _tbl.Columns.Add ();
347                         _tbl.Columns.Add ();
348                         _tbl.Columns.Add ();
349                         
350                         DataRowCollection Rows = _tbl.Rows;
351                         
352                         Rows.Add (new object [] {"1", "1", "1"});
353                         Rows.Add (new object [] {"2", "2", "2"});
354                         Rows.Add (new object [] {"3", "3", "3"});
355                         Rows.Add (new object [] {"4", "4", "4"});
356                         Rows.Add (new object [] {"5", "5", "5"});
357                         Rows.Add (new object [] {"6", "6", "6"});
358                         Rows.Add (new object [] {"7", "7", "7"});
359                         
360                         DataRow [] dr = new DataRow [10];
361                         
362                         try {
363                                 Rows.CopyTo (dr, 4);
364                                 Fail ("test#01");
365                         } catch (Exception e) {                 
366                                 AssertEquals ("test#02", typeof (ArgumentException), e.GetType ());
367                                 //AssertEquals ("test#03", "Destination array was not long enough.  Check destIndex and length, and the array's lower bounds.", e.Message);
368                         }
369                         
370                         dr = new DataRow [11];
371                         Rows.CopyTo (dr, 4);
372                         
373                         AssertEquals ("test#04", null, dr [0]);
374                         AssertEquals ("test#05", null, dr [1]);
375                         AssertEquals ("test#06", null, dr [2]);
376                         AssertEquals ("test#07", null, dr [3]);
377                         AssertEquals ("test#08", "1", dr [4] [0]);
378                         AssertEquals ("test#09", "2", dr [5] [0]);
379                         AssertEquals ("test#10", "3", dr [6] [0]);
380                         AssertEquals ("test#11", "4", dr [7] [0]);
381                         AssertEquals ("test#12", "5", dr [8] [0]);
382                         AssertEquals ("test#13", "6", dr [9] [0]);
383                 }
384                 
385                 [Test]
386                 public void Equals ()
387                 {
388                         _tbl.Columns.Add ();
389                         _tbl.Columns.Add ();
390                         _tbl.Columns.Add ();
391                         
392                         DataRowCollection Rows1 = _tbl.Rows;
393                         
394                         Rows1.Add (new object [] {"1", "1", "1"});
395                         Rows1.Add (new object [] {"2", "2", "2"});
396                         Rows1.Add (new object [] {"3", "3", "3"});
397                         Rows1.Add (new object [] {"4", "4", "4"});
398                         Rows1.Add (new object [] {"5", "5", "5"});
399                         Rows1.Add (new object [] {"6", "6", "6"});
400                         Rows1.Add (new object [] {"7", "7", "7"});
401                         
402                         DataRowCollection Rows2 = _tbl.Rows;
403                         
404                         AssertEquals ("test#01", true, Rows2.Equals (Rows1));
405                         AssertEquals ("test#02", true, Rows1.Equals (Rows2));
406                         AssertEquals ("test#03", true, Rows1.Equals (Rows1));
407                         
408                         DataTable Table = new DataTable ();
409                         Table.Columns.Add ();
410                         Table.Columns.Add ();
411                         Table.Columns.Add ();
412                         DataRowCollection Rows3 = Table.Rows;
413
414                         Rows3.Add (new object [] {"1", "1", "1"});
415                         Rows3.Add (new object [] {"2", "2", "2"});
416                         Rows3.Add (new object [] {"3", "3", "3"});
417                         Rows3.Add (new object [] {"4", "4", "4"});
418                         Rows3.Add (new object [] {"5", "5", "5"});
419                         Rows3.Add (new object [] {"6", "6", "6"});
420                         Rows3.Add (new object [] {"7", "7", "7"});
421                         
422                         AssertEquals ("test#04", false, Rows3.Equals (Rows1));
423                         AssertEquals ("test#05", false, Rows3.Equals (Rows2));
424                         AssertEquals ("test#06", false, Rows1.Equals (Rows3));
425                         AssertEquals ("test#07", false, Rows2.Equals (Rows3));
426                 }
427                 
428                 [Test]
429                 public void Find ()
430                 {
431                         DataColumn Col = new DataColumn ("test_1");
432                         Col.AllowDBNull = false;
433                         Col.Unique = true;
434                         Col.DataType = typeof (long);
435                         _tbl.Columns.Add (Col);
436                         
437                         Col = new DataColumn ("test_2");
438                         Col.DataType = typeof (string);
439                         _tbl.Columns.Add (Col);
440                         
441                         DataRowCollection Rows = _tbl.Rows;
442                         
443                         Rows.Add (new object [] {1, "first"});
444                         Rows.Add (new object [] {2, "second"});
445                         Rows.Add (new object [] {3, "third"});
446                         Rows.Add (new object [] {4, "fourth"});
447                         Rows.Add (new object [] {5, "fifth"});
448                         
449                         try {
450                                 Rows.Find (1);
451                                 Fail ("test#01");
452                         } catch (Exception e) {
453                                 AssertEquals ("test#02", typeof (MissingPrimaryKeyException), e.GetType ());
454                                 AssertEquals ("test#03", "Table doesn't have a primary key.", e.Message);              
455                         }
456                         
457                         _tbl.PrimaryKey = new DataColumn [] {_tbl.Columns [0]};
458                         DataRow row = Rows.Find (1);
459                         AssertEquals ("test#04", 1L, row [0]);
460                         row = Rows.Find (2);                    
461                         AssertEquals ("test#05", 2L, row [0]);
462                         row = Rows.Find ("2");
463                         AssertEquals ("test#06", 2L, row [0]);
464                         
465                         try {
466                                 row = Rows.Find ("test");
467                                 Fail ("test#07");
468                         } catch (Exception e) {
469                                 AssertEquals ("test#08", typeof (FormatException), e.GetType ());
470                                 //AssertEquals ("test#09", "Input string was not in a correct format.", e.Message);
471                         }
472                         
473                         String tes = null;                      
474                         row = Rows.Find (tes);                  
475                         AssertEquals ("test#10", null, row);
476                         _tbl.PrimaryKey = null;
477                         
478                         try {
479                                 Rows.Find (new object [] {1, "fir"});
480                                 Fail ("test#11");
481                         } catch (Exception e) {
482                                 AssertEquals ("test#12", typeof (MissingPrimaryKeyException), e.GetType ());
483                                 AssertEquals ("tets#13", "Table doesn't have a primary key.", e.Message);
484                         }
485                         
486                         _tbl.PrimaryKey = new DataColumn [] {_tbl.Columns [0], _tbl.Columns [1]};
487                         
488                         try {
489                                 Rows.Find (1);
490                                 Fail ("test#14");
491                         } catch (Exception e) {
492                                 AssertEquals ("test#15", typeof (ArgumentException), e.GetType ());
493                                 AssertEquals ("test#16", "Expecting 2 value(s) for the key being indexed, but received 1 value(s).", e.Message);
494                         }
495                         
496                         row = Rows.Find (new object [] {1, "fir"});
497                         AssertEquals ("test#16", null, row);
498                         row = Rows.Find (new object [] {1, "first"});
499                         AssertEquals ("test#17", 1L, row [0]);
500                 }
501                 
502                 [Test]
503                 public void InsertAt ()
504                 {
505                         _tbl.Columns.Add ();
506                         _tbl.Columns.Add ();
507                         _tbl.Columns.Add ();
508                         DataRowCollection Rows = _tbl.Rows;
509                         
510                         Rows.Add (new object [] {"a", "aa", "aaa"});
511                         Rows.Add (new object [] {"b", "bb", "bbb"});
512                         Rows.Add (new object [] {"c", "cc", "ccc"});
513                         Rows.Add (new object [] {"d", "dd", "ddd"});
514                         
515                         DataRow Row = _tbl.NewRow ();
516                         Row [0] = "e";
517                         Row [1] = "ee";
518                         Row [2] = "eee";
519                         
520                         try {
521                                 Rows.InsertAt (Row, -1);
522                                 Fail ("test#01");
523                         } catch (Exception e) {
524                                 AssertEquals ("test#02", typeof (IndexOutOfRangeException), e.GetType ());
525                                 AssertEquals ("test#03", "The row insert position -1 is invalid.", e.Message);
526                         }
527                         
528                         Rows.InsertAt (Row, 0);
529                         AssertEquals ("test#04", "e", Rows [0][0]);
530                         AssertEquals ("test#05", "a", Rows [1][0]);
531                         
532                         Row = _tbl.NewRow ();
533                         Row [0] = "f";
534                         Row [1] = "ff";
535                         Row [2] = "fff";
536                         
537                         Rows.InsertAt (Row, 5);
538                         AssertEquals ("test#06", "f", Rows [5][0]);
539                         
540                         Row = _tbl.NewRow ();
541                         Row [0] = "g";
542                         Row [1] = "gg";
543                         Row [2] = "ggg";
544
545                         Rows.InsertAt (Row, 500);
546                         AssertEquals ("test#07", "g", Rows [6][0]);
547
548                         try {
549                                 Rows.InsertAt (Row, 6); //Row already belongs to the table
550                                 Fail ("test#08");
551                         }
552                         catch (Exception e) {
553                                 AssertEquals ("test#09", typeof (ArgumentException), e.GetType ());
554                                 AssertEquals ("test#10", "This row already belongs to this table.", e.Message);
555                         }
556
557                         DataTable table = new DataTable ();
558                         DataColumn col = new DataColumn ("Name");
559                         table.Columns.Add (col);
560                         Row = table.NewRow ();
561                         Row ["Name"] = "Abc";
562                         table.Rows.Add (Row);
563                         try {
564                                 Rows.InsertAt (Row, 6);
565                                 Fail ("test#11");
566                         }
567                         catch (Exception e) {
568                                 AssertEquals ("test#12", typeof (ArgumentException), e.GetType ());
569                                 AssertEquals ("test#13", "This row already belongs to another table.", e.Message);
570                         }
571
572                         table = new DataTable ();
573                         col = new DataColumn ("Name");
574                         col.DataType = typeof (string);
575                         table.Columns.Add (col);
576                         UniqueConstraint uk = new UniqueConstraint (col);
577                         table.Constraints.Add (uk);
578                         
579                         Row = table.NewRow ();
580                         Row ["Name"] = "aaa";
581                         table.Rows.InsertAt (Row, 0);
582         
583                         Row = table.NewRow ();
584                         Row ["Name"] = "aaa";
585                         try {
586                                 table.Rows.InsertAt (Row, 1);
587                                 Fail ("test#14");
588                         }
589                         catch (Exception e) {
590                                 AssertEquals ("test#15", typeof (ConstraintException), e.GetType ());
591                         }
592                         try {
593                                 table.Rows.InsertAt (null, 1);
594                         }
595                         catch (Exception e) {
596                                 AssertEquals ("test#16", typeof (ArgumentNullException), e.GetType ());
597                         }
598                 }
599                 
600                 [Test]
601                 public void Remove ()
602                 {
603                         _tbl.Columns.Add ();
604                         _tbl.Columns.Add ();
605                         _tbl.Columns.Add ();
606                         DataRowCollection Rows = _tbl.Rows;
607                         
608                         Rows.Add (new object [] {"a", "aa", "aaa"});
609                         Rows.Add (new object [] {"b", "bb", "bbb"});
610                         Rows.Add (new object [] {"c", "cc", "ccc"});
611                         Rows.Add (new object [] {"d", "dd", "ddd"});
612                         
613                         AssertEquals ("test#01", 4, _tbl.Rows.Count);
614                         
615                         Rows.Remove (_tbl.Rows [1]);
616                         AssertEquals ("test#02", 3, _tbl.Rows.Count);
617                         AssertEquals ("test#03", "a", _tbl.Rows [0] [0]);
618                         AssertEquals ("test#04", "c", _tbl.Rows [1] [0]);
619                         AssertEquals ("test#05", "d", _tbl.Rows [2] [0]);
620                         
621                         try {
622                                 Rows.Remove (null);
623                                 Fail ("test#06");
624                         } catch (Exception e) {
625                                 AssertEquals ("test#07", typeof (IndexOutOfRangeException), e.GetType ());
626                                 AssertEquals ("test#08", "The given datarow is not in the current DataRowCollection.", e.Message);
627                         }
628                         
629                         DataRow Row = new DataTable ().NewRow ();
630                         
631                         try {
632                                 Rows.Remove (Row);
633                                 Fail ("test#09");
634                         } catch (Exception e) {
635                                 AssertEquals ("test#10", typeof (IndexOutOfRangeException), e.GetType ());
636                                 AssertEquals ("test#11", "The given datarow is not in the current DataRowCollection.", e.Message);
637                         }
638                         
639                         try {
640                                 Rows.RemoveAt (-1);
641                                 Fail ("test#12");
642                         } catch (Exception e) {
643                                 AssertEquals ("test#13", typeof (IndexOutOfRangeException), e.GetType ());
644                                 AssertEquals ("test#14", "There is no row at position -1.", e.Message);
645                         }
646                         
647                         try { 
648                                 Rows.RemoveAt (64);
649                                 Fail ("test#15");
650                         } catch (Exception e) {
651                                 AssertEquals ("test#16", typeof (IndexOutOfRangeException), e.GetType ());
652                                 AssertEquals ("test#17", "There is no row at position 64.", e.Message);
653                         }
654                         
655                         Rows.RemoveAt (0);
656                         Rows.RemoveAt (1);
657                         AssertEquals ("test#18", 1, Rows.Count);
658                         AssertEquals ("test#19", "c", Rows [0] [0]);
659                 }
660         }
661 }