Merge pull request #3091 from alexanderkyte/mobile_static_fix_mcs_tests
[mono.git] / mcs / class / System.Data / Test / System.Data / DataTableTest5.cs
1 // Authors:
2 //   Nagappan A <anagappan@novell.com>
3 //
4 // Copyright (c) 2007 Novell, Inc
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining
7 // a copy of this software and associated documentation files (the
8 // "Software"), to deal in the Software without restriction, including
9 // without limitation the rights to use, copy, modify, merge, publish,
10 // distribute, sublicense, and/or sell copies of the Software, and to
11 // permit persons to whom the Software is furnished to do so, subject to
12 // the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 //
25
26 using System;
27 using System.Collections;
28 using System.Data;
29 using System.Diagnostics;
30 using System.IO;
31 using System.Xml;
32 using System.Xml.Serialization;
33
34 using NUnit.Framework;
35
36 namespace MonoTests.System.Data
37 {
38         [TestFixture]
39         public class DataTableTest5
40         {
41                 string tempFile;
42                 DataSet dataSet;
43                 DataTable dummyTable;
44                 DataTable parentTable1;
45                 DataTable childTable;
46                 DataTable secondChildTable;
47
48                 [SetUp]
49                 public void SetUp ()
50                 {
51                         tempFile = Path.GetTempFileName ();
52                 }
53
54                 [TearDown]
55                 public void TearDown ()
56                 {
57                         if (tempFile != null)
58                                 File.Delete (tempFile);
59                 }
60
61                 void WriteXmlSerializable (Stream s, DataTable dt)
62                 {
63                         XmlWriterSettings ws = new XmlWriterSettings ();
64                         using (XmlWriter xw = XmlWriter.Create (s, ws)) {
65                                 IXmlSerializable idt = dt;
66                                 xw.WriteStartElement ("start");
67                                 idt.WriteXml (xw);
68                                 xw.WriteEndElement ();
69                                 xw.Close ();
70                         }
71                 }
72
73                 void ReadXmlSerializable (Stream s, DataTable dt)
74                 {
75                         using (XmlReader xr = XmlReader.Create (s)) {
76                                 ReadXmlSerializable (dt, xr);
77                         }
78                 }
79
80                 private static void ReadXmlSerializable (DataTable dt, XmlReader xr)
81                 {
82                         XmlSerializer serializer = new XmlSerializer (dt.GetType ());
83                         IXmlSerializable idt = dt;
84                         idt.ReadXml (xr);
85                         xr.Close ();
86                 }
87
88                 void ReadXmlSerializable (string fileName, DataTable dt)
89                 {
90                         using (XmlReader xr = XmlReader.Create (fileName)) {
91                                 ReadXmlSerializable (dt, xr);
92                         }
93                 }
94
95                 private void MakeParentTable1 ()
96                 {
97                         // Create a new Table
98                         parentTable1 = new DataTable ("ParentTable");
99                         dataSet = new DataSet ("XmlDataSet");
100                         DataColumn column;
101                         DataRow row;
102
103                         // Create new DataColumn, set DataType,
104                         // ColumnName and add to Table.
105                         column = new DataColumn ();
106                         column.DataType = typeof (int);
107                         column.ColumnName = "id";
108                         column.Unique = true;
109                         // Add the Column to the DataColumnCollection.
110                         parentTable1.Columns.Add (column);
111
112                         // Create second column
113                         column = new DataColumn ();
114                         column.DataType = typeof (string);
115                         column.ColumnName = "ParentItem";
116                         column.AutoIncrement = false;
117                         column.Caption = "ParentItem";
118                         column.Unique = false;
119                         // Add the column to the table
120                         parentTable1.Columns.Add (column);
121
122                         // Create third column.
123                         column = new DataColumn ();
124                         column.DataType = typeof (int);
125                         column.ColumnName = "DepartmentID";
126                         column.Caption = "DepartmentID";
127                         // Add the column to the table.
128                         parentTable1.Columns.Add (column);
129
130                         // Make the ID column the primary key column.
131                         DataColumn [] PrimaryKeyColumns = new DataColumn [2];
132                         PrimaryKeyColumns [0] = parentTable1.Columns ["id"];
133                         PrimaryKeyColumns [1] = parentTable1.Columns ["DepartmentID"];
134                         parentTable1.PrimaryKey = PrimaryKeyColumns;
135
136                         dataSet.Tables.Add (parentTable1);
137
138                         // Create three new DataRow objects and add 
139                         // them to the DataTable
140                         for (int i = 0; i <= 2; i++) {
141                                 row = parentTable1.NewRow ();
142                                 row ["id"] = i + 1;
143                                 row ["ParentItem"] = "ParentItem " + (i + 1);
144                                 row ["DepartmentID"] = i + 1;
145                                 parentTable1.Rows.Add (row);
146                         }
147                 }
148
149                 private void MakeDummyTable ()
150                 {
151                         // Create a new Table
152                         dataSet = new DataSet ();
153                         dummyTable = new DataTable ("DummyTable");
154                         DataColumn column;
155                         DataRow row;
156
157                         // Create new DataColumn, set DataType, 
158                         // ColumnName and add to Table.
159                         column = new DataColumn ();
160                         column.DataType = typeof (int);
161                         column.ColumnName = "id";
162                         column.Unique = true;
163                         // Add the Column to the DataColumnCollection.
164                         dummyTable.Columns.Add (column);
165
166                         // Create second column
167                         column = new DataColumn ();
168                         column.DataType = typeof (string);
169                         column.ColumnName = "DummyItem";
170                         column.AutoIncrement = false;
171                         column.Caption = "DummyItem";
172                         column.Unique = false;
173                         // Add the column to the table
174                         dummyTable.Columns.Add (column);
175
176                         dataSet.Tables.Add (dummyTable);
177
178                         // Create three new DataRow objects and add 
179                         // them to the DataTable
180                         for (int i = 0; i <= 2; i++) {
181                                 row = dummyTable.NewRow ();
182                                 row ["id"] = i + 1;
183                                 row ["DummyItem"] = "DummyItem " + (i + 1);
184                                 dummyTable.Rows.Add (row);
185                         }
186
187                         DataRow row1 = dummyTable.Rows [1];
188                         dummyTable.AcceptChanges ();
189                         row1.BeginEdit ();
190                         row1 [1] = "Changed_DummyItem " + 2;
191                         row1.EndEdit ();
192                 }
193
194                 private void MakeChildTable ()
195                 {
196                         // Create a new Table
197                         childTable = new DataTable ("ChildTable");
198                         DataColumn column;
199                         DataRow row;
200
201                         // Create first column and add to the DataTable.
202                         column = new DataColumn ();
203                         column.DataType = typeof (int);
204                         column.ColumnName = "ChildID";
205                         column.AutoIncrement = true;
206                         column.Caption = "ID";
207                         column.Unique = true;
208
209                         // Add the column to the DataColumnCollection
210                         childTable.Columns.Add (column);
211
212                         // Create second column
213                         column = new DataColumn ();
214                         column.DataType = typeof (string);
215                         column.ColumnName = "ChildItem";
216                         column.AutoIncrement = false;
217                         column.Caption = "ChildItem";
218                         column.Unique = false;
219                         childTable.Columns.Add (column);
220
221                         //Create third column
222                         column = new DataColumn ();
223                         column.DataType = typeof (int);
224                         column.ColumnName = "ParentID";
225                         column.AutoIncrement = false;
226                         column.Caption = "ParentID";
227                         column.Unique = false;
228                         childTable.Columns.Add (column);
229
230                         dataSet.Tables.Add (childTable);
231
232                         // Create three sets of DataRow objects, 
233                         // five rows each, and add to DataTable.
234                         for (int i = 0; i <= 1; i++) {
235                                 row = childTable.NewRow ();
236                                 row ["childID"] = i + 1;
237                                 row ["ChildItem"] = "ChildItem " + (i + 1);
238                                 row ["ParentID"] = 1;
239                                 childTable.Rows.Add (row);
240                         }
241                         for (int i = 0; i <= 1; i++) {
242                                 row = childTable.NewRow ();
243                                 row ["childID"] = i + 5;
244                                 row ["ChildItem"] = "ChildItem " + (i + 1);
245                                 row ["ParentID"] = 2;
246                                 childTable.Rows.Add (row);
247                         }
248                         for (int i = 0; i <= 1; i++) {
249                                 row = childTable.NewRow ();
250                                 row ["childID"] = i + 10;
251                                 row ["ChildItem"] = "ChildItem " + (i + 1);
252                                 row ["ParentID"] = 3;
253                                 childTable.Rows.Add (row);
254                         }
255                 }
256
257                 private void MakeSecondChildTable ()
258                 {
259                         // Create a new Table
260                         secondChildTable = new DataTable ("SecondChildTable");
261                         DataColumn column;
262                         DataRow row;
263
264                         // Create first column and add to the DataTable.
265                         column = new DataColumn ();
266                         column.DataType = typeof (int);
267                         column.ColumnName = "ChildID";
268                         column.AutoIncrement = true;
269                         column.Caption = "ID";
270                         column.ReadOnly = true;
271                         column.Unique = true;
272
273                         // Add the column to the DataColumnCollection.
274                         secondChildTable.Columns.Add (column);
275
276                         // Create second column.
277                         column = new DataColumn ();
278                         column.DataType = typeof (string);
279                         column.ColumnName = "ChildItem";
280                         column.AutoIncrement = false;
281                         column.Caption = "ChildItem";
282                         column.ReadOnly = false;
283                         column.Unique = false;
284                         secondChildTable.Columns.Add (column);
285
286                         //Create third column.
287                         column = new DataColumn ();
288                         column.DataType = typeof (int);
289                         column.ColumnName = "ParentID";
290                         column.AutoIncrement = false;
291                         column.Caption = "ParentID";
292                         column.ReadOnly = false;
293                         column.Unique = false;
294                         secondChildTable.Columns.Add (column);
295
296                         //Create fourth column.
297                         column = new DataColumn ();
298                         column.DataType = typeof (int);
299                         column.ColumnName = "DepartmentID";
300                         column.Caption = "DepartmentID";
301                         column.Unique = false;
302                         secondChildTable.Columns.Add (column);
303
304                         dataSet.Tables.Add (secondChildTable);
305                         // Create three sets of DataRow objects, 
306                         // five rows each, and add to DataTable.
307                         for (int i = 0; i <= 1; i++) {
308                                 row = secondChildTable.NewRow ();
309                                 row ["childID"] = i + 1;
310                                 row ["ChildItem"] = "SecondChildItem " + (i + 1);
311                                 row ["ParentID"] = 1;
312                                 row ["DepartmentID"] = 1;
313                                 secondChildTable.Rows.Add (row);
314                         }
315                         for (int i = 0; i <= 1; i++) {
316                                 row = secondChildTable.NewRow ();
317                                 row ["childID"] = i + 5;
318                                 row ["ChildItem"] = "SecondChildItem " + (i + 1);
319                                 row ["ParentID"] = 2;
320                                 row ["DepartmentID"] = 2;
321                                 secondChildTable.Rows.Add (row);
322                         }
323                         for (int i = 0; i <= 1; i++) {
324                                 row = secondChildTable.NewRow ();
325                                 row ["childID"] = i + 10;
326                                 row ["ChildItem"] = "SecondChildItem " + (i + 1);
327                                 row ["ParentID"] = 3;
328                                 row ["DepartmentID"] = 3;
329                                 secondChildTable.Rows.Add (row);
330                         }
331                 }
332
333                 private void MakeDataRelation ()
334                 {
335                         DataColumn parentColumn = dataSet.Tables ["ParentTable"].Columns ["id"];
336                         DataColumn childColumn = dataSet.Tables ["ChildTable"].Columns ["ParentID"];
337                         DataRelation relation = new DataRelation ("ParentChild_Relation1", parentColumn, childColumn);
338                         dataSet.Tables ["ChildTable"].ParentRelations.Add (relation);
339
340                         DataColumn [] parentColumn1 = new DataColumn [2];
341                         DataColumn [] childColumn1 = new DataColumn [2];
342
343                         parentColumn1 [0] = dataSet.Tables ["ParentTable"].Columns ["id"];
344                         parentColumn1 [1] = dataSet.Tables ["ParentTable"].Columns ["DepartmentID"];
345
346                         childColumn1 [0] = dataSet.Tables ["SecondChildTable"].Columns ["ParentID"];
347                         childColumn1 [1] = dataSet.Tables ["SecondChildTable"].Columns ["DepartmentID"];
348
349                         DataRelation secondRelation = new DataRelation ("ParentChild_Relation2", parentColumn1, childColumn1);
350                         dataSet.Tables ["SecondChildTable"].ParentRelations.Add (secondRelation);
351                 }
352
353                 private void MakeDataRelation (DataTable dt)
354                 {
355                         DataColumn parentColumn = dt.Columns ["id"];
356                         DataColumn childColumn = dataSet.Tables ["ChildTable"].Columns ["ParentID"];
357                         DataRelation relation = new DataRelation ("ParentChild_Relation1", parentColumn, childColumn);
358                         dataSet.Tables ["ChildTable"].ParentRelations.Add (relation);
359
360                         DataColumn [] parentColumn1 = new DataColumn [2];
361                         DataColumn [] childColumn1 = new DataColumn [2];
362
363                         parentColumn1 [0] = dt.Columns ["id"];
364                         parentColumn1 [1] = dt.Columns ["DepartmentID"];
365
366                         childColumn1 [0] = dataSet.Tables ["SecondChildTable"].Columns ["ParentID"];
367                         childColumn1 [1] = dataSet.Tables ["SecondChildTable"].Columns ["DepartmentID"];
368
369                         DataRelation secondRelation = new DataRelation ("ParentChild_Relation2", parentColumn1, childColumn1);
370                         dataSet.Tables ["SecondChildTable"].ParentRelations.Add (secondRelation);
371                 }
372
373                 //Test properties of a table which does not belongs to a DataSet
374                 private void VerifyTableSchema (DataTable table, string tableName, DataSet ds)
375                 {
376                         //Test Schema 
377                         //Check Properties of Table
378                         Assert.AreEqual (string.Empty, table.Namespace, "#1");
379                         Assert.AreEqual (ds, table.DataSet, "#2");
380                         Assert.AreEqual (3, table.Columns.Count, "#3");
381                         Assert.AreEqual (false, table.CaseSensitive, "#5");
382                         Assert.AreEqual (tableName, table.TableName, "#6");
383                         Assert.AreEqual (2, table.Constraints.Count, "#7");
384                         Assert.AreEqual (string.Empty, table.Prefix, "#8");
385                         Assert.AreEqual (2, table.Constraints .Count, "#10");
386                         Assert.AreEqual (typeof (UniqueConstraint), table.Constraints [0].GetType (), "#11");
387                         Assert.AreEqual (typeof (UniqueConstraint), table.Constraints [1].GetType (), "#12");
388                         Assert.AreEqual (2, table.PrimaryKey.Length, "#13");
389                         Assert.AreEqual ("id", table.PrimaryKey [0].ToString (), "#14");
390                         Assert.AreEqual ("DepartmentID", table.PrimaryKey [1].ToString (), "#15");
391                         Assert.AreEqual (0, table.ParentRelations.Count, "#16");
392                         Assert.AreEqual (0, table.ChildRelations.Count, "#17");
393
394                         //Check properties of each column
395                         //First Column
396                         DataColumn col = table.Columns [0];
397                         Assert.AreEqual (false, col.AllowDBNull, "#18");
398                         Assert.AreEqual (false, col.AutoIncrement, "#19");
399                         Assert.AreEqual (0, col.AutoIncrementSeed, "#20");
400                         Assert.AreEqual (1, col.AutoIncrementStep, "#21");
401                         Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#22");
402                         Assert.AreEqual ("id", col.Caption, "#23");
403                         Assert.AreEqual ("id", col.ColumnName, "#24");
404                         Assert.AreEqual (typeof (int), col.DataType, "#25");
405                         Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#26");
406                         Assert.AreEqual (false, col.DesignMode, "#27");
407                         Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#28");
408                         Assert.AreEqual (-1, col.MaxLength, "#29");
409                         Assert.AreEqual (0, col.Ordinal, "#30");
410                         Assert.AreEqual (string.Empty, col.Prefix, "#31");
411                         Assert.AreEqual ("ParentTable", col.Table.ToString (), "#32");
412                         Assert.AreEqual (true, col.Unique, "#33");
413
414                         //Second Column
415                         col = table.Columns [1];
416                         Assert.AreEqual (true, col.AllowDBNull, "#34");
417                         Assert.AreEqual (false, col.AutoIncrement, "#35");
418                         Assert.AreEqual (0, col.AutoIncrementSeed, "#36");
419                         Assert.AreEqual (1, col.AutoIncrementStep, "#37");
420                         Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#38");
421                         Assert.AreEqual ("ParentItem", col.Caption, "#39");
422                         Assert.AreEqual ("ParentItem", col.ColumnName, "#40");
423                         Assert.AreEqual (typeof (string), col.DataType, "#41");
424                         Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#42");
425                         Assert.AreEqual (false, col.DesignMode, "#43");
426                         Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#44");
427                         Assert.AreEqual (-1, col.MaxLength, "#45");
428                         Assert.AreEqual (1, col.Ordinal, "#46");
429                         Assert.AreEqual (string.Empty, col.Prefix, "#47");
430                         Assert.AreEqual ("ParentTable", col.Table.ToString (), "#48");
431                         Assert.AreEqual (false, col.Unique, "#49");
432
433                         //Third Column
434                         col = table.Columns [2];
435                         Assert.AreEqual (false, col.AllowDBNull, "#50");
436                         Assert.AreEqual (false, col.AutoIncrement, "#51");
437                         Assert.AreEqual (0, col.AutoIncrementSeed, "#52");
438                         Assert.AreEqual (1, col.AutoIncrementStep, "#53");
439                         Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#54");
440                         Assert.AreEqual ("DepartmentID", col.Caption, "#55");
441                         Assert.AreEqual ("DepartmentID", col.ColumnName, "#56");
442                         Assert.AreEqual (typeof (int), col.DataType, "#57");
443                         Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#58");
444                         Assert.AreEqual (false, col.DesignMode, "#59");
445                         Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#60");
446                         Assert.AreEqual (-1, col.MaxLength, "#61");
447                         Assert.AreEqual (2, col.Ordinal, "#62");
448                         Assert.AreEqual (string.Empty, col.Prefix, "#63");
449                         Assert.AreEqual ("ParentTable", col.Table.ToString (), "#64");
450                         Assert.AreEqual (false, col.Unique, "#65");
451
452                         //Test the Xml
453                         Assert.AreEqual (3, table.Rows.Count, "#66");
454                         //Test values of each row
455                         DataRow row = table.Rows [0];
456                         Assert.AreEqual (1, row ["id"], "#67");
457                         Assert.AreEqual ("ParentItem 1", row ["ParentItem"], "#68");
458                         Assert.AreEqual (1, row ["DepartmentID"], "#69");
459
460                         row = table.Rows [1];
461                         Assert.AreEqual (2, row ["id"], "#70");
462                         Assert.AreEqual ("ParentItem 2", row ["ParentItem"], "#71");
463                         Assert.AreEqual (2, row ["DepartmentID"], "#72");
464
465                         row = table.Rows [2];
466                         Assert.AreEqual (3, row ["id"], "#73");
467                         Assert.AreEqual ("ParentItem 3", row ["ParentItem"], "#74");
468                         Assert.AreEqual (3, row ["DepartmentID"], "#75");
469                 }
470
471                 [Test]
472                 public void XmlTest1 ()
473                 {
474                         //Make a table without any relations
475                         MakeParentTable1 ();
476                         dataSet.Tables.Remove (parentTable1);
477
478                         using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
479                                 WriteXmlSerializable (stream, parentTable1);
480                         }
481
482                         DataTable table = new DataTable ("ParentTable");
483                         //Read the Xml and the Schema into a table which does not belongs to any DataSet
484                         ReadXmlSerializable (tempFile, table);
485                         VerifyTableSchema (table, parentTable1.TableName, null);//parentTable1.DataSet);
486                 }
487
488                 [Test]
489                 public void XmlTest2 ()
490                 {
491                         MakeParentTable1 ();
492
493                         using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
494                                 WriteXmlSerializable (stream, parentTable1);
495                         }
496
497                         DataTable table = new DataTable ("ParentTable");
498                         DataSet ds = new DataSet ("XmlDataSet");
499                         ds.Tables.Add (table);
500                         //Read the Xml and the Schema into a table which already belongs to a DataSet
501                         //and the table name matches with the table in the source XML 
502                         ReadXmlSerializable (tempFile, table);
503                         VerifyTableSchema (table, parentTable1.TableName, ds);
504                 }
505
506                 [Test]
507                 public void XmlTest3 ()
508                 {
509                         //Create a parent table and create child tables
510                         MakeParentTable1 ();
511                         MakeChildTable ();
512                         MakeSecondChildTable ();
513                         //Relate the parent and the children
514                         MakeDataRelation ();
515
516                         using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
517                                 WriteXmlSerializable (stream, parentTable1);
518                         }
519
520                         DataTable table = new DataTable ();
521                         ReadXmlSerializable (tempFile, table);
522                         VerifyTableSchema (table, parentTable1.TableName, null);
523                 }
524
525                 [Test]
526                 public void XmlTest4 ()
527                 {
528                         //Create a parent table and create child tables
529                         MakeParentTable1 ();
530                         MakeChildTable ();
531                         MakeSecondChildTable ();
532                         //Relate the parent and the children
533                         MakeDataRelation ();
534
535                         using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
536                                 //WriteXml on any of the children
537                                 WriteXmlSerializable (stream, childTable);
538                         }
539
540                         DataTable table = new DataTable ();
541                         ReadXmlSerializable (tempFile, table);
542
543                         //Test Schema 
544                         //Check Properties of Table
545                         Assert.AreEqual (string.Empty, table.Namespace, "#1");
546                         Assert.IsNull (table.DataSet, "#2");
547                         Assert.AreEqual (3, table.Columns.Count, "#3");
548                         Assert.AreEqual (false, table.CaseSensitive, "#5");
549                         Assert.AreEqual ("ChildTable", table.TableName, "#6");
550                         Assert.AreEqual (string.Empty, table.Prefix, "#7");
551                         Assert.AreEqual (1, table.Constraints.Count, "#8");
552                         Assert.AreEqual ("Constraint1", table.Constraints [0].ToString (), "#9");
553                         Assert.AreEqual (typeof (UniqueConstraint), table.Constraints [0].GetType (), "#10");
554                         Assert.AreEqual (0, table.PrimaryKey.Length, "#11");
555                         Assert.AreEqual (0, table.ParentRelations.Count, "#12");
556                         Assert.AreEqual (0, table.ChildRelations.Count, "#13");
557
558                         //Check properties of each column
559                         //First Column
560                         DataColumn col = table.Columns [0];
561                         Assert.AreEqual (true, col.AllowDBNull, "#14");
562                         Assert.AreEqual (0, col.AutoIncrementSeed, "#15");
563                         Assert.AreEqual (1, col.AutoIncrementStep, "#16");
564                         Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#17");
565                         Assert.AreEqual ("ChildID", col.ColumnName, "#19");
566                         Assert.AreEqual (typeof (int), col.DataType, "#20");
567                         Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#21");
568                         Assert.AreEqual (false, col.DesignMode, "#22");
569                         Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#23");
570                         Assert.AreEqual (-1, col.MaxLength, "#24");
571                         Assert.AreEqual (0, col.Ordinal, "#25");
572                         Assert.AreEqual (string.Empty, col.Prefix, "#26");
573                         Assert.AreEqual ("ChildTable", col.Table.ToString (), "#27");
574                         Assert.AreEqual (true, col.Unique, "#28");
575
576                         //Second Column
577                         col = table.Columns [1];
578                         Assert.AreEqual (true, col.AllowDBNull, "#29");
579                         Assert.AreEqual (0, col.AutoIncrementSeed, "#30");
580                         Assert.AreEqual (1, col.AutoIncrementStep, "#31");
581                         Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#32");
582                         Assert.AreEqual ("ChildItem", col.Caption, "#33");
583                         Assert.AreEqual ("ChildItem", col.ColumnName, "#34");
584                         Assert.AreEqual (typeof (string), col.DataType, "#35");
585                         Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#36");
586                         Assert.AreEqual (false, col.DesignMode, "#37");
587                         Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#38");
588                         Assert.AreEqual (-1, col.MaxLength, "#39");
589                         Assert.AreEqual (1, col.Ordinal, "#40");
590                         Assert.AreEqual (string.Empty, col.Prefix, "#41");
591                         Assert.AreEqual ("ChildTable", col.Table.ToString (), "#42");
592                         Assert.AreEqual (false, col.Unique, "#43");
593
594                         //Third Column
595                         col = table.Columns [2];
596                         Assert.AreEqual (true, col.AllowDBNull, "#44");
597                         Assert.AreEqual (false, col.AutoIncrement, "#45");
598                         Assert.AreEqual (0, col.AutoIncrementSeed, "#46");
599                         Assert.AreEqual (1, col.AutoIncrementStep, "#47");
600                         Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#48");
601                         Assert.AreEqual ("ParentID", col.Caption, "#49");
602                         Assert.AreEqual ("ParentID", col.ColumnName, "#50");
603                         Assert.AreEqual (typeof (int), col.DataType, "#51");
604                         Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#52");
605                         Assert.AreEqual (false, col.DesignMode, "#53");
606                         Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#54");
607                         Assert.AreEqual (-1, col.MaxLength, "#55");
608                         Assert.AreEqual (2, col.Ordinal, "#56");
609                         Assert.AreEqual (string.Empty, col.Prefix, "#57");
610                         Assert.AreEqual ("ChildTable", col.Table.ToString (), "#58");
611                         Assert.AreEqual (false, col.Unique, "#59");
612
613                         //Test the Xml
614                         Assert.AreEqual (6, table.Rows.Count, "#60");
615
616                         //Test values of each row
617                         DataRow row = table.Rows [0];
618                         Assert.AreEqual (1, row ["ChildID"], "#61");
619                         Assert.AreEqual ("ChildItem 1", row ["ChildItem"], "#62");
620                         Assert.AreEqual (1, row ["ParentID"], "#63");
621
622                         row = table.Rows [1];
623                         Assert.AreEqual (2, row ["ChildID"], "#64");
624                         Assert.AreEqual ("ChildItem 2", row ["ChildItem"], "#65");
625                         Assert.AreEqual (1, row ["ParentID"], "#66");
626
627                         row = table.Rows [2];
628                         Assert.AreEqual (5, row ["ChildID"], "#67");
629                         Assert.AreEqual ("ChildItem 1", row ["ChildItem"], "#68");
630                         Assert.AreEqual (2, row ["ParentID"], "#69");
631
632                         row = table.Rows [3];
633                         Assert.AreEqual (6, row ["ChildID"], "#70");
634                         Assert.AreEqual ("ChildItem 2", row ["ChildItem"], "#71");
635                         Assert.AreEqual (2, row ["ParentID"], "#72");
636
637                         row = table.Rows [4];
638                         Assert.AreEqual (10, row ["ChildID"], "#73");
639                         Assert.AreEqual ("ChildItem 1", row ["ChildItem"], "#74");
640                         Assert.AreEqual (3, row ["ParentID"], "#75");
641
642                         row = table.Rows [5];
643                         Assert.AreEqual (11, row ["ChildID"], "#75");
644                         Assert.AreEqual ("ChildItem 2", row ["ChildItem"], "#76");
645                         Assert.AreEqual (3, row ["ParentID"], "#77");
646                 }
647
648                 [Test]
649                 public void XmlTest5 ()
650                 {
651                         MakeParentTable1 ();
652
653                         using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
654                                 WriteXmlSerializable (stream, parentTable1);
655                                 stream.Close ();
656                         }
657
658                         DataTable table = new DataTable ("ParentTable");
659                         DataSet dataSet = new DataSet ("XmlDataSet");
660                         dataSet.Tables.Add (table);
661                         table.Columns.Add (new DataColumn ("id", typeof (string)));
662
663                         using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
664                                 ReadXmlSerializable (stream, table);
665                         }
666
667                         Assert.AreEqual ("ParentTable", table.TableName, "#2");
668                         Assert.AreEqual (3, table.Rows.Count, "#3");
669                         Assert.AreEqual (1, table.Columns.Count, "#4");
670                         Assert.AreEqual (typeof (string), table.Columns [0].DataType, "#5");
671                         Assert.IsNotNull (table.DataSet, "#6");
672
673                         //Check Rows
674                         DataRow row = table.Rows [0];
675                         Assert.AreEqual ("1", row [0], "#7");
676
677                         row = table.Rows [1];
678                         Assert.AreEqual ("2", row [0], "#8");
679
680                         row = table.Rows [2];
681                         Assert.AreEqual ("3", row [0], "#9");
682                 }
683
684                 [Test]
685                 public void XmlTest6 ()
686                 {
687                         MakeParentTable1 ();
688
689                         using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
690                                 WriteXmlSerializable (stream, parentTable1);
691                                 stream.Close ();
692                         }
693
694                         //Create a target table which has nomatching column(s) names
695                         DataTable table = new DataTable ("ParentTable");
696                         DataSet dataSet = new DataSet ("XmlDataSet");
697                         dataSet.Tables.Add (table);
698                         table.Columns.Add (new DataColumn ("sid", typeof (string)));
699
700                         using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
701                                 // ReadXml does not read anything as the column 
702                                 // names are not matching
703                                 ReadXmlSerializable (stream, table);
704                         }
705
706                         Assert.AreEqual ("ParentTable", table.TableName, "#2");
707                         Assert.AreEqual (3, table.Rows.Count, "#3");
708                         Assert.AreEqual (1, table.Columns.Count, "#4");
709                         Assert.AreEqual ("sid", table.Columns [0].ColumnName, "#5");
710                         Assert.AreEqual (typeof (string), table.Columns [0].DataType, "#6");
711                         Assert.IsNotNull (table.DataSet, "#6");
712                 }
713
714                 [Test]
715                 public void XmlTest7 ()
716                 {
717                         MakeParentTable1 ();
718
719                         using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
720                                 WriteXmlSerializable (stream, parentTable1);
721                                 stream.Close ();
722                         }
723
724                         //Create a target table which has matching
725                         // column(s) name and an extra column
726                         DataTable table = new DataTable ("ParentTable");
727                         table.Columns.Add (new DataColumn ("id", typeof (int)));
728                         table.Columns.Add (new DataColumn ("ParentItem", typeof (string)));
729                         table.Columns.Add (new DataColumn ("DepartmentID", typeof (int)));
730                         table.Columns.Add (new DataColumn ("DummyColumn", typeof (string)));
731                         DataSet dataSet = new DataSet ("XmlDataSet");
732                         dataSet.Tables.Add (table);
733
734                         using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
735                                 ReadXmlSerializable (stream, table);
736                         }
737
738                         Assert.AreEqual ("ParentTable", table.TableName, "#2");
739                         Assert.AreEqual (3, table.Rows.Count, "#3");
740                         Assert.AreEqual (4, table.Columns.Count, "#4");
741                         Assert.IsNotNull (table.DataSet, "#6");
742
743                         //Check the Columns
744                         Assert.AreEqual ("id", table.Columns [0].ColumnName, "#6");
745                         Assert.AreEqual (typeof (int), table.Columns [0].DataType, "#7");
746
747                         Assert.AreEqual ("ParentItem", table.Columns [1].ColumnName, "#8");
748                         Assert.AreEqual (typeof (string), table.Columns [1].DataType, "#9");
749
750                         Assert.AreEqual ("DepartmentID", table.Columns [2].ColumnName, "#10");
751                         Assert.AreEqual (typeof (int), table.Columns [2].DataType, "#11");
752
753                         Assert.AreEqual ("DummyColumn", table.Columns [3].ColumnName, "#12");
754                         Assert.AreEqual (typeof (string), table.Columns [3].DataType, "#13");
755
756                         //Check the rows
757                         DataRow row = table.Rows [0];
758                         Assert.AreEqual (1, row ["id"], "#14");
759                         Assert.AreEqual ("ParentItem 1", row ["ParentItem"], "#15");
760                         Assert.AreEqual (1, row ["DepartmentID"], "#16");
761
762                         row = table.Rows [1];
763                         Assert.AreEqual (2, row ["id"], "#18");
764                         Assert.AreEqual ("ParentItem 2", row ["ParentItem"], "#19");
765                         Assert.AreEqual (2, row ["DepartmentID"], "#20");
766
767                         row = table.Rows [2];
768                         Assert.AreEqual (3, row ["id"], "#22");
769                         Assert.AreEqual ("ParentItem 3", row ["ParentItem"], "#23");
770                         Assert.AreEqual (3, row ["DepartmentID"], "#24");
771                 }
772
773                 [Test]
774                 public void XmlTest8 ()
775                 {
776                         MakeParentTable1 ();
777
778                         using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
779                                 WriteXmlSerializable (stream, parentTable1);
780                         }
781
782                         DataTable table = new DataTable ("ParentTable");
783                         DataSet dataSet = new DataSet ("XmlDataSet");
784                         dataSet.Tables.Add (table);
785                         table.Columns.Add (new DataColumn ("id", typeof (int)));
786                         table.Columns.Add (new DataColumn ("DepartmentID", typeof (int)));
787
788                         using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
789                                 ReadXmlSerializable (stream, table);
790                         }
791
792                         Assert.AreEqual ("ParentTable", table.TableName, "#2");
793                         Assert.AreEqual (3, table.Rows.Count, "#3");
794                         Assert.AreEqual (2, table.Columns.Count, "#4");
795                         Assert.AreEqual (typeof (int), table.Columns [0].DataType, "#5");
796                         Assert.AreEqual (typeof (int), table.Columns [1].DataType, "#6");
797                         Assert.IsNotNull (table.DataSet, "#6");
798
799                         //Check rows
800                         DataRow row = table.Rows [0];
801                         Assert.AreEqual (1, row [0], "#7");
802                         Assert.AreEqual (1, row [1], "#8");
803
804                         row = table.Rows [1];
805                         Assert.AreEqual (2, row [0], "#9");
806                         Assert.AreEqual (2, row [1], "#10");
807
808                         row = table.Rows [2];
809                         Assert.AreEqual (3, row [0], "#11");
810                         Assert.AreEqual (3, row [1], "#12");
811                 }
812
813                 [Test]
814                 public void XmlTest9 ()
815                 {
816                         MakeParentTable1 ();
817
818                         using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
819                                 WriteXmlSerializable (stream, parentTable1);
820                         }
821
822                         DataSet ds = new DataSet ();
823                         DataTable table = new DataTable ("ParentTable");
824                         table.Columns.Add (new DataColumn ("id", typeof (int)));
825                         ds.Tables.Add (table);
826
827                         using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
828                                 ReadXmlSerializable (stream, table);
829                         }
830
831                         Assert.AreEqual ("ParentTable", table.TableName, "#2");
832                         Assert.AreEqual (3, table.Rows.Count, "#3");
833                         Assert.AreEqual (1, table.Columns.Count, "#4");
834                         Assert.AreEqual (typeof (int), table.Columns [0].DataType, "#5");
835                         Assert.AreEqual ("System.Data.DataSet", table.DataSet.ToString (), "#6");
836                         Assert.AreEqual ("NewDataSet", table.DataSet.DataSetName, "#7");
837
838                         //Check the rows
839                         DataRow row = table.Rows [0];
840                         Assert.AreEqual (1, row [0], "#8");
841
842                         row = table.Rows [1];
843                         Assert.AreEqual (2, row [0], "#9");
844
845                         row = table.Rows [2];
846                         Assert.AreEqual (3, row [0], "#10");
847                 }
848
849                 [Test]
850                 public void XmlTest10 ()
851                 {
852                         MakeParentTable1 ();
853
854                         using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
855                                 WriteXmlSerializable (stream, parentTable1);
856                         }
857
858                         DataSet ds = new DataSet ();
859                         DataTable table = new DataTable ("ParentTable");
860                         table.Columns.Add (new DataColumn ("id", typeof (int)));
861                         table.Columns.Add (new DataColumn ("DepartmentID", typeof (string)));
862                         ds.Tables.Add (table);
863
864                         using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
865                                 ReadXmlSerializable (stream, table);
866                         }
867
868                         Assert.AreEqual ("ParentTable", table.TableName, "#2");
869                         Assert.AreEqual ("NewDataSet", table.DataSet.DataSetName, "#3");
870                         Assert.AreEqual (3, table.Rows.Count, "#4");
871                         Assert.AreEqual (2, table.Columns.Count, "#5");
872                         Assert.AreEqual (typeof (int), table.Columns [0].DataType, "#6");
873                         Assert.AreEqual (typeof (string), table.Columns [1].DataType, "#7");
874
875                         //Check rows
876                         DataRow row = table.Rows [0];
877                         Assert.AreEqual (1, row [0], "#8");
878                         Assert.AreEqual ("1", row [1], "#9");
879
880                         row = table.Rows [1];
881                         Assert.AreEqual (2, row [0], "#10");
882                         Assert.AreEqual ("2", row [1], "#11");
883
884                         row = table.Rows [2];
885                         Assert.AreEqual (3, row [0], "#12");
886                         Assert.AreEqual ("3", row [1], "#13");
887                 }
888                 
889                 [Test]
890                 public void XmlTest11 ()
891                 {
892                         MakeDummyTable ();
893
894                         using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
895                                 WriteXmlSerializable (stream, dummyTable);
896                         }
897
898                         //Create a table and set the table name
899                         DataTable table = new DataTable ("DummyTable");
900                         //define the table schame partially
901                         table.Columns.Add (new DataColumn ("DummyItem", typeof (string)));
902
903                         using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
904                                 ReadXmlSerializable (stream, table);
905                         }
906
907                         Assert.IsNull (table.DataSet, "#2");
908                         Assert.AreEqual (1, table.Columns.Count, "#3");
909                         Assert.AreEqual (typeof (string), table.Columns [0].DataType, "#4");
910                         Assert.AreEqual (3, table.Rows.Count, "#5");
911
912                         //Check Rows
913                         DataRow row = table.Rows [0];
914                         Assert.AreEqual ("DummyItem 1", row [0], "#1");
915                         Assert.AreEqual (DataRowState.Unchanged, row.RowState, "#2");
916
917                         row = table.Rows [1];
918                         Assert.AreEqual ("Changed_DummyItem 2", row [0], "#3");
919                         Assert.AreEqual (DataRowState.Modified, row.RowState, "#4");
920
921                         row = table.Rows [2];
922                         Assert.AreEqual ("DummyItem 3", row [0], "#5");
923                         Assert.AreEqual (DataRowState.Unchanged, row.RowState, "#6");
924                 }
925
926                 [Test]
927                 [Category("NotWorking")]
928                 public void XmlTest12 ()
929                 {
930                         MakeDummyTable ();
931
932                         using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
933                                 WriteXmlSerializable (stream, dummyTable);
934                         }
935
936                         //Create a table and set the table name
937                         DataTable table = new DataTable ("DummyTable");
938                         //define the table and add an extra column in the table
939                         table.Columns.Add (new DataColumn ("id", typeof (int)));
940                         table.Columns.Add (new DataColumn ("DummyItem", typeof (string)));
941                         //Add an extra column which does not match any column in the source diffram
942                         table.Columns.Add (new DataColumn ("ExtraColumn", typeof (double)));
943
944                         using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
945                                 ReadXmlSerializable (stream, table);
946                         }
947
948                         Assert.IsNull (table.DataSet, "#2");
949                         Assert.AreEqual (3, table.Columns.Count, "#3");
950                         Assert.AreEqual (typeof (int), table.Columns [0].DataType, "#4");
951                         Assert.AreEqual (typeof (string), table.Columns [1].DataType, "#5");
952                         Assert.AreEqual (typeof (double), table.Columns [2].DataType, "#6");
953                         Assert.AreEqual (3, table.Rows.Count, "#7");
954
955                         //Check Rows
956                         DataRow row = table.Rows [0];
957                         Assert.AreEqual (1, row [0], "#8");
958                         Assert.AreEqual ("DummyItem 1", row [1], "#9");
959                         Assert.AreSame (DBNull.Value, row [2], "#10");
960                         Assert.AreEqual (DataRowState.Unchanged, row.RowState, "#11");
961
962                         row = table.Rows [1];
963                         Assert.AreEqual (2, row [0], "#12");
964                         Assert.AreEqual ("Changed_DummyItem 2", row [1], "#13");
965                         Assert.AreSame (DBNull.Value, row [2], "#14");
966                         Assert.AreEqual (DataRowState.Modified, row.RowState, "#15");
967
968                         row = table.Rows [2];
969                         Assert.AreEqual (3, row [0], "#16");
970                         Assert.AreEqual ("DummyItem 3", row [1], "#17");
971                         Assert.AreSame (DBNull.Value, row [2], "#18");
972                         Assert.AreEqual (DataRowState.Unchanged, row.RowState, "#19");
973                 }
974
975                 [Test]
976                 [Category ("NotWorking")]
977                 public void XmlTest13 ()
978                 {
979                         MakeDummyTable ();
980
981                         using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
982                                 WriteXmlSerializable (stream, dummyTable);
983                         }
984
985                         //Create a table and set the table name
986                         DataTable table = new DataTable ("DummyTable");
987                         //define the table schame partially with a column name which does not match with any
988                         //table columns in the diffgram
989                         table.Columns.Add (new DataColumn ("WrongColumnName", typeof (string)));
990
991                         using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
992                                 ReadXmlSerializable (stream, table);
993                         }
994
995                         Assert.IsNull (table.DataSet, "#2");
996                         Assert.AreEqual ("DummyTable", table.TableName, "#3");
997                         Assert.AreEqual (1, table.Columns.Count, "#4");
998                         Assert.AreEqual (typeof (string), table.Columns [0].DataType, "#5");
999
1000                         Assert.AreEqual (3, table.Rows.Count, "#6");
1001                         foreach (DataRow row in table.Rows)
1002                                 Assert.AreSame (DBNull.Value, row [0], "#7");
1003                 }
1004
1005                 [Test]
1006                 public void XmlTest14 ()
1007                 {
1008                         MakeParentTable1 ();
1009                         MakeChildTable ();
1010                         MakeSecondChildTable ();
1011                         MakeDataRelation ();
1012
1013                         using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
1014                                 WriteXmlSerializable (stream, parentTable1);
1015                         }
1016
1017                         DataTable table1 = new DataTable ("ParentTable");
1018                         table1.Columns.Add (new DataColumn (parentTable1.Columns [0].ColumnName, typeof (int)));
1019                         table1.Columns.Add (new DataColumn (parentTable1.Columns [1].ColumnName, typeof (string)));
1020                         table1.Columns.Add (new DataColumn (parentTable1.Columns [2].ColumnName, typeof (int)));
1021
1022                         ReadXmlSerializable (tempFile, table1);
1023
1024                         Assert.IsNull (table1.DataSet, "#2");
1025                         Assert.AreEqual ("ParentTable", table1.TableName, "#3");
1026                         Assert.AreEqual (3, table1.Columns.Count, "#4");
1027                         Assert.AreEqual (typeof (int), table1.Columns [0].DataType, "#5");
1028                         Assert.AreEqual (typeof (string), table1.Columns [1].DataType, "#6");
1029                         Assert.AreEqual (typeof (int), table1.Columns [2].DataType, "#7");
1030                         Assert.AreEqual (0, table1.ChildRelations.Count, "#8");
1031
1032                         Assert.AreEqual (3, table1.Rows.Count, "#9");
1033                         //Check the row
1034                         DataRow row = table1.Rows [0];
1035                         Assert.AreEqual (1, row [0], "#10");
1036                         Assert.AreEqual ("ParentItem 1", row [1], "#11");
1037                         Assert.AreEqual (1, row [2], "#12");
1038
1039                         row = table1.Rows [1];
1040                         Assert.AreEqual (2, row [0], "#13");
1041                         Assert.AreEqual ("ParentItem 2", row [1], "#14");
1042                         Assert.AreEqual (2, row [2], "#15");
1043
1044                         row = table1.Rows [2];
1045                         Assert.AreEqual (3, row [0], "#16");
1046                         Assert.AreEqual ("ParentItem 3", row [1], "#17");
1047                         Assert.AreEqual (3, row [2], "#18");
1048                 }
1049
1050                 [Test]
1051                 public void XmlTest15 ()
1052                 {
1053                         MakeDummyTable ();
1054
1055                         using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
1056                                 WriteXmlSerializable (stream, dummyTable);
1057                         }
1058
1059                         Assert.AreEqual (3, dummyTable.Rows.Count, "#4b");
1060
1061                         DataSet dataSet = new DataSet ("HelloWorldDataSet");
1062                         DataTable table = new DataTable ("DummyTable");
1063                         table.Columns.Add (new DataColumn ("DummyItem", typeof (string)));
1064                         dataSet.Tables.Add (table);
1065
1066                         //Call ReadXml on a table which belong to a DataSet
1067                         ReadXmlSerializable (tempFile, table);
1068
1069                         Assert.AreEqual ("HelloWorldDataSet", table.DataSet.DataSetName, "#1");
1070                         Assert.AreEqual (1, table.Columns.Count, "#2");
1071                         Assert.AreEqual (typeof (string), table.Columns [0].DataType, "#3");
1072                         Assert.AreEqual (3, table.Rows.Count, "#4");
1073
1074                         //Check Rows
1075                         DataRow row = table.Rows [0];
1076                         Assert.AreEqual ("DummyItem 1", row [0], "#5");
1077                         Assert.AreEqual (DataRowState.Unchanged, row.RowState, "#6");
1078
1079                         row = table.Rows [1];
1080                         Assert.AreEqual ("Changed_DummyItem 2", row [0], "#7");
1081                         Assert.AreEqual (DataRowState.Modified, row.RowState, "#8");
1082
1083                         row = table.Rows [2];
1084                         Assert.AreEqual ("DummyItem 3", row [0], "#9");
1085                         Assert.AreEqual (DataRowState.Unchanged, row.RowState, "#10");
1086                 }
1087
1088                 [Test]
1089                 public void XmlTest16 ()
1090                 {
1091                         DataSet ds = new DataSet ();
1092                         DataTable parent = new DataTable ("Parent");
1093                         parent.Columns.Add (new DataColumn ("col1", typeof (int)));
1094                         parent.Columns.Add (new DataColumn ("col2", typeof (string)));
1095                         parent.Columns [0].Unique = true;
1096
1097                         DataTable child1 = new DataTable ("Child1");
1098                         child1.Columns.Add (new DataColumn ("col3", typeof (int)));
1099                         child1.Columns.Add (new DataColumn ("col4", typeof (string)));
1100                         child1.Columns.Add (new DataColumn ("col5", typeof (int)));
1101                         child1.Columns [2].Unique = true;
1102
1103                         DataTable child2 = new DataTable ("Child2");
1104                         child2.Columns.Add (new DataColumn ("col6", typeof (int)));
1105                         child2.Columns.Add (new DataColumn ("col7"));
1106
1107                         parent.Rows.Add (new object [] { 1, "P_" });
1108                         parent.Rows.Add (new object [] { 2, "P_" });
1109
1110                         child1.Rows.Add (new object [] { 1, "C1_", 3 });
1111                         child1.Rows.Add (new object [] { 1, "C1_", 4 });
1112                         child1.Rows.Add (new object [] { 2, "C1_", 5 });
1113                         child1.Rows.Add (new object [] { 2, "C1_", 6 });
1114
1115                         child2.Rows.Add (new object [] { 3, "C2_" });
1116                         child2.Rows.Add (new object [] { 3, "C2_" });
1117                         child2.Rows.Add (new object [] { 4, "C2_" });
1118                         child2.Rows.Add (new object [] { 4, "C2_" });
1119                         child2.Rows.Add (new object [] { 5, "C2_" });
1120                         child2.Rows.Add (new object [] { 5, "C2_" });
1121                         child2.Rows.Add (new object [] { 6, "C2_" });
1122                         child2.Rows.Add (new object [] { 6, "C2_" });
1123
1124                         ds.Tables.Add (parent);
1125                         ds.Tables.Add (child1);
1126                         ds.Tables.Add (child2);
1127
1128                         DataRelation relation = new DataRelation ("Relation1", parent.Columns [0], child1.Columns [0]);
1129                         parent.ChildRelations.Add (relation);
1130
1131                         relation = new DataRelation ("Relation2", child1.Columns [2], child2.Columns [0]);
1132                         child1.ChildRelations.Add (relation);
1133
1134                         using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
1135                                 WriteXmlSerializable (stream, parent);
1136                         }
1137
1138                         DataTable table = new DataTable ();
1139                         ReadXmlSerializable (tempFile, table);
1140
1141                         Assert.AreEqual ("Parent", table.TableName, "#1");
1142                         Assert.AreEqual (2, table.Columns.Count, "#3");
1143                         Assert.AreEqual (2, table.Rows.Count, "#4");
1144                         Assert.AreEqual (typeof (int), table.Columns [0].DataType, "#5");
1145                         Assert.AreEqual (typeof (string), table.Columns [1].DataType, "#6");
1146                         Assert.AreEqual (1, table.Constraints.Count, "#7");
1147                         Assert.AreEqual (typeof (UniqueConstraint), table.Constraints [0].GetType (), "#8");
1148                 }
1149         }
1150 }