* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Data / Test / System.Data.Tests.Mainsoft / System.Data / ForeignKeyConstraint / ForeignKeyConstraint_ctor_DclmsDclms.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
31
32 using System;
33 using System.Data;
34
35 using GHTUtils;
36 using GHTUtils.Base;
37
38 namespace tests.system_data_dll.System_Data
39 {
40 [TestFixture] public class ForeignKeyConstraint_ctor_DclmsDclms : GHTBase
41 {
42         [Test] public void Main()
43         {
44                 ForeignKeyConstraint_ctor_DclmsDclms tc = new ForeignKeyConstraint_ctor_DclmsDclms();
45                 Exception exp = null;
46                 try
47                 {
48                         tc.BeginTest("ForeignKeyConstraint_ctor_DclmsDclms");
49                         tc.run();
50                 }
51                 catch(Exception ex)
52                 {
53                         exp = ex;
54                 }
55                 finally
56                 {
57                         tc.EndTest(exp);
58                 }
59         }
60
61         //Activate This Construntor to log All To Standard output
62         //public TestClass():base(true){}
63
64         //Activate this constructor to log Failures to a log file
65         //public TestClass(System.IO.TextWriter tw):base(tw, false){}
66
67
68         //Activate this constructor to log All to a log file
69         //public TestClass(System.IO.TextWriter tw):base(tw, true){}
70
71         //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
72
73         public void run()
74         {
75                 Exception exp = null;
76
77
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);
83                 
84                 ForeignKeyConstraint fc = null;
85
86                 try
87                 {
88                         BeginCase("Ctor ArgumentException");
89                         try
90                         {
91                                 fc = new ForeignKeyConstraint(new DataColumn[] {dtParent.Columns[0]} ,new DataColumn[] {dtChild.Columns[0],dtChild.Columns[1]});                                
92                         }
93                         catch (Exception ex)
94                         {
95                                 exp = ex;
96                         }
97                         Compare(exp.GetType().FullName , typeof(ArgumentException).FullName );
98                         exp=null;
99                 }
100                 catch(Exception ex)     {exp = ex;}
101                 finally {EndCase(exp); exp = null;}
102         
103
104                 fc = new ForeignKeyConstraint(new DataColumn[] {dtParent.Columns[0],dtParent.Columns[1]} ,new DataColumn[] {dtChild.Columns[0],dtChild.Columns[2]});                            
105
106                 try
107                 {
108                         BeginCase("Add constraint to table - ArgumentException");
109                         try
110                         {
111                                 dtChild.Constraints.Add(fc);
112                         }
113                         catch (Exception ex)
114                         {
115                                 exp = ex;
116                         }
117                         Compare(exp.GetType().FullName , typeof(ArgumentException).FullName );
118                         exp=null;
119                 }
120                 catch(Exception ex)     {exp = ex;}
121                 finally {EndCase(exp); exp = null;}
122
123                 try
124                 {
125                         BeginCase("Child Table Constraints Count - two columnns");
126                         Compare(dtChild.Constraints.Count ,0);
127                 }
128                 catch(Exception ex)     {exp = ex;}
129                 finally {EndCase(exp); exp = null;}
130
131                 try
132                 {
133                         BeginCase("Parent Table Constraints Count - two columnns");
134                         Compare(dtParent.Constraints.Count ,1);
135                 }
136                 catch(Exception ex)     {exp = ex;}
137                 finally {EndCase(exp); exp = null;}
138                 
139                 try
140                 {
141                         BeginCase("DataSet relations Count");
142                         Compare(ds.Relations.Count ,0);
143                 }
144                 catch(Exception ex)     {exp = ex;}
145                 finally {EndCase(exp); exp = null;}
146
147                 dtParent.Constraints.Clear();
148                 dtChild.Constraints.Clear();
149
150                 fc = new ForeignKeyConstraint(new DataColumn[] {dtParent.Columns[0]} ,new DataColumn[] {dtChild.Columns[0]});
151                 try
152                 {
153                         BeginCase("Ctor");
154                         Compare(fc == null ,false );
155                 }
156                 catch(Exception ex)     {exp = ex;}
157                 finally {EndCase(exp); exp = null;}
158
159                 try
160                 {
161                         BeginCase("Child Table Constraints Count");
162                         Compare(dtChild.Constraints.Count ,0);
163                 }
164                 catch(Exception ex)     {exp = ex;}
165                 finally {EndCase(exp); exp = null;}
166
167                 try
168                 {
169                         BeginCase("Parent Table Constraints Count");
170                         Compare(dtParent.Constraints.Count ,0);
171                 }
172                 catch(Exception ex)     {exp = ex;}
173                 finally {EndCase(exp); exp = null;}
174                 
175                 try
176                 {
177                         BeginCase("DataSet relations Count");
178                         Compare(ds.Relations.Count ,0);
179                 }
180                 catch(Exception ex)     {exp = ex;}
181                 finally {EndCase(exp); exp = null;}
182
183                 dtChild.Constraints.Add(fc);
184
185                 try
186                 {
187                         BeginCase("Child Table Constraints Count, Add");
188                         Compare(dtChild.Constraints.Count ,1);
189                 }
190                 catch(Exception ex)     {exp = ex;}
191                 finally {EndCase(exp); exp = null;}
192
193                 try
194                 {
195                         BeginCase("Parent Table Constraints Count, Add");
196                         Compare(dtParent.Constraints.Count ,1);
197                 }
198                 catch(Exception ex)     {exp = ex;}
199                 finally {EndCase(exp); exp = null;}
200
201                 try
202                 {
203                         BeginCase("DataSet relations Count, Add");
204                         Compare(ds.Relations.Count ,0);
205                 }
206                 catch(Exception ex)     {exp = ex;}
207                 finally {EndCase(exp); exp = null;}
208
209                 try
210                 {
211                         BeginCase("Parent Table Constraints type");
212                         Compare(dtParent.Constraints[0].GetType() ,typeof(UniqueConstraint));
213                 }
214                 catch(Exception ex)     {exp = ex;}
215                 finally {EndCase(exp); exp = null;}
216
217                 try
218                 {
219                         BeginCase("Parent Table Constraints type");
220                         Compare(dtChild.Constraints[0].GetType() ,typeof(ForeignKeyConstraint));
221                 }
222                 catch(Exception ex)     {exp = ex;}
223                 finally {EndCase(exp); exp = null;}
224
225                 try
226                 {
227                         BeginCase("Parent Table Primary key");
228                         Compare(dtParent.PrimaryKey.Length ,0);
229                 }
230                 catch(Exception ex)     {exp = ex;}
231                 finally {EndCase(exp); exp = null;}
232
233                 
234                 dtChild.Constraints.Clear();
235                 dtParent.Constraints.Clear();
236                 ds.Relations.Add(new DataRelation("myRelation",dtParent.Columns[0],dtChild.Columns[0]));
237
238                 try
239                 {
240                         BeginCase("Relation - Child Table Constraints Count");
241                         Compare(dtChild.Constraints.Count ,1);
242                 }
243                 catch(Exception ex)     {exp = ex;}
244                 finally {EndCase(exp); exp = null;}
245
246                 try
247                 {
248                         BeginCase("Relation - Parent Table Constraints Count");
249                         Compare(dtParent.Constraints.Count ,1);
250                 }
251                 catch(Exception ex)     {exp = ex;}
252                 finally {EndCase(exp); exp = null;}
253
254                 try
255                 {
256                         BeginCase("Relation - Parent Table Constraints type");
257                         Compare(dtParent.Constraints[0].GetType() ,typeof(UniqueConstraint));
258                 }
259                 catch(Exception ex)     {exp = ex;}
260                 finally {EndCase(exp); exp = null;}
261
262                 try
263                 {
264                         BeginCase("Relation - Parent Table Constraints type");
265                         Compare(dtChild.Constraints[0].GetType() ,typeof(ForeignKeyConstraint));
266                 }
267                 catch(Exception ex)     {exp = ex;}
268                 finally {EndCase(exp); exp = null;}
269
270                 try
271                 {
272                         BeginCase("Relation - Parent Table Primary key");
273                         Compare(dtParent.PrimaryKey.Length ,0);
274                 }
275                 catch(Exception ex)     {exp = ex;}
276                 finally {EndCase(exp); exp = null;}
277
278
279
280
281         }
282 }
283 }