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