7539d2010b9b7353c00916c4a4598d4a34885f2c
[mono.git] / mcs / class / System.Data / Test / System.Data / DataTableTest.cs
1 // DataTableTest.cs - NUnit Test Cases for testing the DataTable 
2 //
3 // Authors:
4 //   Franklin Wise (gracenote@earthlink.net)
5 //   Martin Willemoes Hansen (mwh@sysrq.dk)
6 // 
7 // (C) Franklin Wise
8 // (C) 2003 Martin Willemoes Hansen
9 // 
10
11 using NUnit.Framework;
12 using System;
13 using System.Data;
14 using System.Globalization;
15 using System.IO;
16 using System.Runtime.Serialization.Formatters.Binary;
17 using System.Xml;
18
19 namespace MonoTests.System.Data
20 {
21         [TestFixture]
22         public class DataTableTest : Assertion
23         {
24                 [Test]
25                 public void Ctor()
26                 {
27                         DataTable dt = new DataTable();
28
29                         AssertEquals("CaseSensitive must be false." ,false,dt.CaseSensitive);
30                         Assert("Col",dt.Columns != null);
31                         //Assert(dt.ChildRelations != null);
32                         Assert("Const", dt.Constraints != null);
33                         Assert("ds", dt.DataSet == null); 
34                         Assert("dv", dt.DefaultView != null);
35                         Assert("de", dt.DisplayExpression == "");
36                         Assert("ep", dt.ExtendedProperties != null);
37                         Assert("he", dt.HasErrors == false);
38                         Assert("lc", dt.Locale != null);
39                         Assert("mc", dt.MinimumCapacity == 50); //LAMESPEC:
40                         Assert("ns", dt.Namespace == "");
41                         //Assert(dt.ParentRelations != null);
42                         Assert("pf", dt.Prefix == "");
43                         Assert("pk", dt.PrimaryKey != null);
44                         Assert("rows", dt.Rows != null);
45                         Assert("Site", dt.Site == null);
46                         Assert("tname", dt.TableName == "");
47                         
48                 }
49
50                 [Test]
51                 public void Select ()
52                 {
53                         DataSet Set = new DataSet ();
54                         DataTable Mom = new DataTable ("Mom");
55                         DataTable Child = new DataTable ("Child");                      
56                         Set.Tables.Add (Mom);
57                         Set.Tables.Add (Child);
58                         
59                         DataColumn Col = new DataColumn ("Name");
60                         DataColumn Col2 = new DataColumn ("ChildName");
61                         Mom.Columns.Add (Col);
62                         Mom.Columns.Add (Col2);
63                         
64                         DataColumn Col3 = new DataColumn ("Name");
65                         DataColumn Col4 = new DataColumn ("Age");
66                         Col4.DataType = Type.GetType ("System.Int16");
67                         Child.Columns.Add (Col3);
68                         Child.Columns.Add (Col4);
69                         
70                         DataRelation Relation = new DataRelation ("Rel", Mom.Columns [1], Child.Columns [0]);
71                         Set.Relations.Add (Relation);
72
73                         DataRow Row = Mom.NewRow ();
74                         Row [0] = "Laura";
75                         Row [1] = "Nick";
76                         Mom.Rows.Add (Row);
77                         
78                         Row = Mom.NewRow ();
79                         Row [0] = "Laura";
80                         Row [1] = "Dick";
81                         Mom.Rows.Add (Row);
82                         
83                         Row = Mom.NewRow ();
84                         Row [0] = "Laura";
85                         Row [1] = "Mick";
86                         Mom.Rows.Add (Row);
87
88                         Row = Mom.NewRow ();
89                         Row [0] = "Teresa";
90                         Row [1] = "Jack";
91                         Mom.Rows.Add (Row);
92                         
93                         Row = Mom.NewRow ();
94                         Row [0] = "Teresa";
95                         Row [1] = "Mack";
96                         Mom.Rows.Add (Row);
97                         
98                         Row = Child.NewRow ();
99                         Row [0] = "Nick";
100                         Row [1] = 15;
101                         Child.Rows.Add (Row);
102                         
103                         Row = Child.NewRow ();
104                         Row [0] = "Dick";
105                         Row [1] = 25;
106                         Child.Rows.Add (Row);
107                         
108                         Row = Child.NewRow ();
109                         Row [0] = "Mick";
110                         Row [1] = 35;
111                         Child.Rows.Add (Row);
112                         
113                         Row = Child.NewRow ();
114                         Row [0] = "Jack";
115                         Row [1] = 10;
116                         Child.Rows.Add (Row);
117                         
118                         Row = Child.NewRow ();
119                         Row [0] = "Mack";
120                         Row [1] = 19;
121                         Child.Rows.Add (Row);
122                 
123                         Row = Child.NewRow ();
124                         Row [0] = "Mack";
125                         Row [1] = 99;
126                         Child.Rows.Add (Row);
127                         
128                         DataRow [] Rows = Mom.Select ("Name = 'Teresa'");
129                         AssertEquals ("test#01", 2, Rows.Length);
130                         
131                         Rows = Mom.Select ("Name = 'Teresa' and ChildName = 'Nick'");
132                         AssertEquals ("test#02", 0, Rows.Length);
133
134                         Rows = Mom.Select ("Name = 'Teresa' and ChildName = 'Jack'");
135                         AssertEquals ("test#03", 1, Rows.Length);
136
137                         Rows = Mom.Select ("Name = 'Teresa' and ChildName <> 'Jack'");
138                         AssertEquals ("test#04", "Mack", Rows [0] [1]);
139                         
140                         Rows = Mom.Select ("Name = 'Teresa' or ChildName <> 'Jack'");
141                         AssertEquals ("test#05", 5, Rows.Length);
142                         
143                         Rows = Child.Select ("age = 20 - 1");
144                         AssertEquals ("test#06", 1, Rows.Length);
145                         
146                         Rows = Child.Select ("age <= 20");
147                         AssertEquals ("test#07", 3, Rows.Length);
148                         
149                         Rows = Child.Select ("age >= 20");
150                         AssertEquals ("test#08", 3, Rows.Length);
151                         
152                         Rows = Child.Select ("age >= 20 and name = 'Mack' or name = 'Nick'");
153                         AssertEquals ("test#09", 2, Rows.Length);
154
155                         Rows = Child.Select ("age >= 20 and (name = 'Mack' or name = 'Nick')");
156                         AssertEquals ("test#10", 1, Rows.Length);
157                         AssertEquals ("test#11", "Mack", Rows [0] [0]);
158                         
159                         Rows = Child.Select ("not (Name = 'Jack')");
160                         AssertEquals ("test#12", 5, Rows.Length);
161                 }
162                 
163                 [Test]
164                 public void Select2 ()
165                 {
166                         DataSet Set = new DataSet ();
167                         DataTable Child = new DataTable ("Child");
168
169                         Set.Tables.Add (Child);
170                                                 
171                         DataColumn Col3 = new DataColumn ("Name");
172                         DataColumn Col4 = new DataColumn ("Age");
173                         Col4.DataType = Type.GetType ("System.Int16");
174                         Child.Columns.Add (Col3);
175                         Child.Columns.Add (Col4);
176                         
177                         DataRow Row = Child.NewRow ();
178                         Row [0] = "Nick";
179                         Row [1] = 15;
180                         Child.Rows.Add (Row);
181                         
182                         Row = Child.NewRow ();
183                         Row [0] = "Dick";
184                         Row [1] = 25;
185                         Child.Rows.Add (Row);
186                         
187                         Row = Child.NewRow ();
188                         Row [0] = "Mick";
189                         Row [1] = 35;
190                         Child.Rows.Add (Row);
191                         
192                         Row = Child.NewRow ();
193                         Row [0] = "Jack";
194                         Row [1] = 10;
195                         Child.Rows.Add (Row);
196                         
197                         Row = Child.NewRow ();
198                         Row [0] = "Mack";
199                         Row [1] = 19;
200                         Child.Rows.Add (Row);
201                 
202                         Row = Child.NewRow ();
203                         Row [0] = "Mack";
204                         Row [1] = 99;
205                         Child.Rows.Add (Row);
206
207                         DataRow [] Rows = Child.Select ("age >= 20", "age DESC");
208                         AssertEquals ("test#01", 3, Rows.Length);
209                         AssertEquals ("test#02", "Mack", Rows [0] [0]);
210                         AssertEquals ("test#03", "Mick", Rows [1] [0]);                 
211                         AssertEquals ("test#04", "Dick", Rows [2] [0]);                 
212                         
213                         Rows = Child.Select ("age >= 20", "age asc");
214                         AssertEquals ("test#05", 3, Rows.Length);
215                         AssertEquals ("test#06", "Dick", Rows [0] [0]);
216                         AssertEquals ("test#07", "Mick", Rows [1] [0]);                 
217                         AssertEquals ("test#08", "Mack", Rows [2] [0]);                 
218                 
219                         Rows = Child.Select ("age >= 20", "name asc");
220                         AssertEquals ("test#09", 3, Rows.Length);
221                         AssertEquals ("test#10", "Dick", Rows [0] [0]);
222                         AssertEquals ("test#11", "Mack", Rows [1] [0]);                 
223                         AssertEquals ("test#12", "Mick", Rows [2] [0]);                 
224
225                         Rows = Child.Select ("age >= 20", "name desc");
226                         AssertEquals ("test#09", 3, Rows.Length);
227                         AssertEquals ("test#10", "Mick", Rows [0] [0]);
228                         AssertEquals ("test#11", "Mack", Rows [1] [0]);                 
229                         AssertEquals ("test#12", "Dick", Rows [2] [0]);                 
230
231                 }
232
233                 [Test]
234                 public void SelectParsing ()
235                 {
236                         DataTable T = new DataTable ("test");
237                         DataColumn C = new DataColumn ("name");
238                         T.Columns.Add (C);
239                         C = new DataColumn ("age");
240                         C.DataType = typeof (int);
241                         T.Columns.Add (C);
242                         C = new DataColumn ("id");
243                         T.Columns.Add (C);
244                         
245                         DataSet Set = new DataSet ("TestSet");
246                         Set.Tables.Add (T);
247                         
248                         DataRow Row = null;
249                         for (int i = 0; i < 100; i++) {
250                                 Row = T.NewRow ();
251                                 Row [0] = "human" + i;
252                                 Row [1] = i;
253                                 Row [2] = i;
254                                 T.Rows.Add (Row);
255                         }
256                         
257                         Row = T.NewRow ();
258                         Row [0] = "h*an";
259                         Row [1] = 1;
260                         Row [2] = 1;
261                         T.Rows.Add (Row);
262
263                         AssertEquals ("test#01", 12, T.Select ("age<=10").Length);
264                         
265                         AssertEquals ("test#02", 12, T.Select ("age\n\t<\n\t=\t\n10").Length);
266
267                         try {
268                                 T.Select ("name = 1human ");
269                                 Fail ("test#03");
270                         } catch (Exception e) {
271                                 
272                                 // missing operand after 'human' operand 
273                                 AssertEquals ("test#04", typeof (SyntaxErrorException), e.GetType ());                          
274                         }
275                         
276                         try {                   
277                                 T.Select ("name = 1");
278                                 Fail ("test#05");
279                         } catch (Exception e) {
280                                 
281                                 // Cannot perform '=' operation between string and Int32
282                                 AssertEquals ("test#06", typeof (EvaluateException), e.GetType ());
283                         }
284                         
285                         AssertEquals ("test#07", 1, T.Select ("age = '13'").Length);
286
287                 }
288
289                 [Test]
290                 public void SelectOperators ()
291                 {
292                         DataTable T = new DataTable ("test");
293                         DataColumn C = new DataColumn ("name");
294                         T.Columns.Add (C);
295                         C = new DataColumn ("age");
296                         C.DataType = typeof (int);
297                         T.Columns.Add (C);
298                         C = new DataColumn ("id");
299                         T.Columns.Add (C);
300                         
301                         DataSet Set = new DataSet ("TestSet");
302                         Set.Tables.Add (T);
303                         
304                         DataRow Row = null;
305                         for (int i = 0; i < 100; i++) {
306                                 Row = T.NewRow ();
307                                 Row [0] = "human" + i;
308                                 Row [1] = i;
309                                 Row [2] = i;
310                                 T.Rows.Add (Row);
311                         }
312                         
313                         Row = T.NewRow ();
314                         Row [0] = "h*an";
315                         Row [1] = 1;
316                         Row [2] = 1;
317                         T.Rows.Add (Row);
318                         
319                         AssertEquals ("test#01", 11, T.Select ("age < 10").Length);
320                         AssertEquals ("test#02", 12, T.Select ("age <= 10").Length);                    
321                         AssertEquals ("test#03", 12, T.Select ("age< =10").Length);                     
322                         AssertEquals ("test#04", 89, T.Select ("age > 10").Length);
323                         AssertEquals ("test#05", 90, T.Select ("age >= 10").Length);                    
324                         AssertEquals ("test#06", 100, T.Select ("age <> 10").Length);
325                         AssertEquals ("test#07", 3, T.Select ("name < 'human10'").Length);
326                         AssertEquals ("test#08", 3, T.Select ("id < '10'").Length);
327                         // FIXME: Somebody explain how this can be possible.
328                         // it seems that it is no matter between 10 - 30. The
329                         // result is allways 25 :-P
330                         //AssertEquals ("test#09", 25, T.Select ("id < 10").Length);
331                         
332                 }
333
334                 [Test]
335                 public void SelectExceptions ()
336                 {
337                         DataTable T = new DataTable ("test");
338                         DataColumn C = new DataColumn ("name");
339                         T.Columns.Add (C);
340                         C = new DataColumn ("age");
341                         C.DataType = typeof (int);
342                         T.Columns.Add (C);
343                         C = new DataColumn ("id");
344                         T.Columns.Add (C);
345                         
346                         for (int i = 0; i < 100; i++) {
347                                 DataRow Row = T.NewRow ();
348                                 Row [0] = "human" + i;
349                                 Row [1] = i;
350                                 Row [2] = i;
351                                 T.Rows.Add (Row);
352                         }
353                         
354                         try {
355                                 T.Select ("name = human1");
356                                 Fail ("test#01");
357                         } catch (Exception e) {
358                                 
359                                 // column name human not found
360                                 AssertEquals ("test#02", typeof (EvaluateException), e.GetType ());
361                         }
362                         
363                         AssertEquals ("test#04", 1, T.Select ("id = '12'").Length);
364                         AssertEquals ("test#05", 1, T.Select ("id = 12").Length);
365                         
366                         try {
367                                 T.Select ("id = 1k3");
368                                 Fail ("test#06");
369                         } catch (Exception e) {
370                                 
371                                 // no operands after k3 operator
372                                 AssertEquals ("test#07", typeof (SyntaxErrorException), e.GetType ());
373                         }                                               
374                 }
375                 
376                 [Test]
377                 public void SelectStringOperators ()
378                 {
379                         DataTable T = new DataTable ("test");
380                         DataColumn C = new DataColumn ("name");
381                         T.Columns.Add (C);
382                         C = new DataColumn ("age");
383                         C.DataType = typeof (int);
384                         T.Columns.Add (C);
385                         C = new DataColumn ("id");
386                         T.Columns.Add (C);
387                         
388                         DataSet Set = new DataSet ("TestSet");
389                         Set.Tables.Add (T);
390                         
391                         DataRow Row = null;
392                         for (int i = 0; i < 100; i++) {
393                                 Row = T.NewRow ();
394                                 Row [0] = "human" + i;
395                                 Row [1] = i;
396                                 Row [2] = i;
397                                 T.Rows.Add (Row);
398                         }
399                         Row = T.NewRow ();
400                         Row [0] = "h*an";
401                         Row [1] = 1;
402                         Row [2] = 1;
403                         T.Rows.Add (Row);
404                                         
405                         AssertEquals ("test#01", 1, T.Select ("name = 'human' + 1").Length);
406                         
407                         AssertEquals ("test#02", "human1", T.Select ("name = 'human' + 1") [0] ["name"]);                       
408                         AssertEquals ("test#03", 1, T.Select ("name = 'human' + '1'").Length);
409                         AssertEquals ("test#04", "human1", T.Select ("name = 'human' + '1'") [0] ["name"]);                     
410                         AssertEquals ("test#05", 1, T.Select ("name = 'human' + 1 + 2").Length);
411                         AssertEquals ("test#06", "human12", T.Select ("name = 'human' + '1' + '2'") [0] ["name"]);
412                         
413                         AssertEquals ("test#07", 1, T.Select ("name = 'huMAn' + 1").Length);
414                         
415                         Set.CaseSensitive = true;
416                         AssertEquals ("test#08", 0, T.Select ("name = 'huMAn' + 1").Length);
417                         
418                         T.CaseSensitive = false;
419                         AssertEquals ("test#09", 1, T.Select ("name = 'huMAn' + 1").Length);
420                         
421                         T.CaseSensitive = true;
422                         AssertEquals ("test#10", 0, T.Select ("name = 'huMAn' + 1").Length);
423                         
424                         Set.CaseSensitive = false;
425                         AssertEquals ("test#11", 0, T.Select ("name = 'huMAn' + 1").Length);
426                         
427                         T.CaseSensitive = false;
428                         AssertEquals ("test#12", 1, T.Select ("name = 'huMAn' + 1").Length);
429                         
430                         AssertEquals ("test#13", 0, T.Select ("name = 'human1*'").Length);
431                         AssertEquals ("test#14", 11, T.Select ("name like 'human1*'").Length);
432                         AssertEquals ("test#15", 11, T.Select ("name like 'human1%'").Length);
433                         
434                         try {
435                                 AssertEquals ("test#16", 11, T.Select ("name like 'h*an1'").Length);
436                                 Fail ("test#16");
437                         } catch (Exception e) {
438                                 
439                                 // 'h*an1' is invalid
440                                 AssertEquals ("test#17", typeof (EvaluateException), e.GetType ());
441                         }
442                         
443                         try {
444                                 AssertEquals ("test#18", 11, T.Select ("name like 'h%an1'").Length);
445                                 Fail ("test#19");
446                         } catch (Exception e) {
447                                 
448                                 // 'h%an1' is invalid
449                                 AssertEquals ("test#20", typeof (EvaluateException), e.GetType ());
450                         }
451                         
452                         AssertEquals ("test#21", 0, T.Select ("name like 'h[%]an'").Length);
453                         AssertEquals ("test#22", 1, T.Select ("name like 'h[*]an'").Length);
454                         
455                 }
456
457                 [Test]
458                 public void SelectAggregates ()
459                 {
460                         DataTable T = new DataTable ("test");
461                         DataColumn C = new DataColumn ("name");
462                         T.Columns.Add (C);
463                         C = new DataColumn ("age");
464                         C.DataType = typeof (int);
465                         T.Columns.Add (C);
466                         C = new DataColumn ("id");
467                         T.Columns.Add (C);
468                         DataRow Row = null;
469                         
470                         for (int i = 0; i < 1000; i++) {
471                                 Row = T.NewRow ();
472                                 Row [0] = "human" + i;
473                                 Row [1] = i;
474                                 Row [2] = i;
475                                 T.Rows.Add (Row);
476                         }
477                         
478                         AssertEquals ("test#01", 1000, T.Select ("Sum(age) > 10").Length);
479                         AssertEquals ("test#02", 1000, T.Select ("avg(age) = 499").Length);
480                         AssertEquals ("test#03", 1000, T.Select ("min(age) = 0").Length);
481                         AssertEquals ("test#04", 1000, T.Select ("max(age) = 999").Length);
482                         AssertEquals ("test#05", 1000, T.Select ("count(age) = 1000").Length);
483                         AssertEquals ("test#06", 1000, T.Select ("stdev(age) > 287 and stdev(age) < 289").Length);
484                         AssertEquals ("test#07", 1000, T.Select ("var(age) < 83417 and var(age) > 83416").Length);
485                 }
486                 
487                 [Test]
488                 public void SelectFunctions ()
489                 {
490                         DataTable T = new DataTable ("test");
491                         DataColumn C = new DataColumn ("name");
492                         T.Columns.Add (C);
493                         C = new DataColumn ("age");
494                         C.DataType = typeof (int);
495                         T.Columns.Add (C);
496                         C = new DataColumn ("id");
497                         T.Columns.Add (C);
498                         DataRow Row = null;
499                         
500                         for (int i = 0; i < 1000; i++) {
501                                 Row = T.NewRow ();
502                                 Row [0] = "human" + i;
503                                 Row [1] = i;
504                                 Row [2] = i;
505                                 T.Rows.Add (Row);
506                         }
507                         
508                         Row = T.NewRow ();
509                         Row [0] = "human" + "test";
510                         Row [1] = DBNull.Value;
511                         Row [2] = DBNull.Value;
512                         T.Rows.Add (Row);
513
514                         //TODO: How to test Convert-function
515                         AssertEquals ("test#01", 25, T.Select ("age = 5*5") [0]["age"]);                        
516                         AssertEquals ("test#02", 901, T.Select ("len(name) > 7").Length);
517                         AssertEquals ("test#03", 125, T.Select ("age = 5*5*5 AND len(name)>7") [0]["age"]);
518                         AssertEquals ("test#04", 1, T.Select ("isnull(id, 'test') = 'test'").Length);                   
519                         AssertEquals ("test#05", 1000, T.Select ("iif(id = '56', 'test', 'false') = 'false'").Length);                  
520                         AssertEquals ("test#06", 1, T.Select ("iif(id = '56', 'test', 'false') = 'test'").Length);
521                         AssertEquals ("test#07", 9, T.Select ("substring(id, 2, 3) = '23'").Length);
522                         AssertEquals ("test#08", "123", T.Select ("substring(id, 2, 3) = '23'") [0] ["id"]);
523                         AssertEquals ("test#09", "423", T.Select ("substring(id, 2, 3) = '23'") [3] ["id"]);
524                         AssertEquals ("test#10", "923", T.Select ("substring(id, 2, 3) = '23'") [8] ["id"]);
525                         
526                 }
527
528                 [Test]
529                 public void SelectRelations ()
530                 {
531                         DataSet Set = new DataSet ();
532                         DataTable Mom = new DataTable ("Mom");
533                         DataTable Child = new DataTable ("Child");
534
535                         Set.Tables.Add (Mom);
536                         Set.Tables.Add (Child);
537                         
538                         DataColumn Col = new DataColumn ("Name");
539                         DataColumn Col2 = new DataColumn ("ChildName");
540                         Mom.Columns.Add (Col);
541                         Mom.Columns.Add (Col2);
542                         
543                         DataColumn Col3 = new DataColumn ("Name");
544                         DataColumn Col4 = new DataColumn ("Age");
545                         Col4.DataType = Type.GetType ("System.Int16");
546                         Child.Columns.Add (Col3);
547                         Child.Columns.Add (Col4);
548                         
549                         DataRelation Relation = new DataRelation ("Rel", Mom.Columns [1], Child.Columns [0]);
550                         Set.Relations.Add (Relation);
551
552                         DataRow Row = Mom.NewRow ();
553                         Row [0] = "Laura";
554                         Row [1] = "Nick";
555                         Mom.Rows.Add (Row);
556                         
557                         Row = Mom.NewRow ();
558                         Row [0] = "Laura";
559                         Row [1] = "Dick";
560                         Mom.Rows.Add (Row);
561                         
562                         Row = Mom.NewRow ();
563                         Row [0] = "Laura";
564                         Row [1] = "Mick";
565                         Mom.Rows.Add (Row);
566
567                         Row = Mom.NewRow ();
568                         Row [0] = "Teresa";
569                         Row [1] = "Jack";
570                         Mom.Rows.Add (Row);
571                         
572                         Row = Mom.NewRow ();
573                         Row [0] = "Teresa";
574                         Row [1] = "Mack";
575                         Mom.Rows.Add (Row);
576                         
577                         Row = Child.NewRow ();
578                         Row [0] = "Nick";
579                         Row [1] = 15;
580                         Child.Rows.Add (Row);
581                         
582                         Row = Child.NewRow ();
583                         Row [0] = "Dick";
584                         Row [1] = 25;
585                         Child.Rows.Add (Row);
586                         
587                         Row = Child.NewRow ();
588                         Row [0] = "Mick";
589                         Row [1] = 35;
590                         Child.Rows.Add (Row);
591                         
592                         Row = Child.NewRow ();
593                         Row [0] = "Jack";
594                         Row [1] = 10;
595                         Child.Rows.Add (Row);
596                         
597                         Row = Child.NewRow ();
598                         Row [0] = "Mack";
599                         Row [1] = 19;
600                         Child.Rows.Add (Row);
601                 
602                         Row = Child.NewRow ();
603                         Row [0] = "Mack";
604                         Row [1] = 99;
605                         Child.Rows.Add (Row);
606                         
607                         DataRow [] Rows = Child.Select ("name = Parent.Childname");
608                         AssertEquals ("test#01", 6, Rows.Length);
609                         Rows = Child.Select ("Parent.childname = 'Jack'");
610                         AssertEquals ("test#02", 1, Rows.Length);
611                         
612                         /*
613                         try {
614                                 // FIXME: LAMESPEC: Why the exception is thrown why... why... 
615                                 Mom.Select ("Child.Name = 'Jack'");
616                                 Fail ("test#03");
617                         } catch (Exception e) {
618                                 AssertEquals ("test#04", typeof (SyntaxErrorException), e.GetType ());
619                                 AssertEquals ("test#05", "Cannot interpret token 'Child' at position 1.", e.Message);
620                         }
621                         */
622                         
623                         Rows = Child.Select ("Parent.name = 'Laura'");
624                         AssertEquals ("test#06", 3, Rows.Length);
625                         
626                         DataTable Parent2 = new DataTable ("Parent2");
627                         Col = new DataColumn ("Name");
628                         Col2 = new DataColumn ("ChildName");
629
630                         Parent2.Columns.Add (Col);
631                         Parent2.Columns.Add (Col2);
632                         Set.Tables.Add (Parent2);
633                         
634                         Row = Parent2.NewRow ();
635                         Row [0] = "Laura";
636                         Row [1] = "Nick";
637                         Parent2.Rows.Add (Row);
638                         
639                         Row = Parent2.NewRow ();
640                         Row [0] = "Laura";
641                         Row [1] = "Dick";
642                         Parent2.Rows.Add (Row);
643                         
644                         Row = Parent2.NewRow ();
645                         Row [0] = "Laura";
646                         Row [1] = "Mick";
647                         Parent2.Rows.Add (Row);
648
649                         Row = Parent2.NewRow ();
650                         Row [0] = "Teresa";
651                         Row [1] = "Jack";
652                         Parent2.Rows.Add (Row);
653                         
654                         Row = Parent2.NewRow ();
655                         Row [0] = "Teresa";
656                         Row [1] = "Mack";
657                         Parent2.Rows.Add (Row);
658
659                         Relation = new DataRelation ("Rel2", Parent2.Columns [1], Child.Columns [0]);
660                         Set.Relations.Add (Relation);
661                         
662                         try {
663                                 Rows = Child.Select ("Parent.ChildName = 'Jack'");
664                                 Fail ("test#07");
665                         } catch (Exception e) {
666                                 AssertEquals ("test#08", typeof (EvaluateException), e.GetType ());
667                                 //AssertEquals ("test#09", "The table [Child] involved in more than one relation. You must explicitly mention a relation name in the expression 'parent.[ChildName]'.", e.Message);
668                         }
669                         
670                         Rows = Child.Select ("Parent(rel).ChildName = 'Jack'");
671                         AssertEquals ("test#10", 1, Rows.Length);
672
673                         Rows = Child.Select ("Parent(Rel2).ChildName = 'Jack'");
674                         AssertEquals ("test#10", 1, Rows.Length);
675                         
676                         try {
677                                 Mom.Select ("Parent.name  = 'John'");
678                         } catch (Exception e) {
679                                 AssertEquals ("test#11", typeof (IndexOutOfRangeException), e.GetType ());
680                                 AssertEquals ("test#12", "Cannot find relation 0.", e.Message);
681                         }
682                         
683                 }
684
685                 [Test]
686                 public void ToStringTest()
687                 {
688                         DataTable dt = new DataTable();
689                         dt.Columns.Add("Col1",typeof(int));
690                         
691                         dt.TableName = "Mytable";
692                         dt.DisplayExpression = "Col1";
693                         
694                         
695                         string cmpr = dt.TableName + " + " + dt.DisplayExpression;
696                         AssertEquals(cmpr,dt.ToString());
697                 }
698
699                 [Test]
700                 public void PrimaryKey ()
701                 {
702                         DataTable dt = new DataTable ();
703                         DataColumn Col = new DataColumn ();
704                         Col.AllowDBNull = false;
705                         Col.DataType = typeof (int);
706                         dt.Columns.Add (Col);
707                         dt.Columns.Add ();
708                         dt.Columns.Add ();
709                         dt.Columns.Add ();
710                         
711                         AssertEquals ("test#01", 0, dt.PrimaryKey.Length);
712                         
713                         dt.PrimaryKey = new DataColumn [] {dt.Columns [0]};
714                         AssertEquals ("test#02", 1, dt.PrimaryKey.Length);
715                         AssertEquals ("test#03", "Column1", dt.PrimaryKey [0].ColumnName);
716                         
717                         dt.PrimaryKey = null;
718                         AssertEquals ("test#04", 0, dt.PrimaryKey.Length);
719                         
720                         Col = new DataColumn ("failed");
721                         
722                         try {
723                                 dt.PrimaryKey = new DataColumn [] {Col};
724                                 Fail ("test#05");                                       
725                         } catch (Exception e) {
726                                 AssertEquals ("test#06", typeof (ArgumentException), e.GetType ());
727                                 AssertEquals ("test#07", "Column must belong to a table.", e.Message);
728                         }
729                         
730                         DataTable dt2 = new DataTable ();
731                         dt2.Columns.Add ();
732                         
733                         try {
734                                 dt.PrimaryKey = new DataColumn [] {dt2.Columns [0]};
735                                 Fail ("test#08");
736                         } catch (Exception e) {
737                                 AssertEquals ("test#09", typeof (ArgumentException), e.GetType ());
738                                 AssertEquals ("test#10", "PrimaryKey columns do not belong to this table.", e.Message);
739                         }
740                         
741                         
742                         AssertEquals ("test#11", 0, dt.Constraints.Count);
743                         
744                         dt.PrimaryKey = new DataColumn [] {dt.Columns [0], dt.Columns [1]};
745                         AssertEquals ("test#12", 2, dt.PrimaryKey.Length);
746                         AssertEquals ("test#13", 1, dt.Constraints.Count);
747                         AssertEquals ("test#14", true, dt.Constraints [0] is UniqueConstraint);
748                         AssertEquals ("test#15", "Column1", dt.PrimaryKey [0].ColumnName);
749                         AssertEquals ("test#16", "Column2", dt.PrimaryKey [1].ColumnName);
750                         
751                 }
752                 
753                 [Test]
754                 public void PropertyExceptions ()
755                 {
756                         DataSet set = new DataSet ();
757                         DataTable table = new DataTable ();
758                         DataTable table1 =  new DataTable ();
759                         set.Tables.Add (table);
760                         set.Tables.Add (table1);
761
762                         DataColumn col = new DataColumn ();
763                         col.ColumnName = "Id";
764                         col.DataType = Type.GetType ("System.Int32");
765                         table.Columns.Add (col);
766                         UniqueConstraint uc = new UniqueConstraint ("UK1", table.Columns[0] );
767                         table.Constraints.Add (uc);
768                         table.CaseSensitive = false;
769                                                                                                                            
770                         col = new DataColumn ();
771                         col.ColumnName = "Name";
772                         col.DataType = Type.GetType ("System.String");
773                         table.Columns.Add (col);
774                         
775                         col = new DataColumn ();
776                         col.ColumnName = "Id";
777                         col.DataType = Type.GetType ("System.Int32");
778                         table1.Columns.Add (col);
779                         col = new DataColumn ();
780                         col.ColumnName = "Name";
781                         col.DataType = Type.GetType ("System.String");
782                         table1.Columns.Add (col);
783
784                         DataRelation dr = new DataRelation ("DR", table.Columns[0], table1.Columns[0]);
785                         set.Relations.Add (dr);
786
787                         try {
788                                 table.CaseSensitive = true;
789                                 table1.CaseSensitive = true;
790                                 Fail ("#A01");
791                         }
792                         catch (Exception e) {
793                                 if (e.GetType () != typeof (AssertionException))
794                                         AssertEquals ("#A02", "Cannot change CaseSensitive or Locale property. This change would lead to at least one DataRelation or Constraint to have different Locale or CaseSensitive settings between its related tables.",e.Message);
795                                 else
796                                         Console.WriteLine (e);
797                         }
798                         try {
799                                 CultureInfo cultureInfo = new CultureInfo ("en-gb");
800                                 table.Locale = cultureInfo;
801                                 table1.Locale = cultureInfo;
802                                 Fail ("#A03");
803                         }
804                         catch (Exception e) {
805                                  if (e.GetType () != typeof (AssertionException))
806                                         AssertEquals ("#A04", "Cannot change CaseSensitive or Locale property. This change would lead to at least one DataRelation or Constraint to have different Locale or CaseSensitive settings between its related tables.",e.Message);
807                                 else
808                                         Console.WriteLine (e);
809                         }
810                         try {
811                                 table.Prefix = "Prefix#1";
812                                 Fail ("#A05");
813                         }
814                         catch (Exception e){
815                                 if (e.GetType () != typeof (AssertionException))
816                                         AssertEquals ("#A06", "Prefix 'Prefix#1' is not valid, because it contains special characters.",e.Message);
817                                 else
818                                         Console.WriteLine (e);
819
820                         }
821                 }
822
823                 [Test]
824                 public void GetErrors ()
825                 {
826                         DataTable table = new DataTable ();
827
828                         DataColumn col = new DataColumn ();
829                         col.ColumnName = "Id";
830                         col.DataType = Type.GetType ("System.Int32");
831                         table.Columns.Add (col);
832                                                                                                                              
833                         col = new DataColumn ();
834                         col.ColumnName = "Name";
835                         col.DataType = Type.GetType ("System.String");
836                         table.Columns.Add (col);
837                         
838                         DataRow row = table.NewRow ();
839                         row ["Id"] = 147;
840                         row ["name"] = "Abc";
841                         row.RowError = "Error#1";
842                         table.Rows.Add (row);
843
844                         AssertEquals ("#A01", 1, table.GetErrors ().Length);
845                         AssertEquals ("#A02", "Error#1", (table.GetErrors ())[0].RowError);
846                 }
847                 [Test]
848                 public void CloneCopyTest ()
849                 {
850                         DataTable table = new DataTable ();
851                         table.TableName = "Table#1";
852                         DataTable table1 = new DataTable ();
853                         table1.TableName = "Table#2";
854                 
855                         table.AcceptChanges ();
856                         
857                         DataSet set = new DataSet ("Data Set#1");
858                         set.DataSetName = "Dataset#1";
859                         set.Tables.Add (table);
860                         set.Tables.Add (table1);
861
862                         DataColumn col = new DataColumn ();
863                         col.ColumnName = "Id";
864                         col.DataType = Type.GetType ("System.Int32");
865                         table.Columns.Add (col);
866                         UniqueConstraint uc = new UniqueConstraint ("UK1", table.Columns[0] );
867                         table.Constraints.Add (uc);
868                 
869                         col = new DataColumn ();
870                         col.ColumnName = "Id";
871                         col.DataType = Type.GetType ("System.Int32");
872                         table1.Columns.Add (col);
873                                                                                                                              
874                         col = new DataColumn ();
875                         col.ColumnName = "Name";
876                         col.DataType = Type.GetType ("System.String");
877                         table.Columns.Add (col);
878                         
879                         col = new DataColumn ();
880                         col.ColumnName = "Name";
881                         col.DataType = Type.GetType ("System.String");
882                         table1.Columns.Add (col);
883                         DataRow row = table.NewRow ();
884                         row ["Id"] = 147;
885                         row ["name"] = "Abc";
886                         row.RowError = "Error#1";
887                         table.Rows.Add (row);
888                                                                                                                              
889                         row = table.NewRow ();
890                         row ["Id"] = 47;
891                         row ["name"] = "Efg";
892                         table.Rows.Add (row);
893                         table.AcceptChanges ();
894                                                                                                                              
895                         table.CaseSensitive = true;
896                         table1.CaseSensitive = true;
897                         table.MinimumCapacity = 100;
898                         table.Prefix = "PrefixNo:1";
899                         table.Namespace = "Namespace#1";
900                         table.DisplayExpression = "Id / Name + (Id * Id)";
901                         DataColumn[] colArray = {table.Columns[0]};
902                         table.PrimaryKey = colArray;
903                         table.ExtendedProperties.Add ("TimeStamp", DateTime.Now);
904 #if NET_1_1 // This prevents further tests after .NET 1.1.
905 #else
906                         CultureInfo cultureInfo = new CultureInfo ("en-gb");
907                         table.Locale = cultureInfo;
908 #endif
909
910                         row = table1.NewRow ();
911                         row ["Name"] = "Abc";
912                         row ["Id"] = 147;
913                         table1.Rows.Add (row);
914
915                         row = table1.NewRow ();
916                         row ["Id"] = 47;
917                         row ["Name"] = "Efg";
918                         table1.Rows.Add (row);
919                 
920                         DataRelation dr = new DataRelation ("DR", table.Columns[0], table1.Columns[0]);
921                         set.Relations.Add (dr);
922
923                         //Testing properties of clone
924                         DataTable cloneTable = table.Clone ();
925                         AssertEquals ("#A01",true ,cloneTable.CaseSensitive);
926                         AssertEquals ("#A02", 0 , cloneTable.ChildRelations.Count);
927                         AssertEquals ("#A03", 0 , cloneTable.ParentRelations.Count);
928                         AssertEquals ("#A04", 2,  cloneTable.Columns.Count);
929                         AssertEquals ("#A05", 1, cloneTable.Constraints.Count);
930                         AssertEquals ("#A06", "Id / Name + (Id * Id)", cloneTable.DisplayExpression);
931                         AssertEquals ("#A07", 1 ,cloneTable.ExtendedProperties.Count);
932                         AssertEquals ("#A08", false ,cloneTable.HasErrors);
933 #if NET_1_1
934 #else
935                         AssertEquals ("#A09", 2057, cloneTable.Locale.LCID);
936 #endif
937                         AssertEquals ("#A10", 100, cloneTable.MinimumCapacity);
938                         AssertEquals ("#A11","Namespace#1", cloneTable.Namespace);
939                         AssertEquals ("#A12", "PrefixNo:1",cloneTable.Prefix);
940                         AssertEquals ("#A13", "Id",  cloneTable.PrimaryKey[0].ColumnName);
941                         AssertEquals ("#A14",0 , cloneTable.Rows.Count );
942                         AssertEquals ("#A15", "Table#1", cloneTable.TableName);
943
944                         //Testing properties of copy
945                         DataTable copyTable = table.Copy ();
946                         AssertEquals ("#A16",true ,copyTable.CaseSensitive);
947                         AssertEquals ("#A17", 0 , copyTable.ChildRelations.Count);
948                         AssertEquals ("#A18", 0 , copyTable.ParentRelations.Count);
949                         AssertEquals ("#A19", 2,  copyTable.Columns.Count);
950                         AssertEquals ("#A20", 1, copyTable.Constraints.Count);
951                         AssertEquals ("#A21", "Id / Name + (Id * Id)", copyTable.DisplayExpression);
952                         AssertEquals ("#A22", 1 ,copyTable.ExtendedProperties.Count);
953                         AssertEquals ("#A23", true ,copyTable.HasErrors);
954 #if NET_1_1
955 #else
956                         AssertEquals ("#A24", 2057, copyTable.Locale.LCID);
957 #endif
958                         AssertEquals ("#A25", 100, copyTable.MinimumCapacity);
959                         AssertEquals ("#A26","Namespace#1", copyTable.Namespace);
960                         AssertEquals ("#A27", "PrefixNo:1",copyTable.Prefix);
961                         AssertEquals ("#A28", "Id",  copyTable.PrimaryKey[0].ColumnName);
962                         AssertEquals ("#A29", 2 , copyTable.Rows.Count );
963                         AssertEquals ("#A30", "Table#1", copyTable.TableName);
964                 }
965
966                 [Test]
967                 public void LoadDataException ()
968                 {
969                         DataTable table = new DataTable ();
970                         DataColumn col = new DataColumn ();
971                         col.ColumnName = "Id";
972                         col.DataType = Type.GetType ("System.Int32");
973                         col.DefaultValue = 47;
974                         table.Columns.Add (col);
975                         UniqueConstraint uc = new UniqueConstraint ("UK1", table.Columns[0] );
976                         table.Constraints.Add (uc);
977                 
978                         col = new DataColumn ();
979                         col.ColumnName = "Name";
980                         col.DataType = Type.GetType ("System.String");
981                         col.DefaultValue = "Hello";
982                         table.Columns.Add (col);
983                 
984                         table.BeginLoadData();
985                         object[] row = {147, "Abc"};
986                         DataRow newRow = table.LoadDataRow (row, true);
987                 
988                         object[] row1 = {147, "Efg"};
989                         DataRow newRow1 = table.LoadDataRow (row1, true);
990                                                                                                                              
991                         object[] row2 = {143, "Hij"};
992                         DataRow newRow2 = table.LoadDataRow (row2, true);
993                                                                                                                              
994                         try {
995                                 table.EndLoadData ();
996                                 Fail ("#A01");
997                         }
998                         catch (ConstraintException) {
999                         }
1000                 }
1001                 [Test]
1002                 public void Changes () //To test GetChanges and RejectChanges
1003                 {
1004                         DataTable table = new DataTable ();
1005
1006                         DataColumn col = new DataColumn ();
1007                         col.ColumnName = "Id";
1008                         col.DataType = Type.GetType ("System.Int32");
1009                         table.Columns.Add (col);
1010                         UniqueConstraint uc = new UniqueConstraint ("UK1", table.Columns[0] );
1011                         table.Constraints.Add (uc);
1012                                                                                                                              
1013                         col = new DataColumn ();
1014                         col.ColumnName = "Name";
1015                         col.DataType = Type.GetType ("System.String");
1016                         table.Columns.Add (col);                        
1017
1018                         DataRow row = table.NewRow ();
1019                         row ["Id"] = 147;
1020                         row ["name"] = "Abc";
1021                         table.Rows.Add (row);
1022                         table.AcceptChanges ();
1023                         
1024                         row = table.NewRow ();
1025                         row ["Id"] = 47;
1026                         row ["name"] = "Efg";
1027                         table.Rows.Add (row);
1028
1029                         //Testing GetChanges
1030                         DataTable changesTable = table.GetChanges ();
1031                         AssertEquals ("#A01", 1 ,changesTable.Rows.Count);
1032                         AssertEquals ("#A02","Efg" ,changesTable.Rows[0]["Name"]);                      
1033                         table.AcceptChanges ();
1034                         changesTable = table.GetChanges ();
1035                         try {
1036                                 int cnt = changesTable.Rows.Count;
1037                         }
1038                         catch(Exception e) {
1039                                 if (e.GetType () != typeof (AssertionException))
1040                                         AssertEquals ("#A03",typeof(NullReferenceException) ,e.GetType ());
1041                                 else
1042                                         Console.WriteLine (e);
1043                         }
1044                         
1045                         //Testing RejectChanges
1046                         row = table.NewRow ();
1047                         row ["Id"] = 247;
1048                         row ["name"] = "Hij";
1049                         table.Rows.Add (row);
1050
1051                         (table.Rows [0])["Name"] = "AaBbCc";
1052                         table.RejectChanges ();
1053                         AssertEquals ("#A03", "Abc" , (table.Rows [0]) ["Name"]);
1054                         AssertEquals ("#A04", 2, table.Rows.Count);
1055                 }
1056                 [Test]
1057                 public void ImportRow ()
1058                 {
1059                         DataTable table = new DataTable ();
1060                         DataColumn col = new DataColumn ();
1061                         col.ColumnName = "Id";
1062                         col.DataType = Type.GetType ("System.Int32");
1063                         table.Columns.Add (col);
1064                         
1065                         col = new DataColumn ();
1066                         col.ColumnName = "Name";
1067                         col.DataType = Type.GetType ("System.String");
1068                         table.Columns.Add (col);
1069                         
1070                         DataRow row = table.NewRow ();
1071                         row ["Id"] = 147;
1072                         row ["name"] = "Abc";
1073                         table.Rows.Add (row);
1074                         table.AcceptChanges ();
1075                                                                                                      
1076                         row = table.NewRow ();
1077                         row ["Id"] = 47;
1078                         row ["name"] = "Efg";
1079                         table.Rows.Add (row);
1080
1081                         (table.Rows [0]) ["Name"] = "AaBbCc";
1082                 
1083                         table.ImportRow (table.Rows [0]);
1084                         table.ImportRow (table.Rows [1]);
1085
1086                         AssertEquals ("#A01", 147, table.Rows [2]["Id"]);
1087                         AssertEquals ("#A02", 47, table.Rows [3]["Id"]);
1088                         AssertEquals ("#A03", DataRowState.Modified, table.Rows [2].RowState);
1089                         AssertEquals ("#A04", DataRowState.Added, table.Rows [3].RowState);
1090                 }
1091                 [Test]
1092                 public void ClearReset () //To test Clear and Reset methods
1093                 {
1094                         DataTable table = new DataTable ();
1095                         DataTable table1 = new DataTable ();
1096                 
1097                         DataSet set = new DataSet ();
1098                         set.Tables.Add (table);
1099                         set.Tables.Add (table1);
1100                 
1101                         DataColumn col = new DataColumn ();
1102                         col.ColumnName = "Id";
1103                         col.DataType = Type.GetType ("System.Int32");
1104                         table.Columns.Add (col);
1105                         UniqueConstraint uc = new UniqueConstraint ("UK1", table.Columns[0] );
1106                         table.Constraints.Add (uc);
1107                         table.CaseSensitive = false;
1108                 
1109                         col = new DataColumn ();
1110                         col.ColumnName = "Name";
1111                         col.DataType = Type.GetType ("System.String");
1112                         table.Columns.Add (col);
1113                 
1114                         col = new DataColumn ();
1115                         col.ColumnName = "Id";
1116                         col.DataType = Type.GetType ("System.Int32");
1117                         table1.Columns.Add (col);
1118                 
1119                         col = new DataColumn ();
1120                         col.ColumnName = "Name";
1121                         col.DataType = Type.GetType ("System.String");
1122                         table1.Columns.Add (col);
1123
1124                         DataRelation dr = new DataRelation ("DR", table.Columns[0], table1.Columns[0]);
1125                         set.Relations.Add (dr);
1126                 
1127                         DataRow row = table.NewRow ();
1128                         row ["Id"] = 147;
1129                         row ["name"] = "Roopa";
1130                         table.Rows.Add (row);
1131                 
1132                         row = table.NewRow ();
1133                         row ["Id"] = 47;
1134                         row ["Name"] = "roopa";
1135                         table.Rows.Add (row);
1136                 
1137                         try {
1138                                 table.Reset ();
1139                                 Fail ("#A01");
1140                         }
1141                         catch (ArgumentException) {
1142                         }
1143                         try {
1144                                 table.Clear ();
1145 #if NET_1_1
1146 #else
1147                                 Fail ("#A03");
1148 #endif
1149                         }
1150                         catch (Exception e) {
1151 #if NET_1_1
1152                                 throw e;
1153 #else
1154                                 if (e.GetType () != typeof (AssertionException)) {
1155                                         // FIXME: Don't depend on localizable error messages.
1156                                         AssertEquals ("#A04", "Cannot clear table Parent because ForeignKeyConstraint DR enforces Child.", e.Message);
1157                                 }
1158                                 else throw e;
1159 #endif
1160                         }
1161                         table1.Reset ();
1162                         AssertEquals ("#A05", 0, table1.Rows.Count);
1163                         AssertEquals ("#A06", 0, table1.Constraints.Count);
1164                         AssertEquals ("#A07", 0, table1.ParentRelations.Count);
1165                 
1166                         table.Clear ();
1167                         AssertEquals ("#A08", 0, table.Rows.Count);
1168 #if NET_1_1
1169                         AssertEquals ("#A09", 0, table.Constraints.Count);
1170 #else
1171                         AssertEquals ("#A09", 1, table.Constraints.Count);
1172 #endif
1173                         AssertEquals ("#A05", 0, table.ChildRelations.Count);
1174                 }
1175
1176                 [Test]
1177                 public void Serialize ()
1178                 {
1179                         MemoryStream fs = new MemoryStream ();
1180                         
1181                         // Construct a BinaryFormatter and use it 
1182                         // to serialize the data to the stream.
1183                         BinaryFormatter formatter = new BinaryFormatter();
1184                 
1185                         // Create an array with multiple elements refering to 
1186                         // the one Singleton object.
1187                         DataTable dt = new DataTable();
1188                 
1189                 
1190                         dt.Columns.Add(new DataColumn("Id", typeof(string)));
1191                         dt.Columns.Add(new DataColumn("ContactName", typeof(string)));
1192                         dt.Columns.Add(new DataColumn("ContactTitle", typeof(string)));
1193                         dt.Columns.Add(new DataColumn("ContactAreaCode", typeof(string)));
1194                         dt.Columns.Add(new DataColumn("ContactPhone", typeof(string)));
1195                 
1196                         DataRow loRowToAdd;
1197                         loRowToAdd = dt.NewRow();
1198                         loRowToAdd[0] = "a";
1199                         loRowToAdd[1] = "b";
1200                         loRowToAdd[2] = "c";
1201                         loRowToAdd[3] = "d";
1202                         loRowToAdd[4] = "e";
1203                                                 
1204                         dt.Rows.Add(loRowToAdd);
1205                 
1206                         DataTable[] dtarr = new DataTable[] {dt}; 
1207                 
1208                         // Serialize the array elements.
1209                         formatter.Serialize(fs, dtarr);
1210                 
1211                         // Deserialize the array elements.
1212                         fs.Position = 0;
1213                         DataTable[] a2 = (DataTable[]) formatter.Deserialize(fs);
1214                 
1215                         DataSet ds = new DataSet();
1216                         ds.Tables.Add(a2[0]);
1217                 
1218                         StringWriter sw = new StringWriter ();
1219                         ds.WriteXml(sw);
1220                         XmlDocument doc = new XmlDocument ();
1221                         doc.LoadXml (sw.ToString ());
1222                         AssertEquals (5, doc.DocumentElement.FirstChild.ChildNodes.Count);
1223                 }
1224         }
1225 }