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;
36 namespace tests.system_data_dll.System_Data
38 [TestFixture] public class DataRow_SetParentRow_D : GHTBase
40 [Test] public void Main()
42 DataRow_SetParentRow_D tc = new DataRow_SetParentRow_D();
46 tc.BeginTest("DataRow_SetParentRow_D");
59 //Activate This Construntor to log All To Standard output
60 //public TestClass():base(true){}
62 //Activate this constructor to log Failures to a log file
63 //public TestClass(System.IO.TextWriter tw):base(tw, false){}
66 //Activate this constructor to log All to a log file
67 //public TestClass(System.IO.TextWriter tw):base(tw, true){}
69 //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
75 DataRow drParent,drChild;
76 DataRow drArrExcepted,drArrResult;
77 DataTable dtChild,dtParent;
78 DataSet ds = new DataSet();
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);
86 DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
87 ds.Relations.Add(dRel);
89 drParent = dtParent.Rows[0];
90 drChild = dtChild.Select("ParentId=" + drParent["ParentId"])[0];
92 drChild.SetParentRow(drParent);
95 drArrExcepted = drParent;
96 //Get Result DataRowVersion.Current
97 drArrResult = drChild.GetParentRow("Parent-Child",DataRowVersion.Current);
101 BeginCase("SetParentRow");
102 base.Compare( drArrResult, drArrExcepted );
104 catch(Exception ex) {exp = ex;}
105 finally {EndCase(exp); exp = null;}
108 public void testMore()
110 DataSet ds = DataProvider.CreateForigenConstraint();
111 DataRow drParent = ds.Tables[0].Rows[0];
114 //DataRow[] drArray = ds.Tables[1].Rows[0].GetParentRows(ds.Tables[1].ParentRelations[0]);
115 ds.Tables[1].Rows[0].SetParentRow(drParent);
126 BeginCase("test SetParentRow");
127 DataTable parent = DataProvider.CreateParentDataTable();
128 DataTable child = DataProvider.CreateChildDataTable();
129 DataRow dr = parent.Rows[0];
131 parent.AcceptChanges();
135 child.Rows[0].SetParentRow(dr);
143 public void checkForLoops()
145 DataSet ds = new DataSet();
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);
153 dtChild.Rows.Clear();
154 dtParent.Rows.Clear();
156 dtParent.ChildRelations.Add(dtParent.Columns[0],dtChild.Columns[0]);
159 dtChild.ChildRelations.Add(dtChild.Columns[0],dtParent.Columns[0]);
166 dtChild.Rows[0].SetParentRow(dtParent.Rows[0]);
167 dtParent.Rows[0].SetParentRow(dtChild.Rows[0]);
173 public void checkForLoopsAdvenced()
177 DataTable dtChild = new DataTable();
178 dtChild.Columns.Add("Col1",typeof(int));
179 dtChild.Columns.Add("Col2",typeof(int));
184 DataRelation drl = new DataRelation("drl1",dtChild.Columns[0],dtChild.Columns[1]);
185 dtChild.ChildRelations.Add(drl);
191 dtChild.Rows[0].SetParentRow(dtChild.Rows[1]);
192 dtChild.Rows[1].SetParentRow(dtChild.Rows[0]);