**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Data / Test / System.Data / DataRowTest.cs
blob84e2d5e2da1c26f3cf583758b2a02c18c7276c9d
1 // DataRowTest.cs - NUnit Test Cases for System.DataRow
2 //
3 // Authors:
4 // Franklin Wise (gracenote@earthlink.net)
5 // Daniel Morgan <danmorg@sc.rr.com>
6 // Roopa Wilson (rowilson@novell.com)
7 //
8 // (C) Copyright 2002 Franklin Wise
9 // (C) Copyright 2003 Daniel Morgan
10 // (C) Copyright 2003 Martin Willemoes Hansen
11 //
14 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
16 // Permission is hereby granted, free of charge, to any person obtaining
17 // a copy of this software and associated documentation files (the
18 // "Software"), to deal in the Software without restriction, including
19 // without limitation the rights to use, copy, modify, merge, publish,
20 // distribute, sublicense, and/or sell copies of the Software, and to
21 // permit persons to whom the Software is furnished to do so, subject to
22 // the following conditions:
23 //
24 // The above copyright notice and this permission notice shall be
25 // included in all copies or substantial portions of the Software.
26 //
27 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 using NUnit.Framework;
38 using System;
39 using System.Data;
41 namespace MonoTests.System.Data
43 [TestFixture]
44 public class DataRowTest : Assertion {
46 private DataTable _tbl;
47 private DataTable table;
48 private DataRow row;
50 [SetUp]
51 public void GetReady() {
52 _tbl = new DataTable();
53 table = MakeTable ();
54 row = table.NewRow ();
55 row ["FName"] = "Hello";
56 row ["LName"] = "World";
57 table.Rows.Add (row);
60 private DataTable MakeTable ()
62 DataTable namesTable = new DataTable ("Names");
63 DataColumn idColumn = new DataColumn ();
66 idColumn.DataType = Type.GetType ("System.Int32");
67 idColumn.ColumnName = "Id";
68 idColumn.AutoIncrement = true;
69 namesTable.Columns.Add (idColumn);
72 DataColumn fNameColumn = new DataColumn ();
73 fNameColumn.DataType = Type.GetType ("System.String");
74 fNameColumn.ColumnName = "Fname";
75 fNameColumn.DefaultValue = "Fname";
76 namesTable.Columns.Add (fNameColumn);
78 DataColumn lNameColumn = new DataColumn ();
79 lNameColumn.DataType = Type.GetType ("System.String");
80 lNameColumn.ColumnName = "LName";
81 lNameColumn.DefaultValue="LName";
82 namesTable.Columns.Add (lNameColumn);
85 // Set the primary key for the table
86 DataColumn [] keys = new DataColumn [1];
87 keys [0] = idColumn;
88 namesTable.PrimaryKey = keys;
89 // Return the new DataTable.
90 return namesTable;
93 [Test]
94 public void SetColumnErrorTest ()
96 string errorString;
97 errorString = "Some error!";
98 // Set the error for the specified column of the row.
99 row.SetColumnError (1, errorString);
100 GetColumnErrorTest ();
101 GetAllErrorsTest ();
104 private void GetColumnErrorTest ()
106 // Print the error of a specified column.
107 AssertEquals ("#A01", "Some error!", row.GetColumnError (1));
110 private void GetAllErrorsTest ()
112 DataColumn [] colArr;
114 if (row.HasErrors) {
115 colArr = row.GetColumnsInError ();
117 for (int i = 0; i < colArr.Length; i++) {
118 AssertEquals ("#A02", table.Columns [1], colArr [i]);
120 row.ClearErrors ();
124 [Test]
125 public void RowEditTest()
127 DeleteRowTest ();
128 EditModeTest ();
129 ParentRowTest ();
132 private void DeleteRowTest ()
134 DataRow newRow;
137 for (int i = 1; i <= 2; i++) {
138 newRow = table.NewRow ();
139 newRow ["FName"] = "Name " + i;
140 newRow ["LName"] = " Last Name" + i;
141 table.Rows.Add (newRow);
143 table.AcceptChanges ();
145 int cnt = 1;
146 for (int i = 1; i < table.Rows.Count; i++) {
147 DataRow r = table.Rows [i];
148 AssertEquals ("#A03", "Name " + cnt, r ["fName"]);
149 cnt++;
153 // Create a DataView with the table.
154 DataRowCollection rc = table.Rows;
155 rc [0].Delete ();
156 rc [2].Delete ();
159 AssertEquals ("#A04", "Deleted", rc [0].RowState.ToString ());
160 AssertEquals ("#A05", "Deleted", rc [2].RowState.ToString ());
163 // Accept changes
164 table.AcceptChanges ();
165 AssertEquals ("#A06", "Name 1", (table.Rows [0]) [1]);
166 try {
167 Console.WriteLine (rc [2]);
168 Fail ("#A07");
170 catch (Exception e) {
171 AssertEquals ("#A08", "There is no row at position 2.", e.Message);
175 private void EditModeTest ()
177 try {
178 //Clear all existing values from table
179 for (int i = 0; i < table.Rows.Count; i++) {
180 table.Rows[i].Delete ();
182 table.AcceptChanges ();
183 row = table.NewRow ();
184 row["FName"] = "My FName";
185 table.Rows.Add (row);
188 // Stage 1
189 //Initially: After Add (Row) But Before Accept Changes");
190 AssertEquals ("#A09", "My FName", row [1, DataRowVersion.Default]);
191 AssertEquals ("#A10", "LName", row [2, DataRowVersion.Default]);
193 AssertEquals ("#A11", "My FName", row [1, DataRowVersion.Current]);
194 AssertEquals ("#A12", "LName", row [2, DataRowVersion.Current]);
196 try {
197 Console.WriteLine (row [1, DataRowVersion.Original]);
198 Console.WriteLine (row [1, DataRowVersion.Proposed]);
199 Fail ("#A13");
201 catch (Exception e) {
202 if (e.GetType () != typeof (AssertionException)) {
203 AssertEquals ("#A14", typeof (VersionNotFoundException), e.GetType ());
207 // Stage 2
208 //After Accept Changes
209 table.AcceptChanges ();
210 AssertEquals ("#A15", "My FName", row [1, DataRowVersion.Default]);
211 AssertEquals ("#A16", "LName", row [2, DataRowVersion.Default]);
214 AssertEquals ("#A17", "My FName", row [1, DataRowVersion.Current]);
215 AssertEquals ("#A18", "LName", row [2, DataRowVersion.Current]);
217 try {
218 Console.WriteLine (row [1, DataRowVersion.Proposed]);
219 Fail ("#A19");
221 catch (Exception e) {
222 if (e.GetType () != typeof (AssertionException)) {
223 AssertEquals ("#A20", typeof (VersionNotFoundException), e.GetType ());
228 // Stage 3 // Edit Mode
229 table.Rows [0].BeginEdit ();
230 table.Rows [0] ["LName"] = "My LName";
232 AssertEquals ("#A21", "My FName", row [1, DataRowVersion.Default]);
233 AssertEquals ("#A22", "My LName", row [2, DataRowVersion.Default]);
235 AssertEquals ("#A23", "My FName", row [1, DataRowVersion.Current]);
236 AssertEquals ("#A24", "LName", row [2, DataRowVersion.Current]);
239 AssertEquals ("#A25", "My FName", row [1, DataRowVersion.Original]); AssertEquals ("#A26", "LName", row [2, DataRowVersion.Original]);
241 AssertEquals ("#A26", "My FName", row [1, DataRowVersion.Proposed]);
242 AssertEquals ("#A27", "My LName", row [2, DataRowVersion.Proposed]);
245 // Stage 4
246 //After Edit sessions
247 for (int i=0; i < table.Rows.Count;i++)
248 table.Rows [i].EndEdit ();
249 AssertEquals ("#A28", "My FName", row [1, DataRowVersion.Default]);
250 AssertEquals ("#A29", "My LName", row [2, DataRowVersion.Default]);
252 AssertEquals ("#A30", "My FName", row [1, DataRowVersion.Original]); AssertEquals ("#A31", "LName", row [2, DataRowVersion.Original]);
255 AssertEquals ("#A32", "My FName", row [1, DataRowVersion.Current]);
256 AssertEquals ("#A33", "My LName", row [2, DataRowVersion.Current]);
258 try {
259 Console.WriteLine (row [1, DataRowVersion.Proposed]);
260 Fail ("#A34");
262 catch (Exception e) {
263 if (e.GetType ()!=typeof (AssertionException)) {
264 AssertEquals ("#A35", typeof (VersionNotFoundException), e.GetType ());
268 //Stage 5
269 //After Accept Changes
270 table.AcceptChanges ();
271 AssertEquals ("#A36", "My FName", row [1, DataRowVersion.Default]);
272 AssertEquals ("#A37", "My LName", row [2, DataRowVersion.Default]);
275 AssertEquals ("#A38", "My FName", row [1, DataRowVersion.Original]); AssertEquals ("#A39", "My LName", row [2, DataRowVersion.Original]);
277 AssertEquals ("#A40", "My FName", row [1, DataRowVersion.Current]);
278 AssertEquals ("#A41", "My LName", row [2, DataRowVersion.Current]);
281 try {
282 Console.WriteLine (row [1, DataRowVersion.Proposed]);
283 Fail ("#A42");
285 catch (Exception e) {
286 if (e.GetType () != typeof (AssertionException)) {
287 AssertEquals ("#A43", typeof (VersionNotFoundException),
288 e.GetType ());
294 catch (Exception e){
295 Console.WriteLine (e + "" + e.StackTrace);
298 private void ParentRowTest (){
300 //Clear all existing values from table
301 for (int i = 0; i < table.Rows.Count; i++) {
302 table.Rows[i].Delete ();
304 table.AcceptChanges ();
305 row = table.NewRow ();
306 row["FName"] = "My FName";
307 row["Id"] = 0;
308 table.Rows.Add (row);
310 DataTable tableC = new DataTable ("Child");
311 DataColumn colC;
312 DataRow rowC;
314 colC = new DataColumn ();
315 colC.DataType = Type.GetType ("System.Int32");
316 colC.ColumnName = "Id";
317 colC.AutoIncrement=true;
318 tableC.Columns.Add (colC);
321 colC = new DataColumn ();
322 colC.DataType = Type.GetType ("System.String");
323 colC.ColumnName = "Name";
324 tableC.Columns.Add (colC);
326 rowC = tableC.NewRow ();
327 rowC["Name"] = "My FName";
328 tableC.Rows.Add (rowC);
329 DataSet ds = new DataSet ();
330 ds.Tables.Add (table);
331 ds.Tables.Add (tableC);
332 DataRelation dr = new DataRelation ("PO", table.Columns ["Id"], tableC.Columns ["Id"]);
333 ds.Relations.Add (dr);
335 rowC.SetParentRow (table.Rows [0], dr);
337 AssertEquals ("#A44", table.Rows [0], (tableC.Rows [0]).GetParentRow (dr));
342 // tests item at row, column in table to be DBNull.Value
343 private void DBNullTest (string message, DataTable dt, int row, int column)
345 object val = dt.Rows[row].ItemArray[column];
346 AssertEquals(message, DBNull.Value, val);
349 // tests item at row, column in table to be null
350 private void NullTest (string message, DataTable dt, int row, int column)
352 object val = dt.Rows[row].ItemArray[column];
353 AssertEquals(message, null, val);
356 // tests item at row, column in table to be
357 private void ValueTest (string message, DataTable dt, int row, int column, object value)
359 object val = dt.Rows[row].ItemArray[column];
360 AssertEquals(message, value, val);
363 // test set null, DBNull.Value, and ItemArray short count
364 [Test]
365 public void NullInItemArray ()
367 string zero = "zero";
368 string one = "one";
369 string two = "two";
371 DataTable table = new DataTable();
372 table.Columns.Add(new DataColumn(zero, typeof(string)));
373 table.Columns.Add(new DataColumn(one, typeof(string)));
374 table.Columns.Add(new DataColumn(two, typeof(string)));
376 object[] obj = new object[3];
377 // -- normal -----------------
378 obj[0] = zero;
379 obj[1] = one;
380 obj[2] = two;
381 // results:
382 // table.Rows[0].ItemArray.ItemArray[0] = "zero"
383 // table.Rows[0].ItemArray.ItemArray[1] = "one"
384 // table.Rows[0].ItemArray.ItemArray[2] = "two"
386 DataRow row = table.NewRow();
388 try {
389 row.ItemArray = obj;
391 catch(Exception e1) {
392 Fail("DR1: Exception Caught: " + e1);
395 table.Rows.Add(row);
397 // -- null ----------
398 obj[1] = null;
399 // results:
400 // table.Rows[1].ItemArray.ItemArray[0] = "zero"
401 // table.Rows[1].ItemArray.ItemArray[1] = DBNull.Value
402 // table.Rows[1].ItemArray.ItemArray[2] = "two"
404 row = table.NewRow();
406 try {
407 row.ItemArray = obj;
409 catch(Exception e2) {
410 Fail("DR2: Exception Caught: " + e2);
413 table.Rows.Add(row);
415 // -- DBNull.Value -------------
416 obj[1] = DBNull.Value;
417 // results:
418 // table.Rows[2].ItemArray.ItemArray[0] = "zero"
419 // table.Rows[2].ItemArray.ItemArray[1] = DBNull.Value
420 // table.Rows[2].ItemArray.ItemArray[2] = "two"
422 row = table.NewRow();
424 try {
425 row.ItemArray = obj;
427 catch(Exception e3) {
428 Fail("DR3: Exception Caught: " + e3);
431 table.Rows.Add(row);
433 // -- object array smaller than number of columns -----
434 string abc = "abc";
435 string def = "def";
436 obj = new object[2];
437 obj[0] = abc;
438 obj[1] = def;
439 // results:
440 // table.Rows[3].ItemArray.ItemArray[0] = "abc"
441 // table.Rows[3].ItemArray.ItemArray[1] = "def"
442 // table.Rows[3].ItemArray.ItemArray[2] = DBNull.Value;
444 row = table.NewRow();
446 try {
447 row.ItemArray = obj;
449 catch(Exception e3) {
450 Fail("DR4: Exception Caught: " + e3);
453 table.Rows.Add(row);
455 // -- normal -----------------
456 ValueTest("DR5: normal value test", table, 0, 0, zero);
457 ValueTest("DR6: normal value test", table, 0, 1, one);
458 ValueTest("DR7: normal value test", table, 0, 2, two);
460 // -- null ----------
461 ValueTest("DR8: null value test", table, 1, 0, zero);
462 ValueTest("DR9: null value test", table, 1, 1, DBNull.Value);
463 ValueTest("DR10: null value test", table, 1, 2, two);
465 // -- DBNull.Value -------------
466 ValueTest("DR11: DBNull.Value value test", table, 2, 0, zero);
467 ValueTest("DR12: DBNull.Value value test", table, 2, 1, DBNull.Value);
468 ValueTest("DR13: DBNull.Value value test", table, 2, 2, two);
470 // -- object array smaller than number of columns -----
471 ValueTest("DR14: array smaller value test", table, 3, 0, abc);
472 ValueTest("DR15: array smaller value test", table, 3, 1, def);
473 ValueTest("DR16: array smaller value test", table, 3, 2, DBNull.Value);
476 // test DefaultValue when setting ItemArray
477 [Test]
478 public void DefaultValueInItemArray () {
479 string zero = "zero";
481 DataTable table = new DataTable();
482 table.Columns.Add(new DataColumn("zero", typeof(string)));
484 DataColumn column = new DataColumn("num", typeof(int));
485 column.DefaultValue = 15;
486 table.Columns.Add(column);
488 object[] obj = new object[2];
489 // -- normal -----------------
490 obj[0] = "zero";
491 obj[1] = 8;
492 // results:
493 // table.Rows[0].ItemArray.ItemArray[0] = "zero"
494 // table.Rows[0].ItemArray.ItemArray[1] = 8
496 DataRow row = table.NewRow();
498 try {
499 row.ItemArray = obj;
501 catch(Exception e1) {
502 Fail("DR17: Exception Caught: " + e1);
505 table.Rows.Add(row);
507 // -- null ----------
508 obj[1] = null;
509 // results:
510 // table.Rows[1].ItemArray.ItemArray[0] = "zero"
511 // table.Rows[1].ItemArray.ItemArray[1] = 15
513 row = table.NewRow();
515 try {
516 row.ItemArray = obj;
518 catch(Exception e2) {
519 Fail("DR18: Exception Caught: " + e2);
522 table.Rows.Add(row);
524 // -- DBNull.Value -------------
525 obj[1] = DBNull.Value;
526 // results:
527 // table.Rows[2].ItemArray.ItemArray[0] = "zero"
528 // table.Rows[2].ItemArray.ItemArray[1] = DBNull.Value
529 // even though internally, the v
531 row = table.NewRow();
533 try {
534 row.ItemArray = obj;
536 catch(Exception e3) {
537 Fail("DR19: Exception Caught: " + e3);
540 table.Rows.Add(row);
542 // -- object array smaller than number of columns -----
543 string abc = "abc";
544 string def = "def";
545 obj = new object[2];
546 obj[0] = abc;
547 // results:
548 // table.Rows[3].ItemArray.ItemArray[0] = "abc"
549 // table.Rows[3].ItemArray.ItemArray[1] = DBNull.Value
551 row = table.NewRow();
553 try {
554 row.ItemArray = obj;
556 catch(Exception e3) {
557 Fail("DR20: Exception Caught: " + e3);
560 table.Rows.Add(row);
562 // -- normal -----------------
563 ValueTest("DR20: normal value test", table, 0, 0, zero);
564 ValueTest("DR21: normal value test", table, 0, 1, 8);
566 // -- null ----------
567 ValueTest("DR22: null value test", table, 1, 0, zero);
568 ValueTest("DR23: null value test", table, 1, 1, 15);
570 // -- DBNull.Value -------------
571 ValueTest("DR24: DBNull.Value value test", table, 2, 0, zero);
572 DBNullTest("DR25: DBNull.Value value test", table, 2, 1);
574 // -- object array smaller than number of columns -----
575 ValueTest("DR26: array smaller value test", table, 3, 0, abc);
576 ValueTest("DR27: array smaller value test", table, 3, 1, 15);
579 // test AutoIncrement when setting ItemArray
580 [Test]
581 public void AutoIncrementInItemArray () {
582 string zero = "zero";
583 string num = "num";
585 DataTable table = new DataTable();
586 table.Columns.Add(new DataColumn(zero, typeof(string)));
588 DataColumn column = new DataColumn("num", typeof(int));
589 column.AutoIncrement = true;
590 table.Columns.Add(column);
592 object[] obj = new object[2];
593 // -- normal -----------------
594 obj[0] = "zero";
595 obj[1] = 8;
596 // results:
597 // table.Rows[0].ItemArray.ItemArray[0] = "zero"
598 // table.Rows[0].ItemArray.ItemArray[1] = 8
600 DataRow row = table.NewRow();
602 try {
603 row.ItemArray = obj;
605 catch(Exception e1) {
606 Fail("DR28: Exception Caught: " + e1);
609 table.Rows.Add(row);
611 // -- null 1----------
612 obj[1] = null;
613 // results:
614 // table.Rows[1].ItemArray.ItemArray[0] = "zero"
615 // table.Rows[1].ItemArray.ItemArray[1] = 9
617 row = table.NewRow();
619 try {
620 row.ItemArray = obj;
622 catch(Exception e2) {
623 Fail("DR29: Exception Caught: " + e2);
626 table.Rows.Add(row);
628 // -- null 2----------
629 obj[1] = null;
630 // results:
631 // table.Rows[1].ItemArray.ItemArray[0] = "zero"
632 // table.Rows[1].ItemArray.ItemArray[1] = 10
634 row = table.NewRow();
636 try {
637 row.ItemArray = obj;
639 catch(Exception e2) {
640 Fail("DR30: Exception Caught: " + e2);
643 table.Rows.Add(row);
645 // -- null 3----------
646 obj[1] = null;
647 // results:
648 // table.Rows[1].ItemArray.ItemArray[0] = "zero"
649 // table.Rows[1].ItemArray.ItemArray[1] = 11
651 row = table.NewRow();
653 try {
654 row.ItemArray = obj;
656 catch(Exception e2) {
657 Fail("DR31: Exception Caught: " + e2);
660 table.Rows.Add(row);
662 // -- DBNull.Value -------------
663 obj[1] = DBNull.Value;
664 // results:
665 // table.Rows[2].ItemArray.ItemArray[0] = "zero"
666 // table.Rows[2].ItemArray.ItemArray[1] = DBNull.Value
667 // even though internally, the AutoIncrement value
668 // is incremented
670 row = table.NewRow();
672 try {
673 row.ItemArray = obj;
675 catch(Exception e3) {
676 Fail("DR32: Exception Caught: " + e3);
679 table.Rows.Add(row);
681 // -- null 4----------
682 obj[1] = null;
683 // results:
684 // table.Rows[1].ItemArray.ItemArray[0] = "zero"
685 // table.Rows[1].ItemArray.ItemArray[1] = 13
687 row = table.NewRow();
689 try {
690 row.ItemArray = obj;
692 catch(Exception e2) {
693 Fail("DR48: Exception Caught: " + e2);
696 table.Rows.Add(row);
698 // -- object array smaller than number of columns -----
699 string abc = "abc";
700 string def = "def";
701 obj = new object[2];
702 obj[0] = abc;
703 // results:
704 // table.Rows[3].ItemArray.ItemArray[0] = "abc"
705 // table.Rows[3].ItemArray.ItemArray[1] = 14
707 row = table.NewRow();
709 try {
710 row.ItemArray = obj;
712 catch(Exception e3) {
713 Fail("DR33: Exception Caught: " + e3);
716 table.Rows.Add(row);
718 // -- normal -----------------
719 ValueTest("DR34: normal value test", table, 0, 0, zero);
720 ValueTest("DR35: normal value test", table, 0, 1, 8);
722 // -- null 1----------
723 ValueTest("DR36: null value test", table, 1, 0, zero);
724 ValueTest("DR37: null value test", table, 1, 1, 9);
726 // -- null 2----------
727 ValueTest("DR38: null value test", table, 2, 0, zero);
728 ValueTest("DR39: null value test", table, 2, 1, 10);
730 // -- null 3----------
731 ValueTest("DR40: null value test", table, 3, 0, zero);
732 ValueTest("DR41: null value test", table, 3, 1, 11);
734 // -- DBNull.Value -------------
735 ValueTest("DR42: DBNull.Value value test", table, 4, 0, zero);
736 ValueTest("DR43: DBNull.Value value test", table, 4, 1, DBNull.Value);
738 // -- null 4----------
739 ValueTest("DR44: null value test", table, 5, 0, zero);
740 ValueTest("DR45: null value test", table, 5, 1, 13);
742 // -- object array smaller than number of columns -----
743 ValueTest("DR46: array smaller value test", table, 6, 0, abc);
744 ValueTest("DR47: array smaller value test", table, 6, 1, 14);
747 [Test]
748 public void AutoIncrementColumnIntegrity ()
750 // AutoIncrement-column shouldn't raise index out of range
751 // exception because of size mismatch of internal itemarray.
752 DataTable dt = new DataTable ();
753 dt.Columns.Add ("foo");
754 dt.Rows.Add (new object [] {"value"});
755 DataColumn col = new DataColumn ("bar");
756 col.AutoIncrement = true;
757 dt.Columns.Add (col);
758 dt.Rows [0] [0] = "test";
761 [Test]
762 public void EnforceConstraint ()
764 int id = 100;
765 // Setup stuff
766 DataSet ds = new DataSet();
767 DataTable parent = ds.Tables.Add("parent");
768 parent.Columns.Add("id", typeof(int));
769 DataTable child = ds.Tables.Add("child");
770 child.Columns.Add("idref", typeof(int));
771 Constraint uniqueId = null;
772 parent.Constraints.Add(uniqueId = new UniqueConstraint("uniqueId",
773 new DataColumn[] {parent.Columns["id"]}, true));
774 ForeignKeyConstraint fkc = new ForeignKeyConstraint("ParentChildConstraint", new DataColumn[] { parent.Columns["id"] },
775 new DataColumn[] { child.Columns["idref"]});
777 child.Constraints.Add(fkc);
779 DataRelation relateParentChild = new DataRelation("relateParentChild",
780 new DataColumn[] {parent.Columns["id"] },
781 new DataColumn[] {child.Columns["idref"] },
782 false);
783 ds.Relations.Add(relateParentChild);
785 ds.EnforceConstraints = false;
786 DataRow parentRow = parent.Rows.Add(new object[] { id });
787 DataRow childRow = child.Rows.Add(new object[] { id });
788 if (parentRow == childRow.GetParentRow(relateParentChild)) {
789 foreach(DataColumn dc in parent.Columns)
790 AssertEquals(100,parentRow[dc]);