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 ForeignKeyConstraint_ctor_DclmsDclms : GHTBase
42 [Test] public void Main()
44 ForeignKeyConstraint_ctor_DclmsDclms tc = new ForeignKeyConstraint_ctor_DclmsDclms();
48 tc.BeginTest("ForeignKeyConstraint_ctor_DclmsDclms");
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
78 DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
79 DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
80 DataSet ds = new DataSet();
81 ds.Tables.Add(dtChild);
82 ds.Tables.Add(dtParent);
84 ForeignKeyConstraint fc = null;
88 BeginCase("Ctor ArgumentException");
91 fc = new ForeignKeyConstraint(new DataColumn[] {dtParent.Columns[0]} ,new DataColumn[] {dtChild.Columns[0],dtChild.Columns[1]});
97 Compare(exp.GetType().FullName , typeof(ArgumentException).FullName );
100 catch(Exception ex) {exp = ex;}
101 finally {EndCase(exp); exp = null;}
104 fc = new ForeignKeyConstraint(new DataColumn[] {dtParent.Columns[0],dtParent.Columns[1]} ,new DataColumn[] {dtChild.Columns[0],dtChild.Columns[2]});
108 BeginCase("Add constraint to table - ArgumentException");
111 dtChild.Constraints.Add(fc);
117 Compare(exp.GetType().FullName , typeof(ArgumentException).FullName );
120 catch(Exception ex) {exp = ex;}
121 finally {EndCase(exp); exp = null;}
125 BeginCase("Child Table Constraints Count - two columnns");
126 Compare(dtChild.Constraints.Count ,0);
128 catch(Exception ex) {exp = ex;}
129 finally {EndCase(exp); exp = null;}
133 BeginCase("Parent Table Constraints Count - two columnns");
134 Compare(dtParent.Constraints.Count ,1);
136 catch(Exception ex) {exp = ex;}
137 finally {EndCase(exp); exp = null;}
141 BeginCase("DataSet relations Count");
142 Compare(ds.Relations.Count ,0);
144 catch(Exception ex) {exp = ex;}
145 finally {EndCase(exp); exp = null;}
147 dtParent.Constraints.Clear();
148 dtChild.Constraints.Clear();
150 fc = new ForeignKeyConstraint(new DataColumn[] {dtParent.Columns[0]} ,new DataColumn[] {dtChild.Columns[0]});
154 Compare(fc == null ,false );
156 catch(Exception ex) {exp = ex;}
157 finally {EndCase(exp); exp = null;}
161 BeginCase("Child Table Constraints Count");
162 Compare(dtChild.Constraints.Count ,0);
164 catch(Exception ex) {exp = ex;}
165 finally {EndCase(exp); exp = null;}
169 BeginCase("Parent Table Constraints Count");
170 Compare(dtParent.Constraints.Count ,0);
172 catch(Exception ex) {exp = ex;}
173 finally {EndCase(exp); exp = null;}
177 BeginCase("DataSet relations Count");
178 Compare(ds.Relations.Count ,0);
180 catch(Exception ex) {exp = ex;}
181 finally {EndCase(exp); exp = null;}
183 dtChild.Constraints.Add(fc);
187 BeginCase("Child Table Constraints Count, Add");
188 Compare(dtChild.Constraints.Count ,1);
190 catch(Exception ex) {exp = ex;}
191 finally {EndCase(exp); exp = null;}
195 BeginCase("Parent Table Constraints Count, Add");
196 Compare(dtParent.Constraints.Count ,1);
198 catch(Exception ex) {exp = ex;}
199 finally {EndCase(exp); exp = null;}
203 BeginCase("DataSet relations Count, Add");
204 Compare(ds.Relations.Count ,0);
206 catch(Exception ex) {exp = ex;}
207 finally {EndCase(exp); exp = null;}
211 BeginCase("Parent Table Constraints type");
212 Compare(dtParent.Constraints[0].GetType() ,typeof(UniqueConstraint));
214 catch(Exception ex) {exp = ex;}
215 finally {EndCase(exp); exp = null;}
219 BeginCase("Parent Table Constraints type");
220 Compare(dtChild.Constraints[0].GetType() ,typeof(ForeignKeyConstraint));
222 catch(Exception ex) {exp = ex;}
223 finally {EndCase(exp); exp = null;}
227 BeginCase("Parent Table Primary key");
228 Compare(dtParent.PrimaryKey.Length ,0);
230 catch(Exception ex) {exp = ex;}
231 finally {EndCase(exp); exp = null;}
234 dtChild.Constraints.Clear();
235 dtParent.Constraints.Clear();
236 ds.Relations.Add(new DataRelation("myRelation",dtParent.Columns[0],dtChild.Columns[0]));
240 BeginCase("Relation - Child Table Constraints Count");
241 Compare(dtChild.Constraints.Count ,1);
243 catch(Exception ex) {exp = ex;}
244 finally {EndCase(exp); exp = null;}
248 BeginCase("Relation - Parent Table Constraints Count");
249 Compare(dtParent.Constraints.Count ,1);
251 catch(Exception ex) {exp = ex;}
252 finally {EndCase(exp); exp = null;}
256 BeginCase("Relation - Parent Table Constraints type");
257 Compare(dtParent.Constraints[0].GetType() ,typeof(UniqueConstraint));
259 catch(Exception ex) {exp = ex;}
260 finally {EndCase(exp); exp = null;}
264 BeginCase("Relation - Parent Table Constraints type");
265 Compare(dtChild.Constraints[0].GetType() ,typeof(ForeignKeyConstraint));
267 catch(Exception ex) {exp = ex;}
268 finally {EndCase(exp); exp = null;}
272 BeginCase("Relation - Parent Table Primary key");
273 Compare(dtParent.PrimaryKey.Length ,0);
275 catch(Exception ex) {exp = ex;}
276 finally {EndCase(exp); exp = null;}