2010-07-25 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / mcs / class / System.Data / Test / System.Data.Tests.Mainsoft / System.Data / RowNotInTableException / RowNotInTableException_Generate.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 //\r
28 \r
29 using NUnit.Framework;
30
31
32 using System;
33 using System.Data;
34
35 using GHTUtils;
36 using GHTUtils.Base;\r
37 \r
38 namespace tests.system_data_dll.System_Data
39 {\r
40 [TestFixture] public class RowNotInTableException_Generate : GHTBase\r
41 {\r
42         [Test] public void Main()\r
43         {\r
44                 RowNotInTableException_Generate tc = new RowNotInTableException_Generate();\r
45                 Exception exp = null;\r
46                 try\r
47                 {\r
48                         tc.BeginTest("RowNotInTableException");\r
49                         tc.run();\r
50                 }\r
51                 catch(Exception ex)\r
52                 {\r
53                         exp = ex;\r
54                 }\r
55                 finally\r
56                 {\r
57                         tc.EndTest(exp);\r
58                 }\r
59         }\r
60 \r
61         //Activate This Construntor to log All To Standard output\r
62         //public TestClass():base(true){}\r
63 \r
64         //Activate this constructor to log Failures to a log file\r
65         //public TestClass(System.IO.TextWriter tw):base(tw, false){}\r
66 \r
67 \r
68         //Activate this constructor to log All to a log file\r
69         //public TestClass(System.IO.TextWriter tw):base(tw, true){}\r
70 \r
71         //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES\r
72 \r
73         public void run()\r
74         {\r
75                 Exception exp = null;\r
76                 Exception tmpEx = new Exception() ;\r
77 \r
78                 DataSet ds = new DataSet();\r
79                 ds.Tables.Add(GHTUtils.DataProvider.CreateParentDataTable());\r
80                 ds.Tables.Add(GHTUtils.DataProvider.CreateChildDataTable());\r
81                 ds.Relations.Add(new DataRelation("myRelation",ds.Tables[0].Columns[0],ds.Tables[1].Columns[0]));\r
82 \r
83                 DataRow drParent = ds.Tables[0].Rows[0];\r
84                 DataRow drChild = ds.Tables[1].Rows[0];\r
85                 drParent.Delete();\r
86                 drChild.Delete();\r
87                 ds.AcceptChanges();\r
88         \r
89                 try\r
90                 {\r
91                         BeginCase("RowNotInTableException - AcceptChanges");\r
92                         try\r
93                         {\r
94                                 drParent.AcceptChanges();\r
95                         }\r
96                         catch (RowNotInTableException  ex)\r
97                         {\r
98                                 tmpEx = ex;\r
99                         }\r
100                         base.Compare(tmpEx.GetType(),typeof(RowNotInTableException));\r
101                         tmpEx = new  Exception();\r
102                 }\r
103                 catch(Exception ex)     {exp = ex;}\r
104                 finally {EndCase(exp); exp = null;}\r
105 \r
106                 try\r
107                 {\r
108                         BeginCase("RowNotInTableException - GetChildRows");\r
109                         try\r
110                         {\r
111                                 drParent.GetChildRows("myRelation");\r
112                         }\r
113                         catch (RowNotInTableException  ex)\r
114                         {\r
115                                 tmpEx = ex;\r
116                         }\r
117                         base.Compare(tmpEx.GetType(),typeof(RowNotInTableException));\r
118                         tmpEx = new  Exception();\r
119                 }\r
120                 catch(Exception ex)     {exp = ex;}\r
121                 finally {EndCase(exp); exp = null;}\r
122 \r
123                 try\r
124                 {\r
125                         BeginCase("RowNotInTableException - ItemArray");\r
126                         object[] o = null;\r
127                         try\r
128                         {\r
129                                 o = drParent.ItemArray ;\r
130                         }\r
131                         catch (RowNotInTableException  ex)\r
132                         {\r
133                                 tmpEx = ex;\r
134                         }\r
135                         base.Compare(tmpEx.GetType(),typeof(RowNotInTableException));\r
136                         tmpEx = new  Exception();\r
137                 }\r
138                 catch(Exception ex)     {exp = ex;}\r
139                 finally {EndCase(exp); exp = null;}\r
140 \r
141                 // **********   don't throw exception (should be according to MSDN)     ***********************\r
142                 //              try\r
143                 //              {\r
144                 //                      BeginCase("RowNotInTableException - GetParentRow");\r
145                 //                      DataRow dr = null;\r
146                 //                      try\r
147                 //                      {\r
148                 //                              dr = drChild.GetParentRow("myRelation"); \r
149                 //                      }\r
150                 //                      catch (RowNotInTableException  ex)\r
151                 //                      {\r
152                 //                              tmpEx = ex;\r
153                 //                      }\r
154                 //                      base.Compare(tmpEx.GetType(),typeof(RowNotInTableException));\r
155                 //                      tmpEx = new  Exception();\r
156                 //              }\r
157                 //              catch(Exception ex)     {exp = ex;}\r
158                 //              finally {EndCase(exp); exp = null;}\r
159                 \r
160                 try\r
161                 {\r
162                         BeginCase("RowNotInTableException - GetParentRows");\r
163                         DataRow[] dr = null;\r
164                         try\r
165                         {\r
166                                 dr = drChild.GetParentRows("myRelation"); \r
167                         }\r
168                         catch (RowNotInTableException  ex)\r
169                         {\r
170                                 tmpEx = ex;\r
171                         }\r
172                         base.Compare(tmpEx.GetType(),typeof(RowNotInTableException));\r
173                         tmpEx = new  Exception();\r
174                 }\r
175                 catch(Exception ex)     {exp = ex;}\r
176                 finally {EndCase(exp); exp = null;}\r
177 \r
178                 try\r
179                 {\r
180                         BeginCase("RowNotInTableException - RejectChanges");\r
181                         try\r
182                         {\r
183                                 drParent.RejectChanges();\r
184                         }\r
185                         catch (RowNotInTableException  ex)\r
186                         {\r
187                                 tmpEx = ex;\r
188                         }\r
189                         base.Compare(tmpEx.GetType(),typeof(RowNotInTableException));\r
190                         tmpEx = new  Exception();\r
191                 }\r
192                 catch(Exception ex)     {exp = ex;}\r
193                 finally {EndCase(exp); exp = null;}\r
194 \r
195                 try\r
196                 {\r
197                         BeginCase("RowNotInTableException - SetParentRow");\r
198                         try\r
199                         {\r
200                                 drChild.SetParentRow(ds.Tables[0].Rows[1]);\r
201                         }\r
202                         catch (RowNotInTableException  ex)\r
203                         {\r
204                                 tmpEx = ex;\r
205                         }\r
206                         base.Compare(tmpEx.GetType(),typeof(RowNotInTableException));\r
207                         tmpEx = new  Exception();\r
208                 }\r
209                 catch(Exception ex)     {exp = ex;}\r
210                 finally {EndCase(exp); exp = null;}\r
211         }\r
212 }\r
213 }