2 // Rafael Mizrahi <rafim@mainsoft.com>
3 // Erez Lotan <erezl@mainsoft.com>
4 // Oren Gurfinkel <oreng@mainsoft.com>
7 // Copyright (c) 2004 Mainsoft Co.
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using NUnit.Framework;
32 using System.Collections;
33 using System.ComponentModel;
35 using MonoTests.System.Data.Utils;
37 namespace MonoTests.System.Data
39 [TestFixture] public class DataRowCollectionTest2
41 [Test] public void CopyTo()
43 DataTable dt = DataProvider.CreateParentDataTable();
44 DataRow[] arr = new DataRow[dt.Rows.Count];
45 dt.Rows.CopyTo(arr,0);
46 Assert.AreEqual(dt.Rows.Count, arr.Length, "DRWC1");
49 foreach (DataRow dr in dt.Rows)
51 Assert.AreEqual(dr, arr[index], "DRWC2");
56 [Test] public void Count()
58 DataTable dt = DataProvider.CreateParentDataTable();
59 Assert.AreEqual(6, dt.Rows.Count, "DRWC3");
60 dt.Rows.Remove(dt.Rows[0]);
61 Assert.AreEqual(5, dt.Rows.Count, "DRWC4");
62 dt.Rows.Add(new object[] {1,"1-String1","1-String2",new DateTime(2005,1,1,0,0,0,0),1.534,true});
63 Assert.AreEqual(6, dt.Rows.Count, "DRWC5");
66 [Test] public void GetEnumerator()
68 DataTable dt = DataProvider.CreateParentDataTable();
69 IEnumerator myEnumerator = dt.Rows.GetEnumerator();
71 while (myEnumerator.MoveNext())
73 Assert.AreEqual(dt.Rows[index], (DataRow)myEnumerator.Current, "DRWC6");
76 Assert.AreEqual(index, dt.Rows.Count, "DRWC7");
79 [Test] public void RemoveAt_ByIndex()
81 DataTable dt = DataProvider.CreateParentDataTable();
82 int counter = dt.Rows.Count;
83 dt.PrimaryKey= new DataColumn[] {dt.Columns[0]};
85 Assert.AreEqual(counter-1, dt.Rows.Count, "DRWC8");
86 Assert.AreEqual(null, dt.Rows.Find(4), "DRWC9");
89 [Test] public void Remove_ByDataRow()
91 DataTable dt = DataProvider.CreateParentDataTable();
92 int counter = dt.Rows.Count;
93 dt.PrimaryKey= new DataColumn[] {dt.Columns[0]};
94 Assert.AreEqual(dt.Rows[0], dt.Rows.Find(1), "DRWC10");
95 dt.Rows.Remove(dt.Rows[0]);
96 Assert.AreEqual(counter-1, dt.Rows.Count, "DRWC11");
97 Assert.AreEqual(null, dt.Rows.Find(1), "DRWC12");