2005-08-16 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / class / System.Data / Test / System.Data / DataRowCollectionTest2.cs
1 // Authors:
2 //   Rafael Mizrahi   <rafim@mainsoft.com>
3 //   Erez Lotan       <erezl@mainsoft.com>
4 //   Oren Gurfinkel   <oreng@mainsoft.com>
5 //   Ofer Borstein
6 // 
7 // Copyright (c) 2004 Mainsoft Co.
8 // 
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:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
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.
27 //
28
29 using NUnit.Framework;
30 using System;
31 using System.IO;
32 using System.Collections;
33 using System.ComponentModel;
34 using System.Data;
35 using MonoTests.System.Data.Utils;
36
37 namespace MonoTests.System.Data
38 {
39         [TestFixture] public class DataRowCollectionTest2
40         {
41                 [Test] public void CopyTo()
42                 {
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");
47
48                         int index=0;
49                         foreach (DataRow dr in dt.Rows)
50                         {
51                                 Assert.AreEqual(dr, arr[index], "DRWC2");
52                                 index++;
53                         }
54                 }
55
56                 [Test] public void Count()
57                 {
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");
64                 }
65
66                 [Test] public void GetEnumerator()
67                 {
68                         DataTable dt = DataProvider.CreateParentDataTable();
69                         IEnumerator myEnumerator = dt.Rows.GetEnumerator();
70                         int index=0;
71                         while (myEnumerator.MoveNext())
72                         {
73                                 Assert.AreEqual(dt.Rows[index], (DataRow)myEnumerator.Current, "DRWC6");
74                                 index++;
75                         }
76                         Assert.AreEqual(index, dt.Rows.Count, "DRWC7");
77                 }
78
79                 [Test] public void RemoveAt_ByIndex()
80                 {
81                         DataTable dt = DataProvider.CreateParentDataTable();
82                         int counter = dt.Rows.Count;
83                         dt.PrimaryKey=  new DataColumn[] {dt.Columns[0]};
84                         dt.Rows.RemoveAt(3);
85                         Assert.AreEqual(counter-1, dt.Rows.Count, "DRWC8");
86                         Assert.AreEqual(null, dt.Rows.Find(4), "DRWC9");
87                 }
88
89                 [Test] public void Remove_ByDataRow()
90                 {
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");
98                 }
99         }
100 }