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.
31 using NUnit.Framework;
33 namespace MonoTests.System.Data
36 public class DataTableTest3
40 DataTable parentTable;
42 DataTable secondChildTable;
47 tempFile = Path.GetTempFileName ();
51 public void TearDown ()
54 File.Delete (tempFile);
57 private void MakeParentTable ()
60 parentTable = new DataTable ("ParentTable");
61 dataSet = new DataSet ("XmlSchemaDataSet");
65 // Create new DataColumn, set DataType,
66 // ColumnName and add to Table.
67 column = new DataColumn ();
68 column.DataType = typeof (int);
69 column.ColumnName = "id";
71 // Add the Column to the DataColumnCollection.
72 parentTable.Columns.Add (column);
74 // Create second column
75 column = new DataColumn ();
76 column.DataType = typeof (string);
77 column.ColumnName = "ParentItem";
78 column.AutoIncrement = false;
79 column.Caption = "ParentItem";
80 column.Unique = false;
81 // Add the column to the table
82 parentTable.Columns.Add (column);
84 // Create third column.
85 column = new DataColumn ();
86 column.DataType = typeof (int);
87 column.ColumnName = "DepartmentID";
88 column.Caption = "DepartmentID";
89 // Add the column to the table.
90 parentTable.Columns.Add (column);
92 // Make the ID column the primary key column.
93 DataColumn [] PrimaryKeyColumns = new DataColumn [2];
94 PrimaryKeyColumns [0] = parentTable.Columns ["id"];
95 PrimaryKeyColumns [1] = parentTable.Columns ["DepartmentID"];
96 parentTable.PrimaryKey = PrimaryKeyColumns;
98 dataSet.Tables.Add (parentTable);
100 // Create three new DataRow objects and add
101 // them to the DataTable
102 for (int i = 0; i <= 2; i++) {
103 row = parentTable.NewRow ();
105 row ["ParentItem"] = "ParentItem " + (i + 1);
106 row ["DepartmentID"] = i + 1;
107 parentTable.Rows.Add (row);
111 private void MakeChildTable ()
113 // Create a new Table
114 childTable = new DataTable ("ChildTable");
118 // Create first column and add to the DataTable.
119 column = new DataColumn ();
120 column.DataType= typeof (int);
121 column.ColumnName = "ChildID";
122 column.AutoIncrement = true;
123 column.Caption = "ID";
124 column.Unique = true;
126 // Add the column to the DataColumnCollection
127 childTable.Columns.Add (column);
129 // Create second column
130 column = new DataColumn ();
131 column.DataType= typeof (string);
132 column.ColumnName = "ChildItem";
133 column.AutoIncrement = false;
134 column.Caption = "ChildItem";
135 column.Unique = false;
136 childTable.Columns.Add (column);
138 //Create third column
139 column = new DataColumn ();
140 column.DataType= typeof (int);
141 column.ColumnName = "ParentID";
142 column.AutoIncrement = false;
143 column.Caption = "ParentID";
144 column.Unique = false;
145 childTable.Columns.Add (column);
147 dataSet.Tables.Add (childTable);
149 // Create three sets of DataRow objects,
150 // five rows each, and add to DataTable.
151 for (int i = 0; i <= 1; i ++) {
152 row = childTable.NewRow ();
153 row ["childID"] = i + 1;
154 row ["ChildItem"] = "ChildItem " + (i + 1);
155 row ["ParentID"] = 1 ;
156 childTable.Rows.Add (row);
159 for (int i = 0; i <= 1; i ++) {
160 row = childTable.NewRow ();
161 row ["childID"] = i + 5;
162 row ["ChildItem"] = "ChildItem " + (i + 1);
163 row ["ParentID"] = 2 ;
164 childTable.Rows.Add (row);
167 for (int i = 0; i <= 1; i ++) {
168 row = childTable.NewRow ();
169 row ["childID"] = i + 10;
170 row ["ChildItem"] = "ChildItem " + (i + 1);
171 row ["ParentID"] = 3 ;
172 childTable.Rows.Add (row);
176 private void MakeSecondChildTable ()
178 // Create a new Table
179 secondChildTable = new DataTable ("SecondChildTable");
183 // Create first column and add to the DataTable.
184 column = new DataColumn ();
185 column.DataType= typeof (int);
186 column.ColumnName = "ChildID";
187 column.AutoIncrement = true;
188 column.Caption = "ID";
189 column.ReadOnly = true;
190 column.Unique = true;
192 // Add the column to the DataColumnCollection.
193 secondChildTable.Columns.Add (column);
195 // Create second column.
196 column = new DataColumn ();
197 column.DataType= typeof (string);
198 column.ColumnName = "ChildItem";
199 column.AutoIncrement = false;
200 column.Caption = "ChildItem";
201 column.ReadOnly = false;
202 column.Unique = false;
203 secondChildTable.Columns.Add (column);
205 //Create third column.
206 column = new DataColumn ();
207 column.DataType= typeof (int);
208 column.ColumnName = "ParentID";
209 column.AutoIncrement = false;
210 column.Caption = "ParentID";
211 column.ReadOnly = false;
212 column.Unique = false;
213 secondChildTable.Columns.Add (column);
215 //Create fourth column.
216 column = new DataColumn ();
217 column.DataType= typeof (int);
218 column.ColumnName = "DepartmentID";
219 column.Caption = "DepartmentID";
220 column.Unique = false;
221 secondChildTable.Columns.Add (column);
223 dataSet.Tables.Add (secondChildTable);
225 // Create three sets of DataRow objects,
226 // five rows each, and add to DataTable.
227 for (int i = 0; i <= 1; i++) {
228 row = secondChildTable.NewRow ();
229 row ["childID"] = i + 1;
230 row ["ChildItem"] = "SecondChildItem " + (i + 1);
231 row ["ParentID"] = 1 ;
232 row ["DepartmentID"] = 1;
233 secondChildTable.Rows.Add (row);
236 for (int i = 0;i <= 1;i++) {
237 row = secondChildTable.NewRow ();
238 row ["childID"] = i + 5;
239 row ["ChildItem"] = "SecondChildItem " + (i + 1);
240 row ["ParentID"] = 2;
241 row ["DepartmentID"] = 2;
242 secondChildTable.Rows.Add (row);
245 for (int i = 0;i <= 1;i++) {
246 row = secondChildTable.NewRow ();
247 row ["childID"] = i + 10;
248 row ["ChildItem"] = "SecondChildItem " + (i + 1);
249 row ["ParentID"] = 3 ;
250 row ["DepartmentID"] = 3;
251 secondChildTable.Rows.Add (row);
255 private void MakeDataRelation ()
257 DataColumn parentColumn = dataSet.Tables ["ParentTable"].Columns ["id"];
258 DataColumn childColumn = dataSet.Tables ["ChildTable"].Columns ["ParentID"];
259 DataRelation relation = new DataRelation ("ParentChild_Relation1", parentColumn, childColumn);
260 dataSet.Tables ["ChildTable"].ParentRelations.Add (relation);
262 DataColumn [] parentColumn1 = new DataColumn [2];
263 DataColumn [] childColumn1 = new DataColumn [2];
265 parentColumn1 [0] = dataSet.Tables ["ParentTable"].Columns ["id"];
266 parentColumn1 [1] = dataSet.Tables ["ParentTable"].Columns ["DepartmentID"];
268 childColumn1 [0] = dataSet.Tables ["SecondChildTable"].Columns ["ParentID"];
269 childColumn1 [1] = dataSet.Tables ["SecondChildTable"].Columns ["DepartmentID"];
271 DataRelation secondRelation = new DataRelation("ParentChild_Relation2", parentColumn1, childColumn1);
272 dataSet.Tables ["SecondChildTable"].ParentRelations.Add (secondRelation);
275 //Test properties of a table which does not belongs to a DataSet
276 private void VerifyTableSchema (DataTable table, string tableName, DataSet ds)
278 //Check Properties of Table
279 Assert.AreEqual ("", table.Namespace, "#1");
280 Assert.AreEqual (ds, table.DataSet, "#2");
281 Assert.AreEqual (3, table.Columns.Count, "#3");
282 Assert.AreEqual (0, table.Rows.Count, "#4");
283 Assert.AreEqual (false, table.CaseSensitive, "#5");
284 Assert.AreEqual (tableName, table.TableName, "#6");
285 Assert.AreEqual (2, table.Constraints.Count, "#7");
286 Assert.AreEqual ("", table.Prefix, "#8");
287 Assert.AreEqual ("Constraint2", table.Constraints [0].ToString (), "#9");
288 Assert.AreEqual ("Constraint1", table.Constraints [1].ToString (), "#10");
289 Assert.AreEqual (typeof (UniqueConstraint), table.Constraints [0].GetType (), "#11");
290 Assert.AreEqual (typeof (UniqueConstraint), table.Constraints [1].GetType (), "#12");
291 Assert.AreEqual (2, table.PrimaryKey.Length, "#13");
292 Assert.AreEqual ("id", table.PrimaryKey [0].ToString (), "#14");
293 Assert.AreEqual ("DepartmentID", table.PrimaryKey [1].ToString (), "#15");
295 Assert.AreEqual (0, table.ParentRelations.Count, "#16");
296 Assert.AreEqual (0, table.ChildRelations.Count, "#17");
298 //Check properties of each column
300 DataColumn col = table.Columns [0];
301 Assert.AreEqual (false, col.AllowDBNull, "#18");
302 Assert.AreEqual (false, col.AutoIncrement, "#19");
303 Assert.AreEqual (0, col.AutoIncrementSeed, "#20");
304 Assert.AreEqual (1, col.AutoIncrementStep, "#21");
305 Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#22");
306 Assert.AreEqual ("id", col.Caption, "#23");
307 Assert.AreEqual ("id", col.ColumnName, "#24");
308 Assert.AreEqual (typeof (int), col.DataType, "#25");
309 Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#26");
310 Assert.AreEqual (false, col.DesignMode, "#27");
311 Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#28");
312 Assert.AreEqual (-1, col.MaxLength, "#29");
313 Assert.AreEqual (0, col.Ordinal, "#30");
314 Assert.AreEqual (string.Empty, col.Prefix, "#31");
315 Assert.AreEqual (tableName, col.Table.ToString (), "#32");
316 Assert.AreEqual (true, col.Unique, "#33");
319 col = table.Columns [1];
320 Assert.AreEqual (true, col.AllowDBNull, "#34");
321 Assert.AreEqual (false, col.AutoIncrement, "#35");
322 Assert.AreEqual (0, col.AutoIncrementSeed, "#36");
323 Assert.AreEqual (1, col.AutoIncrementStep, "#37");
324 Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#38");
325 Assert.AreEqual ("ParentItem", col.Caption, "#39");
326 Assert.AreEqual ("ParentItem", col.ColumnName, "#40");
327 Assert.AreEqual (typeof (string), col.DataType, "#41");
328 Assert.AreEqual ("", col.DefaultValue.ToString (), "#42");
329 Assert.AreEqual (false, col.DesignMode, "#43");
330 Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#44");
331 Assert.AreEqual (-1, col.MaxLength, "#45");
332 Assert.AreEqual (1, col.Ordinal, "#46");
333 Assert.AreEqual ("", col.Prefix, "#47");
334 Assert.AreEqual (tableName, col.Table.ToString (), "#48");
335 Assert.AreEqual (false, col.Unique, "#49");
338 col = table.Columns [2];
339 Assert.AreEqual (false, col.AllowDBNull, "#50");
340 Assert.AreEqual (false, col.AutoIncrement, "#51");
341 Assert.AreEqual (0, col.AutoIncrementSeed, "#52");
342 Assert.AreEqual (1, col.AutoIncrementStep, "#53");
343 Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#54");
344 Assert.AreEqual ("DepartmentID", col.Caption, "#55");
345 Assert.AreEqual ("DepartmentID", col.ColumnName, "#56");
346 Assert.AreEqual (typeof (int), col.DataType, "#57");
347 Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#58");
348 Assert.AreEqual (false, col.DesignMode, "#59");
349 Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#60");
350 Assert.AreEqual (-1, col.MaxLength, "#61");
351 Assert.AreEqual (2, col.Ordinal, "#62");
352 Assert.AreEqual ("", col.Prefix, "#63");
353 Assert.AreEqual (tableName, col.Table.ToString (), "#64");
354 Assert.AreEqual (false, col.Unique, "#65");
357 private void VerifyParentTableSchema (DataTable table, string tableName, DataSet ds)
359 //Check Properties of Table
360 Assert.AreEqual (string.Empty, table.Namespace, "#1");
361 Assert.AreEqual (ds.DataSetName, table.DataSet.DataSetName, "#2");
362 Assert.AreEqual (3, table.Columns.Count, "#3");
363 Assert.AreEqual (0, table.Rows.Count, "#4");
364 Assert.AreEqual (false, table.CaseSensitive, "#5");
365 Assert.AreEqual ("ParentTable", table.TableName, "#6");
366 Assert.AreEqual (2, table.Constraints.Count, "#7");
367 Assert.AreEqual (string.Empty, table.Prefix, "#8");
370 Assert.AreEqual ("Constraint1", table.Constraints [0].ToString (), "#9");
371 Assert.AreEqual ("Constraint2", table.Constraints [1].ToString (), "#10");
372 Assert.AreEqual (typeof (UniqueConstraint), table.Constraints [0].GetType (), "#11");
373 Assert.AreEqual (typeof (UniqueConstraint), table.Constraints [1].GetType (), "#12");
374 Assert.AreEqual (2, table.PrimaryKey.Length, "#13");
375 Assert.AreEqual ("id", table.PrimaryKey [0].ToString (), "#14");
376 Assert.AreEqual ("DepartmentID", table.PrimaryKey [1].ToString (), "#15");
378 //Check Relations of the ParentTable
379 Assert.AreEqual (0, table.ParentRelations.Count, "#16");
380 Assert.AreEqual (2, table.ChildRelations.Count, "#17");
381 Assert.AreEqual ("ParentChild_Relation1", table.ChildRelations [0].ToString (), "#18");
382 Assert.AreEqual ("ParentChild_Relation2", table.ChildRelations [1].ToString (), "#19");
383 Assert.AreEqual ("ChildTable", table.ChildRelations [0].ChildTable.TableName, "#20");
384 Assert.AreEqual ("SecondChildTable", table.ChildRelations [1].ChildTable.TableName, "#21");
386 Assert.AreEqual (1, table.ChildRelations [0].ParentColumns.Length, "#22");
387 Assert.AreEqual ("id", table.ChildRelations [0].ParentColumns [0].ColumnName, "#23");
388 Assert.AreEqual (1, table.ChildRelations [0].ChildColumns.Length, "#24");
389 Assert.AreEqual ("ParentID", table.ChildRelations [0].ChildColumns [0].ColumnName, "#25");
391 Assert.AreEqual (2, table.ChildRelations [1].ParentColumns.Length, "#26");
392 Assert.AreEqual ("id", table.ChildRelations [1].ParentColumns [0].ColumnName, "#27");
393 Assert.AreEqual ("DepartmentID", table.ChildRelations [1].ParentColumns [1].ColumnName, "#28");
394 Assert.AreEqual (2, table.ChildRelations [1].ChildColumns.Length, "#29");
396 Assert.AreEqual ("ParentID", table.ChildRelations [1].ChildColumns [0].ColumnName, "#30");
397 Assert.AreEqual ("DepartmentID", table.ChildRelations [1].ChildColumns [1].ColumnName, "#31");
399 //Check properties of each column
401 DataColumn col = table.Columns [0];
402 Assert.AreEqual (false, col.AllowDBNull, "#32");
403 Assert.AreEqual (false, col.AutoIncrement, "#33");
404 Assert.AreEqual (0, col.AutoIncrementSeed, "#34");
405 Assert.AreEqual (1, col.AutoIncrementStep, "#35");
406 Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#36");
407 Assert.AreEqual ("id", col.Caption, "#37");
408 Assert.AreEqual ("id", col.ColumnName, "#38");
409 Assert.AreEqual (typeof (int), col.DataType, "#39");
410 Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#40");
411 Assert.AreEqual (false, col.DesignMode, "#41");
412 Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#42");
413 Assert.AreEqual (-1, col.MaxLength, "#43");
414 Assert.AreEqual (0, col.Ordinal, "#44");
415 Assert.AreEqual (string.Empty, col.Prefix, "#45");
416 Assert.AreEqual ("ParentTable", col.Table.ToString (), "#46");
417 Assert.AreEqual (true, col.Unique, "#47");
420 col = table.Columns [1];
421 Assert.AreEqual (true, col.AllowDBNull, "#48");
422 Assert.AreEqual (false, col.AutoIncrement, "#49");
423 Assert.AreEqual (0, col.AutoIncrementSeed, "#50");
424 Assert.AreEqual (1, col.AutoIncrementStep, "#51");
425 Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#52");
426 Assert.AreEqual ("ParentItem", col.Caption, "#53");
427 Assert.AreEqual ("ParentItem", col.ColumnName, "#54");
428 Assert.AreEqual (typeof (string), col.DataType, "#55");
429 Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#56");
430 Assert.AreEqual (false, col.DesignMode, "#57");
431 Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#58");
432 Assert.AreEqual (-1, col.MaxLength, "#59");
433 Assert.AreEqual (1, col.Ordinal, "#60");
434 Assert.AreEqual (string.Empty, col.Prefix, "#61");
435 Assert.AreEqual ("ParentTable", col.Table.ToString (), "#62");
436 Assert.AreEqual (false, col.Unique, "#63");
439 col = table.Columns [2];
440 Assert.AreEqual (false, col.AllowDBNull, "#64");
441 Assert.AreEqual (false, col.AutoIncrement, "#65");
442 Assert.AreEqual (0, col.AutoIncrementSeed, "#66");
443 Assert.AreEqual (1, col.AutoIncrementStep, "#67");
444 Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#68");
445 Assert.AreEqual ("DepartmentID", col.Caption, "#69");
446 Assert.AreEqual ("DepartmentID", col.ColumnName, "#70");
447 Assert.AreEqual (typeof (int), col.DataType, "#71");
448 Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#72");
449 Assert.AreEqual (false, col.DesignMode, "#73");
450 Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#74");
451 Assert.AreEqual (-1, col.MaxLength, "#75");
452 Assert.AreEqual (2, col.Ordinal, "#76");
453 Assert.AreEqual (string.Empty, col.Prefix, "#77");
454 Assert.AreEqual ("ParentTable", col.Table.ToString (), "#78");
455 Assert.AreEqual (false, col.Unique, "#79");
460 public void XmlSchemaTest1 ()
464 //Detach the table from the DataSet
465 dataSet.Tables.Remove (parentTable);
468 using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
469 parentTable.WriteXmlSchema (stream);
473 DataTable table = new DataTable ();
474 using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
475 table.ReadXmlSchema (stream);
478 VerifyTableSchema (table, parentTable.TableName, parentTable.DataSet);
482 public void XmlSchemaTest2 ()
486 dataSet.Tables.Remove (parentTable);
487 parentTable.TableName = String.Empty;
489 using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
491 parentTable.WriteXmlSchema (stream);
493 } catch (InvalidOperationException ex) {
494 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
495 Assert.IsNull (ex.InnerException, "#3");
496 Assert.IsNotNull (ex.Message, "#4");
502 public void XmlSchemaTest3 ()
507 using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
508 parentTable.WriteXmlSchema (stream);
512 DataTable table = new DataTable ();
513 using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
514 table.ReadXmlSchema (stream);
517 VerifyTableSchema (table, parentTable.TableName, null);
521 [Category ("NotWorking")]
522 public void XmlSchemaTest4 ()
526 MakeSecondChildTable ();
530 using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
531 parentTable.WriteXmlSchema (stream, true);
535 DataTable table = new DataTable ();
536 using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
537 table.ReadXmlSchema (stream);
540 //Test Property of Parent
541 VerifyParentTableSchema (table, parentTable.TableName, parentTable.DataSet);
543 //Check Properties of First Child Table
544 DataTable firstChildTable = parentTable.ChildRelations [0].ChildTable;
545 Assert.AreEqual (string.Empty, firstChildTable.Namespace, "#1");
546 Assert.AreEqual ("XmlSchemaDataSet", firstChildTable.DataSet.DataSetName, "#2");
547 Assert.AreEqual (3, firstChildTable.Columns.Count, "#3");
548 Assert.AreEqual (6, firstChildTable.Rows.Count, "#4");
549 Assert.AreEqual (false, firstChildTable.CaseSensitive, "#5");
550 Assert.AreEqual ("ChildTable", firstChildTable.TableName, "#6");
551 Assert.AreEqual (string.Empty, firstChildTable.Prefix, "#7");
552 Assert.AreEqual (2, firstChildTable.Constraints.Count, "#8");
553 Assert.AreEqual ("Constraint1", firstChildTable.Constraints [0].ToString (), "#9");
554 Assert.AreEqual ("ParentChild_Relation1", firstChildTable.Constraints [1].ToString (), "#10");
555 Assert.AreEqual (1, firstChildTable.ParentRelations.Count, "#11");
556 Assert.AreEqual (0, firstChildTable.ChildRelations.Count, "#12");
557 Assert.AreEqual (0, firstChildTable.PrimaryKey.Length, "#13");
559 //Check Properties of Second Child Table
560 DataTable secondChildTable = parentTable.ChildRelations [1].ChildTable;
561 Assert.AreEqual (string.Empty, secondChildTable.Namespace, "#14");
562 Assert.AreEqual ("XmlSchemaDataSet", secondChildTable.DataSet.DataSetName, "#15");
563 Assert.AreEqual (4, secondChildTable.Columns.Count, "#16");
564 Assert.AreEqual (6, secondChildTable.Rows.Count, "#17");
565 Assert.AreEqual (false, secondChildTable.CaseSensitive, "#18");
566 Assert.AreEqual ("SecondChildTable", secondChildTable.TableName, "#19");
567 Assert.AreEqual (string.Empty, secondChildTable.Prefix, "#20");
568 Assert.AreEqual (2, secondChildTable.Constraints.Count, "#21");
569 Assert.AreEqual ("Constraint1", secondChildTable.Constraints [0].ToString (), "#22");
570 Assert.AreEqual ("ParentChild_Relation2", secondChildTable.Constraints [1].ToString (), "#23");
571 Assert.AreEqual (1, secondChildTable.ParentRelations.Count, "#24");;
572 Assert.AreEqual (0, secondChildTable.ChildRelations.Count, "#25");
573 Assert.AreEqual (0, secondChildTable.PrimaryKey.Length, "#26");
578 public void XmlSchemaTest5 ()
582 MakeSecondChildTable ();
586 using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
587 childTable.WriteXmlSchema (stream);
591 DataTable table = new DataTable (childTable.TableName);
592 using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
593 table.ReadXmlSchema (stream);
596 //Check Properties of the table
597 Assert.AreEqual (string.Empty, table.Namespace, "#1");
598 Assert.IsNull (table.DataSet, "#2");
599 Assert.AreEqual (3, table.Columns.Count, "#3");
600 Assert.AreEqual (0, table.Rows.Count, "#4");
601 Assert.AreEqual (false, table.CaseSensitive, "#5");
602 Assert.AreEqual ("ChildTable", table.TableName, "#6");
603 Assert.AreEqual (string.Empty, table.Prefix, "#7");
604 Assert.AreEqual (1, table.Constraints.Count, "#8");
605 Assert.AreEqual ("Constraint1", table.Constraints [0].ToString (), "#9");
606 Assert.AreEqual (typeof (UniqueConstraint), table.Constraints [0].GetType(), "#10");
607 Assert.AreEqual (0, table.ParentRelations.Count, "#11");
608 Assert.AreEqual (0, table.ChildRelations.Count, "#12");
609 Assert.AreEqual (0, table.PrimaryKey.Length, "#13");
612 DataColumn col = table.Columns [0];
613 Assert.AreEqual (true, col.AllowDBNull, "#14");
614 Assert.AreEqual (true, col.AutoIncrement, "#15");
615 Assert.AreEqual (0, col.AutoIncrementSeed, "#16");
616 Assert.AreEqual (1, col.AutoIncrementStep, "#17");
617 Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#18");
618 Assert.AreEqual ("ChildID", col.ColumnName, "#19");
619 Assert.AreEqual (typeof (int), col.DataType, "#20");
620 Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#21");
621 Assert.AreEqual (false, col.DesignMode, "#22");
622 Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#23");
623 Assert.AreEqual (-1, col.MaxLength, "#24");
624 Assert.AreEqual (0, col.Ordinal, "#25");
625 Assert.AreEqual (string.Empty, col.Prefix, "#26");
626 Assert.AreEqual ("ChildTable", col.Table.ToString (), "#27");
627 Assert.AreEqual (true, col.Unique, "#28");
630 col = table.Columns [1];
631 Assert.AreEqual (true, col.AllowDBNull, "#29");
632 Assert.AreEqual (false, col.AutoIncrement, "#30");
633 Assert.AreEqual (0, col.AutoIncrementSeed, "#31");
634 Assert.AreEqual (1, col.AutoIncrementStep, "#32");
635 Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#33");
636 Assert.AreEqual ("ChildItem", col.Caption, "#34");
637 Assert.AreEqual ("ChildItem", col.ColumnName, "#35");
638 Assert.AreEqual (typeof (string), col.DataType, "#36");
639 Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#37");
640 Assert.AreEqual (false, col.DesignMode, "#38");
641 Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#39");
642 Assert.AreEqual (-1, col.MaxLength, "#40");
643 Assert.AreEqual (1, col.Ordinal, "#41");
644 Assert.AreEqual (string.Empty, col.Prefix, "#42");
645 Assert.AreEqual ("ChildTable", col.Table.ToString (), "#42");
646 Assert.AreEqual (false, col.Unique, "#43");
649 col = table.Columns [2];
650 Assert.AreEqual (true, col.AllowDBNull, "#44");
651 Assert.AreEqual (false, col.AutoIncrement, "#45");
652 Assert.AreEqual (0, col.AutoIncrementSeed, "#46");
653 Assert.AreEqual (1, col.AutoIncrementStep, "#47");
654 Assert.AreEqual ("Element", col.ColumnMapping.ToString (), "#48");
655 Assert.AreEqual ("ParentID", col.Caption, "#49");
656 Assert.AreEqual ("ParentID", col.ColumnName, "#50");
657 Assert.AreEqual (typeof (int), col.DataType, "#51");
658 Assert.AreEqual (string.Empty, col.DefaultValue.ToString (), "#52");
659 Assert.AreEqual (false, col.DesignMode, "#53");
660 Assert.AreEqual ("System.Data.PropertyCollection", col.ExtendedProperties.ToString (), "#54");
661 Assert.AreEqual (-1, col.MaxLength, "#55");
662 Assert.AreEqual (2, col.Ordinal, "#56");
663 Assert.AreEqual (string.Empty, col.Prefix, "#57");
664 Assert.AreEqual ("ChildTable", col.Table.ToString (), "#58");
665 Assert.AreEqual (false, col.Unique, "#59");
669 public void XmlSchemaTest6 ()
673 using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
674 parentTable.WriteXmlSchema (stream);
677 DataTable table = new DataTable ();
678 DataSet ds = new DataSet ();
679 ds.Tables.Add (table);
681 using (FileStream stream = new FileStream (tempFile, FileMode.Open)) {
683 table.ReadXmlSchema (stream);
685 } catch (ArgumentException ex) {
686 // DataTable 'Table1' does not match
687 // to any DataTable in source
688 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
689 Assert.IsNull (ex.InnerException, "#3");
690 Assert.IsNotNull (ex.Message, "#4");
691 Assert.IsTrue (ex.Message.IndexOf ("'Table1'") != -1, "#5");
692 Assert.IsNull (ex.ParamName, "#6");
698 public void XmlSchemaTest7 ()
700 DataTable table = new DataTable ();
703 table.ReadXmlSchema (string.Empty);
705 } catch (ArgumentException ex) {
706 // The URL cannot be empty
707 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
708 Assert.IsNull (ex.InnerException, "#3");
709 Assert.IsNotNull (ex.Message, "#4");
710 //Assert.AreEqual ("url", ex.ParamName, "#5");
715 public void XmlSchemaTest8 ()
719 using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
720 parentTable.WriteXmlSchema (stream);
723 //Create a table and define the schema partially
724 DataTable table = new DataTable ();
725 table.Columns.Add (new DataColumn (parentTable.Columns [0].ColumnName, typeof (int)));
727 //ReadXmlSchema will not read any schema in this case
728 table.ReadXmlSchema (tempFile);
730 Assert.AreEqual (string.Empty, table.TableName, "#1");
731 Assert.AreEqual (1, table.Columns.Count, "#2");
732 Assert.AreEqual (0, table.Constraints.Count, "#3");
736 public void XmlSchemaTest9 ()
740 using (FileStream stream = new FileStream (tempFile, FileMode.Create)) {
741 parentTable.WriteXmlSchema (stream);
744 //Create a table and define the full schema
745 DataTable table = new DataTable ();
746 table.Columns.Add (new DataColumn (parentTable.Columns [0].ColumnName, typeof (int)));
747 table.Columns.Add (new DataColumn (parentTable.Columns [1].ColumnName, typeof (string)));
748 table.Columns.Add (new DataColumn (parentTable.Columns [2].ColumnName, typeof (int)));
750 //ReadXmlSchema will not read any schema in this case
751 table.ReadXmlSchema (tempFile);
753 Assert.AreEqual (string.Empty, table.TableName, "#1");
754 Assert.AreEqual (3, table.Columns.Count, "#2");
755 Assert.AreEqual (0, table.Constraints.Count, "#3");