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;
38 namespace tests.system_data_dll.System_Data
40 [TestFixture] public class DataRelation_ctor_SDclmsDclmsB : GHTBase
42 [Test] public void Main()
44 DataRelation_ctor_SDclmsDclmsB tc = new DataRelation_ctor_SDclmsDclmsB();
48 tc.BeginTest("DataRelation_CTor_SDclmsDclmsB");
61 //Activate This Construntor to log All To Standard output
62 //public TestClass():base(true){}
64 //Activate this constructor to log Failures to a log file
65 //public TestClass(System.IO.TextWriter tw):base(tw, false){}
68 //Activate this constructor to log All to a log file
69 //public TestClass(System.IO.TextWriter tw):base(tw, true){}
71 //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
77 DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
78 DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
80 DataSet ds = new DataSet();
81 ds.Tables.Add(dtParent);
82 ds.Tables.Add(dtChild);
84 //parameter createConstraints = true
86 bool createConstraints = true;
87 for (int i=0; i<=1; i++)
90 createConstraints = false;
92 createConstraints = true;
95 dtParent.Constraints.Clear();
96 dtChild.Constraints.Clear();
100 dtParent.Rows.Add(dtParent.Rows[0].ItemArray);
101 dRel = new DataRelation("MyRelation",new DataColumn[] {dtParent.Columns[0]},new DataColumn[] {dtChild.Columns[0]},createConstraints);
104 BeginCase("Add relation which will create invalid constraint,createConstraints=" + createConstraints.ToString());
105 exp = new Exception();
108 ds.Relations.Add(dRel);
110 catch (ArgumentException ex) {exp=ex;}
111 if (createConstraints==true)
112 Compare(exp.GetType().FullName ,typeof(ArgumentException).FullName );
114 Compare(exp.GetType().FullName ,typeof(Exception).FullName );
117 catch(Exception ex) {exp = ex;}
118 finally {EndCase(exp); exp = null;}
120 ds.Relations.Clear();
121 dtParent.Constraints.Clear();
122 dtChild.Constraints.Clear();
123 dtParent.Rows.Remove(dtParent.Rows[dtParent.Rows.Count-1]);
125 dRel = new DataRelation("MyRelation",new DataColumn[] {dtParent.Columns[0]},new DataColumn[] {dtChild.Columns[0]},createConstraints);
126 ds.Relations.Add(dRel);
130 BeginCase("DataRelation - CTor,createConstraints=" + createConstraints.ToString());
131 Compare(dRel == null ,false );
133 catch(Exception ex) {exp = ex;}
134 finally {EndCase(exp); exp = null;}
138 BeginCase("DataRelation - parent Constraints,createConstraints=" + createConstraints.ToString());
139 Compare(dtParent.Constraints.Count ,i);
141 catch(Exception ex) {exp = ex;}
142 finally {EndCase(exp); exp = null;}
146 BeginCase("DataRelation - child Constraints,createConstraints=" + createConstraints.ToString());
147 Compare(dtChild.Constraints.Count ,i);
149 catch(Exception ex) {exp = ex;}
150 finally {EndCase(exp); exp = null;}
154 BeginCase("DataRelation - child relations,createConstraints=" + createConstraints.ToString());
155 Compare(dtParent.ChildRelations[0] ,dRel);
157 catch(Exception ex) {exp = ex;}
158 finally {EndCase(exp); exp = null;}
162 BeginCase("DataRelation - parent relations,createConstraints=" + createConstraints.ToString());
163 Compare(dtChild.ParentRelations[0],dRel );
165 catch(Exception ex) {exp = ex;}
166 finally {EndCase(exp); exp = null;}
170 BeginCase("DataRelation - name");
171 Compare(dRel.RelationName ,"MyRelation" );
173 catch(Exception ex) {exp = ex;}
174 finally {EndCase(exp); exp = null;}