* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Data / Test / System.Data.Tests.Mainsoft / System.Data / DataRow / DataRow_SetParentRow_D.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.Data;
32
33 using GHTUtils;
34 using GHTUtils.Base;
35
36 namespace tests.system_data_dll.System_Data
37 {
38 [TestFixture] public class DataRow_SetParentRow_D : GHTBase
39 {
40         [Test] public void Main()
41         {
42                 DataRow_SetParentRow_D tc = new DataRow_SetParentRow_D();
43                 Exception exp = null;
44                 try
45                 {
46                         tc.BeginTest("DataRow_SetParentRow_D");
47                         tc.run();
48                 }
49                 catch(Exception ex)
50                 {
51                         exp = ex;
52                 }
53                 finally
54                 {
55                         tc.EndTest(exp);
56                 }
57         }
58
59         //Activate This Construntor to log All To Standard output
60         //public TestClass():base(true){}
61
62         //Activate this constructor to log Failures to a log file
63         //public TestClass(System.IO.TextWriter tw):base(tw, false){}
64
65
66         //Activate this constructor to log All to a log file
67         //public TestClass(System.IO.TextWriter tw):base(tw, true){}
68
69         //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
70
71         public void run()
72         {
73                 Exception exp = null;
74
75                 DataRow drParent,drChild;
76                 DataRow drArrExcepted,drArrResult;
77                 DataTable dtChild,dtParent;
78                 DataSet ds = new DataSet();
79                 //Create tables
80                 dtChild = GHTUtils.DataProvider.CreateChildDataTable();
81                 dtParent= GHTUtils.DataProvider.CreateParentDataTable(); 
82                 //Add tables to dataset
83                 ds.Tables.Add(dtChild);
84                 ds.Tables.Add(dtParent);
85                 //Add Relation
86                 DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
87                 ds.Relations.Add(dRel);
88
89                 drParent = dtParent.Rows[0];
90                 drChild = dtChild.Select("ParentId=" + drParent["ParentId"])[0];
91
92                 drChild.SetParentRow(drParent);
93                                 
94                 //Get Excepted result
95                 drArrExcepted = drParent;
96                 //Get Result DataRowVersion.Current
97                 drArrResult = drChild.GetParentRow("Parent-Child",DataRowVersion.Current);
98                                 
99                 try
100                 {
101                         BeginCase("SetParentRow");
102                         base.Compare( drArrResult, drArrExcepted );
103                 }
104                 catch(Exception ex)     {exp = ex;}
105                 finally {EndCase(exp); exp = null;}
106                 
107         }
108         public void testMore()
109         {
110                 DataSet ds = DataProvider.CreateForigenConstraint();
111                 DataRow drParent = ds.Tables[0].Rows[0];
112                 try
113                 {
114                         //DataRow[] drArray =  ds.Tables[1].Rows[0].GetParentRows(ds.Tables[1].ParentRelations[0]);
115                         ds.Tables[1].Rows[0].SetParentRow(drParent);
116                         
117                 }
118                 catch (Exception ex)
119                 {
120                         throw ex;
121                 }
122                 
123         }
124         public void test()
125         {
126                 BeginCase("test SetParentRow");
127                 DataTable parent = DataProvider.CreateParentDataTable();
128                 DataTable child = DataProvider.CreateChildDataTable();
129                 DataRow dr = parent.Rows[0];
130                 dr.Delete();
131                 parent.AcceptChanges();
132
133                 try
134                 {
135                         child.Rows[0].SetParentRow(dr);
136                 }
137                 catch (Exception ex)
138                 {
139                         throw ex;
140                 }
141         }
142
143         public void checkForLoops()
144         {
145                 DataSet ds = new DataSet();
146                 //Create tables
147                 DataTable  dtChild = GHTUtils.DataProvider.CreateChildDataTable();
148                 DataTable dtParent= GHTUtils.DataProvider.CreateParentDataTable(); 
149                 //Add tables to dataset
150                 ds.Tables.Add(dtChild);
151                 ds.Tables.Add(dtParent);
152
153                 dtChild.Rows.Clear();
154                 dtParent.Rows.Clear();
155
156                 dtParent.ChildRelations.Add(dtParent.Columns[0],dtChild.Columns[0]);
157                 try
158                 {
159                         dtChild.ChildRelations.Add(dtChild.Columns[0],dtParent.Columns[0]);
160                 }
161                 catch (Exception ex)
162                 {
163                         throw ex;
164                 }
165
166                 dtChild.Rows[0].SetParentRow(dtParent.Rows[0]);
167                 dtParent.Rows[0].SetParentRow(dtChild.Rows[0]);
168
169         
170
171         }
172
173         public void checkForLoopsAdvenced()
174         {
175                 
176                 //Create tables
177                 DataTable  dtChild = new DataTable();
178                 dtChild.Columns.Add("Col1",typeof(int));
179                 dtChild.Columns.Add("Col2",typeof(int));
180
181
182                 try
183                 {
184                         DataRelation drl = new DataRelation("drl1",dtChild.Columns[0],dtChild.Columns[1]);
185                         dtChild.ChildRelations.Add(drl);
186                 }
187                 catch (Exception ex)
188                 {
189                         throw ex;
190                 }
191                 dtChild.Rows[0].SetParentRow(dtChild.Rows[1]);
192                 dtChild.Rows[1].SetParentRow(dtChild.Rows[0]);
193
194         
195
196         }
197 }
198 }