2 // Nagappan A <anagappan@novell.com>
4 // Copyright (c) 2007 Novell, Inc
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:
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
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.
32 using NUnit.Framework;
34 namespace Monotests_System.Data
37 public class DataTableTest3
41 DataTable parentTable;
43 DataTable secondChildTable;
48 tempFile = Path.GetTempFileName ();
52 public void TearDown ()
55 File.Delete (tempFile);
58 private void MakeParentTable ()
61 parentTable = new DataTable ("ParentTable");
62 dataSet = new DataSet ("XmlSchemaDataSet");
66 // Create new DataColumn, set DataType,
67 // ColumnName and add to Table.
68 column = new DataColumn ();
69 column.DataType = typeof (int);
70 column.ColumnName = "id";
72 // Add the Column to the DataColumnCollection.
73 parentTable.Columns.Add (column);
75 // Create second column
76 column = new DataColumn ();
77 column.DataType = typeof (string);
78 column.ColumnName = "ParentItem";
79 column.AutoIncrement = false;
80 column.Caption = "ParentItem";
81 column.Unique = false;
82 // Add the column to the table
83 parentTable.Columns.Add (column);
85 // Create third column.
86 column = new DataColumn ();
87 column.DataType = typeof (int);
88 column.ColumnName = "DepartmentID";
89 column.Caption = "DepartmentID";
90 // Add the column to the table.
91 parentTable.Columns.Add (column);
93 // Make the ID column the primary key column.
94 DataColumn [] PrimaryKeyColumns = new DataColumn [2];
95 PrimaryKeyColumns [0] = parentTable.Columns ["id"];
96 PrimaryKeyColumns [1] = parentTable.Columns ["DepartmentID"];
97 parentTable.PrimaryKey = PrimaryKeyColumns;
99 dataSet.Tables.Add (parentTable);
101 // Create three new DataRow objects and add
102 // them to the DataTable
103 for (int i = 0; i <= 2; i++) {
104 row = parentTable.NewRow ();
106 row ["ParentItem"] = "ParentItem " + (i + 1);
107 row ["DepartmentID"] = i + 1;
108 parentTable.Rows.Add (row);
112 private void MakeChildTable ()
114 // Create a new Table
115 childTable = new DataTable ("ChildTable");
119 // Create first column and add to the DataTable.
120 column = new DataColumn ();
121 column.DataType= typeof (int);
122 column.ColumnName = "ChildID";
123 column.AutoIncrement = true;
124 column.Caption = "ID";
125 column.Unique = true;
127 // Add the column to the DataColumnCollection
128 childTable.Columns.Add (column);
130 // Create second column
131 column = new DataColumn ();
132 column.DataType= typeof (string);
133 column.ColumnName = "ChildItem";
134 column.AutoIncrement = false;
135 column.Caption = "ChildItem";
136 column.Unique = false;
137 childTable.Columns.Add (column);
139 //Create third column
140 column = new DataColumn ();
141 column.DataType= typeof (int);
142 column.ColumnName = "ParentID";
143 column.AutoIncrement = false;
144 column.Caption = "ParentID";
145 column.Unique = false;
146 childTable.Columns.Add (column);
148 dataSet.Tables.Add (childTable);
150 // Create three sets of DataRow objects,
151 // five rows each, and add to DataTable.
152 for (int i = 0; i <= 1; i ++) {
153 row = childTable.NewRow ();
154 row ["childID"] = i + 1;
155 row ["ChildItem"] = "ChildItem " + (i + 1);
156 row ["ParentID"] = 1 ;
157 childTable.Rows.Add (row);
160 for (int i = 0; i <= 1; i ++) {
161 row = childTable.NewRow ();
162 row ["childID"] = i + 5;
163 row ["ChildItem"] = "ChildItem " + (i + 1);
164 row ["ParentID"] = 2 ;
165 childTable.Rows.Add (row);
168 for (int i = 0; i <= 1; i ++) {
169 row = childTable.NewRow ();
170 row ["childID"] = i + 10;
171 row ["ChildItem"] = "ChildItem " + (i + 1);
172 row ["ParentID"] = 3 ;
173 childTable.Rows.Add (row);
177 private void MakeSecondChildTable ()
179 // Create a new Table
180 secondChildTable = new DataTable ("SecondChildTable");
184 // Create first column and add to the DataTable.
185 column = new DataColumn ();
186 column.DataType= typeof (int);
187 column.ColumnName = "ChildID";
188 column.AutoIncrement = true;
189 column.Caption = "ID";
190 column.ReadOnly = true;
191 column.Unique = true;
193 // Add the column to the DataColumnCollection.
194 secondChildTable.Columns.Add (column);
196 // Create second column.
197 column = new DataColumn ();
198 column.DataType= typeof (string);
199 column.ColumnName = "ChildItem";
200 column.AutoIncrement = false;
201 column.Caption = "ChildItem";
202 column.ReadOnly = false;
203 column.Unique = false;
204 secondChildTable.Columns.Add (column);
206 //Create third column.
207 column = new DataColumn ();
208 column.DataType= typeof (int);
209 column.ColumnName = "ParentID";
210 column.AutoIncrement = false;
211 column.Caption = "ParentID";
212 column.ReadOnly = false;
213 column.Unique = false;
214 secondChildTable.Columns.Add (column);
216 //Create fourth column.
217 column = new DataColumn ();
218 column.DataType= typeof (int);
219 column.ColumnName = "DepartmentID";
220 column.Caption = "DepartmentID";
221 column.Unique = false;
222 secondChildTable.Columns.Add (column);
224 dataSet.Tables.Add (secondChildTable);
226 // Create three sets of DataRow objects,
227 // five rows each, and add to DataTable.
228 for (int i = 0; i <= 1; i++) {
229 row = secondChildTable.NewRow ();
230 row ["childID"] = i + 1;
231 row ["ChildItem"] = "SecondChildItem " + (i + 1);
232 row ["ParentID"] = 1 ;
233 row ["DepartmentID"] = 1;
234 secondChildTable.Rows.Add (row);
237 for (int i = 0;i <= 1;i++) {
238 row = secondChildTable.NewRow ();
239 row ["childID"] = i + 5;
240 row ["ChildItem"] = "SecondChildItem " + (i + 1);
241 row ["ParentID"] = 2;
242 row ["DepartmentID"] = 2;
243 secondChildTable.Rows.Add (row);
246 for (int i = 0;i <= 1;i++) {
247 row = secondChildTable.NewRow ();
248 row ["childID"] = i + 10;
249 row ["ChildItem"] = "SecondChildItem " + (i + 1);
250 row ["ParentID"] = 3 ;
251 row ["DepartmentID"] = 3;
252 secondChildTable.Rows.Add (row);
256 private void MakeDataRelation ()
258 DataColumn parentColumn = dataSet.Tables ["ParentTable"].Columns ["id"];
259 DataColumn childColumn = dataSet.Tables ["ChildTable"].Columns ["ParentID"];
260 DataRelation relation = new DataRelation ("ParentChild_Relation1", parentColumn, childColumn);
261 dataSet.Tables ["ChildTable"].ParentRelations.Add (relation);
263 DataColumn [] parentColumn1 = new DataColumn [2];
264 DataColumn [] childColumn1 = new DataColumn [2];
266 parentColumn1 [0] = dataSet.Tables ["ParentTable"].Columns ["id"];
267 parentColumn1 [1] = dataSet.Tables ["ParentTable"].Columns ["DepartmentID"];
269 childColumn1 [0] = dataSet.Tables ["SecondChildTable"].Columns ["ParentID"];
270 childColumn1 [1] = dataSet.Tables ["SecondChildTable"].Columns ["DepartmentID"];
272 DataRelation secondRelation = new DataRelation("ParentChild_Relation2", parentColumn1, childColumn1);
273 dataSet.Tables ["SecondChildTable"].ParentRelations.Add (secondRelation);
276 //Test properties of a table which does not belongs to a DataSet
277 private void VerifyTableSchema (DataTable table, string tableName, DataSet ds)
279 //Check Properties of Table
280 Assert.AreEqual ("", table.Namespace, "#1");
281 Assert.AreEqual (ds, table.DataSet, "#2");
282 Assert.AreEqual (3, table.Columns.Count, "#3");
283 Assert.AreEqual (0, table.Rows.Count, "#4");
284 Assert.AreEqual (false, table.CaseSensitive, "#5");
285 Assert.AreEqual (tableName, table.TableName, "#6");
286 Assert.AreEqual (2, table.Constraints.Count, "#7");
287 Assert.AreEqual ("", table.Prefix, "#8");
288 Assert.AreEqual ("Constraint1", table.Constraints [0].ToString (), "#9");
289 Assert.AreEqual ("Constraint2", table.Constraints [1].ToString (), "#10");
290 Assert.AreEqual (typeof (UniqueConstraint), table.Constraints [0].GetType (), "#11");
291 Assert.AreEqual (typeof (UniqueConstraint), table.Constraints [1].GetType (), "#12");
292 Assert.AreEqual (2, table.PrimaryKey.Length, "#13");
293 Assert.AreEqual ("id", table.PrimaryKey [0].ToString (), "#14");
294 Assert.AreEqual ("DepartmentID", table.PrimaryKey [1].ToString (), "#15");
296 Assert.AreEqual (0, table.ParentRelations.Count, "#16");
297 Assert.AreEqual (0, table.ChildRelations.Count, "#17");
299 //Check properties of each column
301 DataColumn col = table.Columns [0];
302 Assert.AreEqual (false, col.AllowDBNull, "#18");
303 Assert.AreEqual (false, col.AutoIncrement, "#19");
304 Assert.AreEqual (0, col.AutoIncrementSeed, "#20");
305 Assert.AreEqual (1, col.AutoIncrementStep, "#21");
306 Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#22");
307 Assert.AreEqual ("id", col.Caption, "#23");
308 Assert.AreEqual ("id", col.ColumnName, "#24");
309 Assert.AreEqual (typeof (int), col.DataType, "#25");
310 Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#26");
311 Assert.AreEqual (false, col.DesignMode, "#27");
312 Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#28");
313 Assert.AreEqual (-1, col.MaxLength, "#29");
314 Assert.AreEqual (0, col.Ordinal, "#30");
315 Assert.AreEqual (string.Empty, col.Prefix, "#31");
316 Assert.AreEqual (tableName, col.Table.ToString (), "#32");
317 Assert.AreEqual (true, col.Unique, "#33");
320 col = table.Columns [1];
321 Assert.AreEqual (true, col.AllowDBNull, "#34");
322 Assert.AreEqual (false, col.AutoIncrement, "#35");
323 Assert.AreEqual (0, col.AutoIncrementSeed, "#36");
324 Assert.AreEqual (1, col.AutoIncrementStep, "#37");
325 Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#38");
326 Assert.AreEqual ("ParentItem", col.Caption, "#39");
327 Assert.AreEqual ("ParentItem", col.ColumnName, "#40");
328 Assert.AreEqual (typeof (string), col.DataType, "#41");
329 Assert.AreEqual ("", col.DefaultValue.ToString (), "#42");
330 Assert.AreEqual (false, col.DesignMode, "#43");
331 Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#44");
332 Assert.AreEqual (-1, col.MaxLength, "#45");
333 Assert.AreEqual (1, col.Ordinal, "#46");
334 Assert.AreEqual ("", col.Prefix, "#47");
335 Assert.AreEqual (tableName, col.Table.ToString (), "#48");
336 Assert.AreEqual (false, col.Unique, "#49");
339 col = table.Columns [2];
340 Assert.AreEqual (false, col.AllowDBNull, "#50");
341 Assert.AreEqual (false, col.AutoIncrement, "#51");
342 Assert.AreEqual (0, col.AutoIncrementSeed, "#52");
343 Assert.AreEqual (1, col.AutoIncrementStep, "#53");
344 Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#54");
345 Assert.AreEqual ("DepartmentID", col.Caption, "#55");
346 Assert.AreEqual ("DepartmentID", col.ColumnName, "#56");
347 Assert.AreEqual (typeof (int), col.DataType, "#57");
348 Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#58");
349 Assert.AreEqual (false, col.DesignMode, "#59");
350 Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#60");
351 Assert.AreEqual (-1, col.MaxLength, "#61");
352 Assert.AreEqual (2, col.Ordinal, "#62");
353 Assert.AreEqual ("", col.Prefix, "#63");
354 Assert.AreEqual (tableName, col.Table.ToString (), "#64");
355 Assert.AreEqual (false, col.Unique, "#65");
358 private void VerifyParentTableSchema (DataTable table, string tableName, DataSet ds)
360 //Check Properties of Table
361 Assert.AreEqual (string.Empty, table.Namespace, "#1");
362 Assert.AreEqual (ds.DataSetName, table.DataSet.DataSetName, "#2");
363 Assert.AreEqual (3, table.Columns.Count, "#3");
364 Assert.AreEqual (0, table.Rows.Count, "#4");
365 Assert.AreEqual (false, table.CaseSensitive, "#5");
366 Assert.AreEqual ("ParentTable", table.TableName, "#6");
367 Assert.AreEqual (2, table.Constraints.Count, "#7");
368 Assert.AreEqual (string.Empty, table.Prefix, "#8");
371 Assert.AreEqual ("Constraint1", table.Constraints [0].ToString (), "#9");
372 Assert.AreEqual ("Constraint2", table.Constraints [1].ToString (), "#10");
373 Assert.AreEqual (typeof (UniqueConstraint), table.Constraints [0].GetType (), "#11");
374 Assert.AreEqual (typeof (UniqueConstraint), table.Constraints [1].GetType (), "#12");
375 Assert.AreEqual (2, table.PrimaryKey.Length, "#13");
376 Assert.AreEqual ("id", table.PrimaryKey [0].ToString (), "#14");
377 Assert.AreEqual ("DepartmentID", table.PrimaryKey [1].ToString (), "#15");
379 //Check Relations of the ParentTable
380 Assert.AreEqual (0, table.ParentRelations.Count, "#16");
381 Assert.AreEqual (2, table.ChildRelations.Count, "#17");
382 Assert.AreEqual ("ParentChild_Relation1", table.ChildRelations [0].ToString (), "#18");
383 Assert.AreEqual ("ParentChild_Relation2", table.ChildRelations [1].ToString (), "#19");
384 Assert.AreEqual ("ChildTable", table.ChildRelations [0].ChildTable.TableName, "#20");
385 Assert.AreEqual ("SecondChildTable", table.ChildRelations [1].ChildTable.TableName, "#21");
387 Assert.AreEqual (1, table.ChildRelations [0].ParentColumns.Length, "#22");
388 Assert.AreEqual ("id", table.ChildRelations [0].ParentColumns [0].ColumnName, "#23");
389 Assert.AreEqual (1, table.ChildRelations [0].ChildColumns.Length, "#24");
390 Assert.AreEqual ("ParentID", table.ChildRelations [0].ChildColumns [0].ColumnName, "#25");
392 Assert.AreEqual (2, table.ChildRelations [1].ParentColumns.Length, "#26");
393 Assert.AreEqual ("id", table.ChildRelations [1].ParentColumns [0].ColumnName, "#27");
394 Assert.AreEqual ("DepartmentID", table.ChildRelations [1].ParentColumns [1].ColumnName, "#28");
395 Assert.AreEqual (2, table.ChildRelations [1].ChildColumns.Length, "#29");
397 Assert.AreEqual ("ParentID", table.ChildRelations [1].ChildColumns [0].ColumnName, "#30");
398 Assert.AreEqual ("DepartmentID", table.ChildRelations [1].ChildColumns [1].ColumnName, "#31");
400 //Check properties of each column
402 DataColumn col = table.Columns [0];
403 Assert.AreEqual (false, col.AllowDBNull, "#32");
404 Assert.AreEqual (false, col.AutoIncrement, "#33");
405 Assert.AreEqual (0, col.AutoIncrementSeed, "#34");
406 Assert.AreEqual (1, col.AutoIncrementStep, "#35");
407 Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#36");
408 Assert.AreEqual ("id", col.Caption, "#37");
409 Assert.AreEqual ("id", col.ColumnName, "#38");
410 Assert.AreEqual (typeof (int), col.DataType, "#39");
411 Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#40");
412 Assert.AreEqual (false, col.DesignMode, "#41");
413 Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#42");
414 Assert.AreEqual (-1, col.MaxLength, "#43");
415 Assert.AreEqual (0, col.Ordinal, "#44");
416 Assert.AreEqual (string.Empty, col.Prefix, "#45");
417 Assert.AreEqual ("ParentTable", col.Table.ToString (), "#46");
418 Assert.AreEqual (true, col.Unique, "#47");
421 col = table.Columns [1];
422 Assert.AreEqual (true, col.AllowDBNull, "#48");
423 Assert.AreEqual (false, col.AutoIncrement, "#49");
424 Assert.AreEqual (0, col.AutoIncrementSeed, "#50");
425 Assert.AreEqual (1, col.AutoIncrementStep, "#51");
426 Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#52");
427 Assert.AreEqual ("ParentItem", col.Caption, "#53");
428 Assert.AreEqual ("ParentItem", col.ColumnName, "#54");
429 Assert.AreEqual (typeof (string), col.DataType, "#55");
430 Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#56");
431 Assert.AreEqual (false, col.DesignMode, "#57");
432 Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#58");
433 Assert.AreEqual (-1, col.MaxLength, "#59");
434 Assert.AreEqual (1, col.Ordinal, "#60");
435 Assert.AreEqual (string.Empty, col.Prefix, "#61");
436 Assert.AreEqual ("ParentTable", col.Table.ToString (), "#62");
437 Assert.AreEqual (false, col.Unique, "#63");
440 col = table.Columns [2];
441 Assert.AreEqual (false, col.AllowDBNull, "#64");
442 Assert.AreEqual (false, col.AutoIncrement, "#65");
443 Assert.AreEqual (0, col.AutoIncrementSeed, "#66");
444 Assert.AreEqual (1, col.AutoIncrementStep, "#67");
445 Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#68");
446 Assert.AreEqual ("DepartmentID", col.Caption, "#69");
447 Assert.AreEqual ("DepartmentID", col.ColumnName, "#70");
448 Assert.AreEqual (typeof (int), col.DataType, "#71");
449 Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#72");
450 Assert.AreEqual (false, col.DesignMode, "#73");
451 Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#74");
452 Assert.AreEqual (-1, col.MaxLength, "#75");
453 Assert.AreEqual (2, col.Ordinal, "#76");
454 Assert.AreEqual (string.Empty, col.Prefix, "#77");
455 Assert.AreEqual ("ParentTable", col.Table.ToString (), "#78");
456 Assert.AreEqual (false, col.Unique, "#79");
461 public void XmlSchemaTest1 ()
465 //Detach the table from the DataSet
466 dataSet.Tables.Remove (parentTable);
469 using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
470 parentTable.WriteXmlSchema (stream);
474 DataTable table = new DataTable ();
475 using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
476 table.ReadXmlSchema (stream);
479 VerifyTableSchema (table, parentTable.TableName, parentTable.DataSet);
483 public void XmlSchemaTest2 ()
487 dataSet.Tables.Remove (parentTable);
488 parentTable.TableName = String.Empty;
490 using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
492 parentTable.WriteXmlSchema (stream);
494 } catch (InvalidOperationException ex) {
495 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
496 Assert.IsNull (ex.InnerException, "#3");
497 Assert.IsNotNull (ex.Message, "#4");
503 public void XmlSchemaTest3 ()
508 using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
509 parentTable.WriteXmlSchema (stream);
513 DataTable table = new DataTable ();
514 using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
515 table.ReadXmlSchema (stream);
518 VerifyTableSchema (table, parentTable.TableName, null);
522 [Category ("NotWorking")]
523 public void XmlSchemaTest4 ()
527 MakeSecondChildTable ();
531 using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
532 parentTable.WriteXmlSchema (stream, true);
536 DataTable table = new DataTable ();
537 using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
538 table.ReadXmlSchema (stream);
541 //Test Property of Parent
542 VerifyParentTableSchema (table, parentTable.TableName, parentTable.DataSet);
544 //Check Properties of First Child Table
545 DataTable firstChildTable = parentTable.ChildRelations [0].ChildTable;
546 Assert.AreEqual (string.Empty, firstChildTable.Namespace, "#1");
547 Assert.AreEqual ("XmlSchemaDataSet", firstChildTable.DataSet.DataSetName, "#2");
548 Assert.AreEqual (3, firstChildTable.Columns.Count, "#3");
549 Assert.AreEqual (6, firstChildTable.Rows.Count, "#4");
550 Assert.AreEqual (false, firstChildTable.CaseSensitive, "#5");
551 Assert.AreEqual ("ChildTable", firstChildTable.TableName, "#6");
552 Assert.AreEqual (string.Empty, firstChildTable.Prefix, "#7");
553 Assert.AreEqual (2, firstChildTable.Constraints.Count, "#8");
554 Assert.AreEqual ("Constraint1", firstChildTable.Constraints [0].ToString (), "#9");
555 Assert.AreEqual ("ParentChild_Relation1", firstChildTable.Constraints [1].ToString (), "#10");
556 Assert.AreEqual (1, firstChildTable.ParentRelations.Count, "#11");
557 Assert.AreEqual (0, firstChildTable.ChildRelations.Count, "#12");
558 Assert.AreEqual (0, firstChildTable.PrimaryKey.Length, "#13");
560 //Check Properties of Second Child Table
561 DataTable secondChildTable = parentTable.ChildRelations [1].ChildTable;
562 Assert.AreEqual (string.Empty, secondChildTable.Namespace, "#14");
563 Assert.AreEqual ("XmlSchemaDataSet", secondChildTable.DataSet.DataSetName, "#15");
564 Assert.AreEqual (4, secondChildTable.Columns.Count, "#16");
565 Assert.AreEqual (6, secondChildTable.Rows.Count, "#17");
566 Assert.AreEqual (false, secondChildTable.CaseSensitive, "#18");
567 Assert.AreEqual ("SecondChildTable", secondChildTable.TableName, "#19");
568 Assert.AreEqual (string.Empty, secondChildTable.Prefix, "#20");
569 Assert.AreEqual (2, secondChildTable.Constraints.Count, "#21");
570 Assert.AreEqual ("Constraint1", secondChildTable.Constraints [0].ToString (), "#22");
571 Assert.AreEqual ("ParentChild_Relation2", secondChildTable.Constraints [1].ToString (), "#23");
572 Assert.AreEqual (1, secondChildTable.ParentRelations.Count, "#24");;
573 Assert.AreEqual (0, secondChildTable.ChildRelations.Count, "#25");
574 Assert.AreEqual (0, secondChildTable.PrimaryKey.Length, "#26");
579 public void XmlSchemaTest5 ()
583 MakeSecondChildTable ();
587 using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
588 childTable.WriteXmlSchema (stream);
592 DataTable table = new DataTable (childTable.TableName);
593 using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
594 table.ReadXmlSchema (stream);
597 //Check Properties of the table
598 Assert.AreEqual (string.Empty, table.Namespace, "#1");
599 Assert.IsNull (table.DataSet, "#2");
600 Assert.AreEqual (3, table.Columns.Count, "#3");
601 Assert.AreEqual (0, table.Rows.Count, "#4");
602 Assert.AreEqual (false, table.CaseSensitive, "#5");
603 Assert.AreEqual ("ChildTable", table.TableName, "#6");
604 Assert.AreEqual (string.Empty, table.Prefix, "#7");
605 Assert.AreEqual (1, table.Constraints.Count, "#8");
606 Assert.AreEqual ("Constraint1", table.Constraints [0].ToString (), "#9");
607 Assert.AreEqual (typeof (UniqueConstraint), table.Constraints [0].GetType(), "#10");
608 Assert.AreEqual (0, table.ParentRelations.Count, "#11");
609 Assert.AreEqual (0, table.ChildRelations.Count, "#12");
610 Assert.AreEqual (0, table.PrimaryKey.Length, "#13");
613 DataColumn col = table.Columns [0];
614 Assert.AreEqual (true, col.AllowDBNull, "#14");
615 Assert.AreEqual (true, col.AutoIncrement, "#15");
616 Assert.AreEqual (0, col.AutoIncrementSeed, "#16");
617 Assert.AreEqual (1, col.AutoIncrementStep, "#17");
618 Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#18");
619 Assert.AreEqual ("ChildID", col.ColumnName, "#19");
620 Assert.AreEqual (typeof (int), col.DataType, "#20");
621 Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#21");
622 Assert.AreEqual (false, col.DesignMode, "#22");
623 Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#23");
624 Assert.AreEqual (-1, col.MaxLength, "#24");
625 Assert.AreEqual (0, col.Ordinal, "#25");
626 Assert.AreEqual (string.Empty, col.Prefix, "#26");
627 Assert.AreEqual ("ChildTable", col.Table.ToString (), "#27");
628 Assert.AreEqual (true, col.Unique, "#28");
631 col = table.Columns [1];
632 Assert.AreEqual (true, col.AllowDBNull, "#29");
633 Assert.AreEqual (false, col.AutoIncrement, "#30");
634 Assert.AreEqual (0, col.AutoIncrementSeed, "#31");
635 Assert.AreEqual (1, col.AutoIncrementStep, "#32");
636 Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#33");
637 Assert.AreEqual ("ChildItem", col.Caption, "#34");
638 Assert.AreEqual ("ChildItem", col.ColumnName, "#35");
639 Assert.AreEqual (typeof (string), col.DataType, "#36");
640 Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#37");
641 Assert.AreEqual (false, col.DesignMode, "#38");
642 Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#39");
643 Assert.AreEqual (-1, col.MaxLength, "#40");
644 Assert.AreEqual (1, col.Ordinal, "#41");
645 Assert.AreEqual (string.Empty, col.Prefix, "#42");
646 Assert.AreEqual ("ChildTable", col.Table.ToString (), "#42");
647 Assert.AreEqual (false, col.Unique, "#43");
650 col = table.Columns [2];
651 Assert.AreEqual (true, col.AllowDBNull, "#44");
652 Assert.AreEqual (false, col.AutoIncrement, "#45");
653 Assert.AreEqual (0, col.AutoIncrementSeed, "#46");
654 Assert.AreEqual (1, col.AutoIncrementStep, "#47");
655 Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#48");
656 Assert.AreEqual ("ParentID", col.Caption, "#49");
657 Assert.AreEqual ("ParentID", col.ColumnName, "#50");
658 Assert.AreEqual (typeof (int), col.DataType, "#51");
659 Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#52");
660 Assert.AreEqual (false, col.DesignMode, "#53");
661 Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#54");
662 Assert.AreEqual (-1, col.MaxLength, "#55");
663 Assert.AreEqual (2, col.Ordinal, "#56");
664 Assert.AreEqual (string.Empty, col.Prefix, "#57");
665 Assert.AreEqual ("ChildTable", col.Table.ToString (), "#58");
666 Assert.AreEqual (false, col.Unique, "#59");
670 public void XmlSchemaTest6 ()
674 using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
675 parentTable.WriteXmlSchema (stream);
678 DataTable table = new DataTable ();
679 DataSet ds = new DataSet ();
680 ds.Tables.Add (table);
682 using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
684 table.ReadXmlSchema (stream);
686 } catch (ArgumentException ex) {
687 // DataTable 'Table1' does not match
688 // to any DataTable in source
689 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
690 Assert.IsNull (ex.InnerException, "#3");
691 Assert.IsNotNull (ex.Message, "#4");
692 Assert.IsTrue (ex.Message.IndexOf ("'Table1'") != -1, "#5");
693 Assert.IsNull (ex.ParamName, "#6");
699 public void XmlSchemaTest7 ()
701 DataTable table = new DataTable ();
704 table.ReadXmlSchema (string.Empty);
706 } catch (ArgumentException ex) {
707 // The URL cannot be empty
708 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
709 Assert.IsNull (ex.InnerException, "#3");
710 Assert.IsNotNull (ex.Message, "#4");
711 //Assert.AreEqual ("url", ex.ParamName, "#5");
716 public void XmlSchemaTest8 ()
720 using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
721 parentTable.WriteXmlSchema (stream);
724 //Create a table and define the schema partially
725 DataTable table = new DataTable ();
726 table.Columns.Add (new DataColumn (parentTable.Columns [0].ColumnName, typeof (int)));
728 //ReadXmlSchema will not read any schema in this case
729 table.ReadXmlSchema (tempFile);
731 Assert.AreEqual (string.Empty, table.TableName, "#1");
732 Assert.AreEqual (1, table.Columns.Count, "#2");
733 Assert.AreEqual (0, table.Constraints.Count, "#3");
737 public void XmlSchemaTest9 ()
741 using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
742 parentTable.WriteXmlSchema (stream);
745 //Create a table and define the full schema
746 DataTable table = new DataTable ();
747 table.Columns.Add (new DataColumn (parentTable.Columns [0].ColumnName, typeof (int)));
748 table.Columns.Add (new DataColumn (parentTable.Columns [1].ColumnName, typeof (string)));
749 table.Columns.Add (new DataColumn (parentTable.Columns [2].ColumnName, typeof (int)));
751 //ReadXmlSchema will not read any schema in this case
752 table.ReadXmlSchema (tempFile);
754 Assert.AreEqual (string.Empty, table.TableName, "#1");
755 Assert.AreEqual (3, table.Columns.Count, "#2");
756 Assert.AreEqual (0, table.Constraints.Count, "#3");