1 // DataRowCollectionTest.cs - NUnit Test Cases for System.DataRowCollection
4 // Franklin Wise (gracenote@earthlink.net)
5 // Martin Willemoes Hansen (mwh@sysrq.dk)
7 // (C) Copyright 2002 Franklin Wise
8 // (C) Copyright 2003 Martin Willemoes Hansen
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using NUnit.Framework;
39 namespace MonoTests.System.Data
42 public class DataRowCollectionTest
44 private DataTable _tbl;
47 public void GetReady()
49 _tbl = new DataTable();
53 public void AutoIncrement()
55 DataColumn col = new DataColumn("Auto");
56 col.AutoIncrement = true;
57 col.AutoIncrementSeed = 0;
58 col.AutoIncrementStep = 1;
60 _tbl.Columns.Add(col);
61 _tbl.Rows.Add(_tbl.NewRow());
63 Assert.AreEqual (0, Convert.ToInt32(_tbl.Rows[0]["Auto"] ), "test#01" );
65 _tbl.Rows.Add(_tbl.NewRow());
66 Assert.AreEqual (1, Convert.ToInt32(_tbl.Rows[1]["Auto"] ), "test#02" );
68 col.AutoIncrement = false;
69 Assert.AreEqual (1, Convert.ToInt32(_tbl.Rows[1]["Auto"] ), "test#03" );
71 _tbl.Rows.Add(_tbl.NewRow());
72 Assert.AreEqual (DBNull.Value, _tbl.Rows[2]["Auto"], "test#04" );
74 col.AutoIncrement = true;
75 col.AutoIncrementSeed = 10;
76 col.AutoIncrementStep = 2;
78 _tbl.Rows.Add(_tbl.NewRow());
79 Assert.AreEqual (10, Convert.ToInt32(_tbl.Rows[3]["Auto"] ), "test#05" );
80 _tbl.Rows.Add(_tbl.NewRow());
81 Assert.AreEqual (12, Convert.ToInt32(_tbl.Rows[4]["Auto"] ), "test#06" );
83 col = new DataColumn ("Auto2");
84 col.DataType = typeof(string);
85 col.AutoIncrement = true;
86 col.AutoIncrementSeed = 0;
87 col.AutoIncrementStep = 1;
88 _tbl.Columns.Add (col);
90 _tbl.Rows.Add(_tbl.NewRow());
91 Assert.AreEqual (typeof (int), _tbl.Columns [1].DataType, "test#07");
92 Assert.AreEqual (typeof (int), _tbl.Rows[5]["Auto2"].GetType (), "test#08" );
94 col = new DataColumn ("Auto3");
95 col.AutoIncrement = true;
96 col.AutoIncrementSeed = 0;
97 col.AutoIncrementStep = 1;
98 col.DataType = typeof(string);
99 Assert.AreEqual (typeof (string), col.DataType, "test#09");
100 Assert.IsFalse (col.AutoIncrement, "test#10");
108 DataRow Row = _tbl.NewRow ();
109 DataRowCollection Rows = _tbl.Rows;
112 Assert.AreEqual (1, Rows.Count, "test#01");
113 Assert.IsFalse (Rows.IsReadOnly, "test#02");
114 Assert.IsFalse (Rows.IsSynchronized, "test#03");
115 Assert.AreEqual ("System.Data.DataRowCollection", Rows.ToString (), "test#04");
117 string [] cols = new string [2];
122 cols [0] = "something";
126 Assert.AreEqual (3, Rows.Count, "test#05");
127 Assert.AreEqual ("System.Data.DataRow", Rows [0].ToString (), "test#06");
128 Assert.AreEqual (DBNull.Value, Rows [0] [0], "test#07");
129 Assert.AreEqual (DBNull.Value, Rows [0] [1], "test#08");
130 Assert.AreEqual ("first", Rows [1] [0], "test#09");
131 Assert.AreEqual ("something", Rows [2] [0], "test#10");
132 Assert.AreEqual ("second", Rows [1] [1], "test#11");
133 Assert.AreEqual ("else", Rows [2] [1], "test#12");
137 Assert.Fail ("test#13");
138 } catch (Exception e) {
139 Assert.AreEqual (typeof (ArgumentException), e.GetType (), "test#14");
140 // Never premise English.
141 //Assert.AreEqual ("This row already belongs to this table.", e.Message, "test#15");
147 Assert.Fail ("test#16");
148 } catch (Exception e) {
149 Assert.AreEqual (typeof (ArgumentNullException), e.GetType (), "test#17");
150 //Assert.AreEqual ("'row' argument cannot be null.\r\nParameter name: row", e.Message, "test#18");
153 DataColumn Column = new DataColumn ("not_null");
154 Column.AllowDBNull = false;
155 _tbl.Columns.Add (Column);
157 cols = new string [3];
164 Assert.Fail ("test#19");
165 } catch (Exception e) {
166 Assert.AreEqual (typeof (NoNullAllowedException), e.GetType (), "test#20");
167 //Assert.AreEqual ("Column 'not_null' does not allow nulls.", e.Message, "test#21");
170 Column = _tbl.Columns [0];
171 Column.Unique = true;
173 cols = new string [3];
180 Assert.Fail ("test#22");
181 } catch (Exception e) {
182 Assert.AreEqual (typeof (ConstraintException), e.GetType (), "test#23");
183 // Never premise English.
184 //Assert.AreEqual ("Column 'Column1' is constrained to be unique. Value 'first' is already present.", e.Message, "test#24");
187 Column = new DataColumn ("integer");
188 Column.DataType = typeof (short);
189 _tbl.Columns.Add (Column);
191 object [] obs = new object [4];
199 Assert.Fail ("test#25");
200 } catch (ArgumentException e) {
201 // LAMESPEC: MSDN says this exception is InvalidCastException
202 // Assert.AreEqual (typeof (ArgumentException), e.GetType (), "test#26");
205 object [] obs1 = new object [5];
213 Assert.Fail ("test#27");
214 } catch (Exception e) {
215 Assert.AreEqual (typeof(ArgumentException), e.GetType (), "test#28");
220 public void Add_ByValuesNullTest ()
222 DataTable t = new DataTable ("test");
223 t.Columns.Add ("id", typeof (int));
224 t.Columns.Add ("name", typeof (string));
225 t.Columns.Add ("nullable", typeof (string));
227 t.Columns [0].AutoIncrement = true;
228 t.Columns [0].AutoIncrementSeed = 10;
229 t.Columns [0].AutoIncrementStep = 5;
231 t.Columns [1].DefaultValue = "testme";
234 // null test & missing columns
235 DataRow r = t.Rows.Add (new object [] { null, null});
236 Assert.AreEqual (10, (int) r [0], "#ABV1");
237 Assert.AreEqual ("testme", (string) r [1], "#ABV2");
238 Assert.AreEqual (DBNull.Value, r [2], "#ABV3");
241 r = t.Rows.Add (new object [] { DBNull.Value, DBNull.Value, DBNull.Value});
242 Assert.AreEqual (DBNull.Value, r [0], "#ABV4");
243 Assert.AreEqual (DBNull.Value, r [1], "#ABV5");
244 Assert.AreEqual (DBNull.Value, r [2], "#ABV6");
246 // ai test & no default value test
247 r = t.Rows.Add (new object [] { null, null, null});
248 Assert.AreEqual (15, (int) r [0], "#ABV7");
249 Assert.AreEqual ("testme", (string) r [1], "#ABV8");
250 Assert.AreEqual (DBNull.Value, r [2], "#ABV9");
256 DataRowCollection Rows = _tbl.Rows;
257 DataTable Table = new DataTable ("child");
258 Table.Columns.Add ("first", typeof (int));
259 Table.Columns.Add ("second", typeof (string));
261 _tbl.Columns.Add ("first", typeof (int));
262 _tbl.Columns.Add ("second", typeof (float));
264 string [] cols = new string [2];
277 Assert.AreEqual (3, Rows.Count, "test#01");
280 // hmm... TODO: better tests
281 Assert.AreEqual (0, Rows.Count, "test#02");
297 Table.Rows.Add (cols);
301 Table.Rows.Add (cols);
305 Table.Rows.Add (cols);
307 DataRelation Rel = new DataRelation ("REL", _tbl.Columns [0], Table.Columns [0]);
308 DataSet Set = new DataSet ();
309 Set.Tables.Add (_tbl);
310 Set.Tables.Add (Table);
311 Set.Relations.Add (Rel);
315 Assert.Fail ("test#03");
316 } catch (InvalidConstraintException) {
319 Assert.AreEqual (3, Table.Rows.Count, "test#06");
321 Assert.AreEqual (0, Table.Rows.Count, "test#07");
325 public void Contains ()
327 DataColumn C = new DataColumn ("key");
329 C.DataType = typeof (int);
330 C.AutoIncrement = true;
331 C.AutoIncrementSeed = 0;
332 C.AutoIncrementStep = 1;
333 _tbl.Columns.Add (C);
334 _tbl.Columns.Add ("first", typeof (string));
335 _tbl.Columns.Add ("second", typeof (decimal));
337 DataRowCollection Rows = _tbl.Rows;
339 DataRow Row = _tbl.NewRow ();
341 Row = _tbl.NewRow ();
343 Row = _tbl.NewRow ();
345 Row = _tbl.NewRow ();
348 Rows [0] [1] = "test0";
350 Rows [1] [1] = "test1";
352 Rows [2] [1] = "test2";
354 Rows [3] [1] = "test3";
357 Assert.AreEqual (3, _tbl.Columns.Count, "test#01");
358 Assert.AreEqual (4, _tbl.Rows.Count, "test#02");
359 Assert.AreEqual (0, _tbl.Rows [0] [0], "test#03");
360 Assert.AreEqual (1, _tbl.Rows [1] [0], "test#04");
361 Assert.AreEqual (2, _tbl.Rows [2] [0], "test#05");
362 Assert.AreEqual (3, _tbl.Rows [3] [0], "test#06");
366 Assert.Fail ("test#07");
367 } catch (Exception e) {
368 Assert.AreEqual (typeof (MissingPrimaryKeyException), e.GetType (), "test#08");
369 // Never premise English.
370 //Assert.AreEqual ("Table doesn't have a primary key.", e.Message, "test#09");
373 _tbl.PrimaryKey = new DataColumn [] {_tbl.Columns [0]};
374 Assert.IsTrue (Rows.Contains (1), "test#10");
375 Assert.IsTrue (Rows.Contains (2), "test#11");
376 Assert.IsFalse (Rows.Contains (4), "test#12");
379 Rows.Contains (new object [] {64, "test0"});
380 Assert.Fail ("test#13");
381 } catch (Exception e) {
382 Assert.AreEqual (typeof (ArgumentException), e.GetType (), "test#14");
383 // Never premise English.
384 //Assert.AreEqual ("Expecting 1 value(s) for the key being indexed, but received 2 value(s).", e.Message, "test#15");
387 _tbl.PrimaryKey = new DataColumn [] {_tbl.Columns [0], _tbl.Columns [1]};
388 Assert.IsFalse (Rows.Contains (new object [] {64, "test0"}), "test#16");
389 Assert.IsFalse (Rows.Contains (new object [] {0, "test1"}), "test#17");
390 Assert.IsTrue (Rows.Contains (new object [] {1, "test1"}), "test#18");
391 Assert.IsTrue (Rows.Contains (new object [] {2, "test2"}), "test#19");
394 Rows.Contains (new object [] {2});
395 Assert.Fail ("test#20");
396 } catch (Exception e) {
397 Assert.AreEqual (typeof (ArgumentException), e.GetType (), "test#21");
398 // Never premise English.
399 //Assert.AreEqual ("Expecting 2 value(s) for the key being indexed, but received 1 value(s).", e.Message, "test#22");
404 public void CopyTo ()
410 DataRowCollection Rows = _tbl.Rows;
412 Rows.Add (new object [] {"1", "1", "1"});
413 Rows.Add (new object [] {"2", "2", "2"});
414 Rows.Add (new object [] {"3", "3", "3"});
415 Rows.Add (new object [] {"4", "4", "4"});
416 Rows.Add (new object [] {"5", "5", "5"});
417 Rows.Add (new object [] {"6", "6", "6"});
418 Rows.Add (new object [] {"7", "7", "7"});
420 DataRow [] dr = new DataRow [10];
424 Assert.Fail ("test#01");
425 } catch (Exception e) {
426 Assert.AreEqual (typeof (ArgumentException), e.GetType (), "test#02");
427 //Assert.AreEqual ("Destination array was not long enough. Check destIndex and length, and the array's lower bounds.", e.Message, "test#03");
430 dr = new DataRow [11];
433 Assert.IsNull (dr [0], "test#04");
434 Assert.IsNull (dr [1], "test#05");
435 Assert.IsNull (dr [2], "test#06");
436 Assert.IsNull (dr [3], "test#07");
437 Assert.AreEqual ("1", dr [4] [0], "test#08");
438 Assert.AreEqual ("2", dr [5] [0], "test#09");
439 Assert.AreEqual ("3", dr [6] [0], "test#10");
440 Assert.AreEqual ("4", dr [7] [0], "test#11");
441 Assert.AreEqual ("5", dr [8] [0], "test#12");
442 Assert.AreEqual ("6", dr [9] [0], "test#13");
446 public void Equals ()
452 DataRowCollection Rows1 = _tbl.Rows;
454 Rows1.Add (new object [] {"1", "1", "1"});
455 Rows1.Add (new object [] {"2", "2", "2"});
456 Rows1.Add (new object [] {"3", "3", "3"});
457 Rows1.Add (new object [] {"4", "4", "4"});
458 Rows1.Add (new object [] {"5", "5", "5"});
459 Rows1.Add (new object [] {"6", "6", "6"});
460 Rows1.Add (new object [] {"7", "7", "7"});
462 DataRowCollection Rows2 = _tbl.Rows;
464 Assert.IsTrue (Rows2.Equals (Rows1), "test#01");
465 Assert.IsTrue (Rows1.Equals (Rows2), "test#02");
466 Assert.IsTrue (Rows1.Equals (Rows1), "test#03");
468 DataTable Table = new DataTable ();
469 Table.Columns.Add ();
470 Table.Columns.Add ();
471 Table.Columns.Add ();
472 DataRowCollection Rows3 = Table.Rows;
474 Rows3.Add (new object [] {"1", "1", "1"});
475 Rows3.Add (new object [] {"2", "2", "2"});
476 Rows3.Add (new object [] {"3", "3", "3"});
477 Rows3.Add (new object [] {"4", "4", "4"});
478 Rows3.Add (new object [] {"5", "5", "5"});
479 Rows3.Add (new object [] {"6", "6", "6"});
480 Rows3.Add (new object [] {"7", "7", "7"});
482 Assert.IsFalse (Rows3.Equals (Rows1), "test#04");
483 Assert.IsFalse (Rows3.Equals (Rows2), "test#05");
484 Assert.IsFalse (Rows1.Equals (Rows3), "test#06");
485 Assert.IsFalse (Rows2.Equals (Rows3), "test#07");
491 DataColumn Col = new DataColumn ("test_1");
492 Col.AllowDBNull = false;
494 Col.DataType = typeof (long);
495 _tbl.Columns.Add (Col);
497 Col = new DataColumn ("test_2");
498 Col.DataType = typeof (string);
499 _tbl.Columns.Add (Col);
501 DataRowCollection Rows = _tbl.Rows;
503 Rows.Add (new object [] {1, "first"});
504 Rows.Add (new object [] {2, "second"});
505 Rows.Add (new object [] {3, "third"});
506 Rows.Add (new object [] {4, "fourth"});
507 Rows.Add (new object [] {5, "fifth"});
511 Assert.Fail ("test#01");
512 } catch (Exception e) {
513 Assert.AreEqual (typeof (MissingPrimaryKeyException), e.GetType (), "test#02");
514 // Never premise English.
515 //Assert.AreEqual ("Table doesn't have a primary key.", e.Message, "test#03");
518 _tbl.PrimaryKey = new DataColumn [] {_tbl.Columns [0]};
519 DataRow row = Rows.Find (1);
520 Assert.AreEqual (1L, row [0], "test#04");
522 Assert.AreEqual (2L, row [0], "test#05");
523 row = Rows.Find ("2");
524 Assert.AreEqual (2L, row [0], "test#06");
527 row = Rows.Find ("test");
528 Assert.Fail ("test#07");
529 } catch (Exception e) {
530 Assert.AreEqual (typeof (FormatException), e.GetType (), "test#08");
531 //Assert.AreEqual ("Input string was not in a correct format.", e.Message, "test#09");
535 row = Rows.Find (tes);
536 Assert.IsNull (row, "test#10");
537 _tbl.PrimaryKey = null;
540 Rows.Find (new object [] {1, "fir"});
541 Assert.Fail ("test#11");
542 } catch (Exception e) {
543 Assert.AreEqual (typeof (MissingPrimaryKeyException), e.GetType (), "test#12");
544 // Never premise English.
545 //Assert.AreEqual ("Table doesn't have a primary key.", e.Message, "tets#13");
548 _tbl.PrimaryKey = new DataColumn [] {_tbl.Columns [0], _tbl.Columns [1]};
552 Assert.Fail ("test#14");
553 } catch (Exception e) {
554 Assert.AreEqual (typeof (ArgumentException), e.GetType (), "test#15");
555 // Never premise English.
556 //Assert.AreEqual ("Expecting 2 value(s) for the key being indexed, but received 1 value(s).", e.Message, "test#16");
559 row = Rows.Find (new object [] {1, "fir"});
560 Assert.IsNull (row, "test#16");
561 row = Rows.Find (new object [] {1, "first"});
562 Assert.AreEqual (1L, row [0], "test#17");
568 DataSet ds = new DataSet ();
569 ds.EnforceConstraints = false;
571 DataTable dt = new DataTable ();
574 DataColumn dc = new DataColumn ("Column A");
577 dt.PrimaryKey = new DataColumn [] {dc};
579 DataRow dr = dt.NewRow ();
591 DataRow row = (DataRow) ds.Tables [0].Rows.Find (new object [] {"a"});
593 Assert.IsNotNull (row);
597 public void InsertAt ()
602 DataRowCollection Rows = _tbl.Rows;
604 Rows.Add (new object [] {"a", "aa", "aaa"});
605 Rows.Add (new object [] {"b", "bb", "bbb"});
606 Rows.Add (new object [] {"c", "cc", "ccc"});
607 Rows.Add (new object [] {"d", "dd", "ddd"});
609 DataRow Row = _tbl.NewRow ();
615 Rows.InsertAt (Row, -1);
616 Assert.Fail ("test#01");
617 } catch (Exception e) {
618 Assert.AreEqual (typeof (IndexOutOfRangeException), e.GetType (), "test#02");
619 // Never premise English.
620 //Assert.AreEqual ("The row insert position -1 is invalid.", e.Message, "test#03");
623 Rows.InsertAt (Row, 0);
624 Assert.AreEqual ("e", Rows [0][0], "test#04");
625 Assert.AreEqual ("a", Rows [1][0], "test#05");
627 Row = _tbl.NewRow ();
632 Rows.InsertAt (Row, 5);
633 Assert.AreEqual ("f", Rows [5][0], "test#06");
635 Row = _tbl.NewRow ();
640 Rows.InsertAt (Row, 500);
641 Assert.AreEqual ("g", Rows [6][0], "test#07");
644 Rows.InsertAt (Row, 6); //Row already belongs to the table
645 Assert.Fail ("test#08");
647 catch (Exception e) {
648 Assert.AreEqual (typeof (ArgumentException), e.GetType (), "test#09");
649 // Never premise English.
650 //Assert.AreEqual ("This row already belongs to this table.", e.Message, "test#10");
653 DataTable table = new DataTable ();
654 DataColumn col = new DataColumn ("Name");
655 table.Columns.Add (col);
656 Row = table.NewRow ();
657 Row ["Name"] = "Abc";
658 table.Rows.Add (Row);
660 Rows.InsertAt (Row, 6);
661 Assert.Fail ("test#11");
663 catch (Exception e) {
664 Assert.AreEqual (typeof (ArgumentException), e.GetType (), "test#12");
665 // Never premise English.
666 //Assert.AreEqual ("This row already belongs to another table.", e.Message, "test#13");
669 table = new DataTable ();
670 col = new DataColumn ("Name");
671 col.DataType = typeof (string);
672 table.Columns.Add (col);
673 UniqueConstraint uk = new UniqueConstraint (col);
674 table.Constraints.Add (uk);
676 Row = table.NewRow ();
677 Row ["Name"] = "aaa";
678 table.Rows.InsertAt (Row, 0);
680 Row = table.NewRow ();
681 Row ["Name"] = "aaa";
683 table.Rows.InsertAt (Row, 1);
684 Assert.Fail ("test#14");
686 catch (Exception e) {
687 Assert.AreEqual (typeof (ConstraintException), e.GetType (), "test#15");
690 table.Rows.InsertAt (null, 1);
692 catch (Exception e) {
693 Assert.AreEqual (typeof (ArgumentNullException), e.GetType (), "test#16");
698 public void Remove ()
703 DataRowCollection Rows = _tbl.Rows;
705 Rows.Add (new object [] {"a", "aa", "aaa"});
706 Rows.Add (new object [] {"b", "bb", "bbb"});
707 Rows.Add (new object [] {"c", "cc", "ccc"});
708 Rows.Add (new object [] {"d", "dd", "ddd"});
710 Assert.AreEqual (4, _tbl.Rows.Count, "test#01");
712 Rows.Remove (_tbl.Rows [1]);
713 Assert.AreEqual (3, _tbl.Rows.Count, "test#02");
714 Assert.AreEqual ("a", _tbl.Rows [0] [0], "test#03");
715 Assert.AreEqual ("c", _tbl.Rows [1] [0], "test#04");
716 Assert.AreEqual ("d", _tbl.Rows [2] [0], "test#05");
720 Assert.Fail ("test#06");
721 } catch (Exception e) {
722 Assert.AreEqual (typeof (IndexOutOfRangeException), e.GetType (), "test#07");
723 // Never premise English.
724 //Assert.AreEqual ("The given datarow is not in the current DataRowCollection.", e.Message, "test#08");
727 DataRow Row = new DataTable ().NewRow ();
731 Assert.Fail ("test#09");
732 } catch (Exception e) {
733 Assert.AreEqual (typeof (IndexOutOfRangeException), e.GetType (), "test#10");
734 // Never premise English.
735 //Assert.AreEqual ("The given datarow is not in the current DataRowCollection.", e.Message, "test#11");
740 Assert.Fail ("test#12");
741 } catch (Exception e) {
742 Assert.AreEqual (typeof (IndexOutOfRangeException), e.GetType (), "test#13");
743 // Never premise English.
744 //Assert.AreEqual ("There is no row at position -1.", e.Message, "test#14");
749 Assert.Fail ("test#15");
750 } catch (Exception e) {
751 Assert.AreEqual (typeof (IndexOutOfRangeException), e.GetType (), "test#16");
752 // Never premise English.
753 //Assert.AreEqual ("There is no row at position 64.", e.Message, "test#17");
758 Assert.AreEqual (1, Rows.Count, "test#18");
759 Assert.AreEqual ("c", Rows [0] [0], "test#19");
763 public void IndexOf () {
764 DataSet ds = new DataSet ();
766 DataTable dt = new DataTable ();
769 DataColumn dc = new DataColumn ("Column A");
772 dt.PrimaryKey = new DataColumn[] { dc };
774 DataRow dr1 = dt.NewRow ();
778 DataRow dr2 = dt.NewRow ();
782 DataRow dr3 = dt.NewRow ();
786 DataRow dr4 = dt.NewRow ();
790 DataRow dr5 = dt.NewRow ();
793 int index = ds.Tables[0].Rows.IndexOf (dr3);
794 Assert.AreEqual (2, index, "IndexOf-Yes");
796 index = ds.Tables[0].Rows.IndexOf (dr5);
797 Assert.AreEqual (-1, index, "IndexOf-No");
800 public void IndexOfTest()
802 DataTable dt = new DataTable("TestWriteXmlSchema");
803 dt.Columns.Add("Col1", typeof(int));
804 dt.Columns.Add("Col2", typeof(int));
805 DataRow dr = dt.NewRow();
809 DataRow dr1 = dt.NewRow();
813 DataRow dr2 = dt.NewRow();
817 Assert.AreEqual (1, dt.Rows.IndexOf (dr1));
818 DataTable dt1 = new DataTable("HelloWorld");
819 dt1.Columns.Add("T1", typeof(int));
820 dt1.Columns.Add("T2", typeof(int));
821 DataRow dr3 = dt1.NewRow();
825 Assert.AreEqual (-1, dt.Rows.IndexOf (dr3));
826 Assert.AreEqual (-1, dt.Rows.IndexOf (null));
830 public void Find_DoesntThrowWithNullObjectInArray () // Novell bug 519648
832 var dt = new DataTable ("datatable");
834 var column = new DataColumn ();
835 dt.Columns.Add (column);
836 var columns = new DataColumn [] { column };
837 dt.PrimaryKey = columns;
840 Assert.AreEqual (null, dt.Rows.Find (new object [] { null }));
841 } catch (IndexOutOfRangeException) {
842 Assert.Fail ("Bug #519648 (https://bugzilla.novell.com/show_bug.cgi?id=519648) is not fixed.");
847 public void Find_DoesntThrowWithNullObject () // Novell bug 519648
849 var dt = new DataTable ("datatable");
851 var column = new DataColumn ();
852 dt.Columns.Add (column);
853 var columns = new DataColumn [] { column };
854 dt.PrimaryKey = columns;
857 Assert.AreEqual (null, dt.Rows.Find ( (object)null));
858 } catch (IndexOutOfRangeException) {
859 Assert.Fail ("Bug #519648 (https://bugzilla.novell.com/show_bug.cgi?id=519648) is not fixed.");