* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Data / Test / System.Data.Tests.Mainsoft / System.Data / DataRow / DataRow_HasVersion_D.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 System;
30 using System.Data;
31
32 using GHTUtils;
33 using GHTUtils.Base;
34
35 using NUnit.Framework;
36
37 namespace tests.system_data_dll.System_Data
38 {
39         [TestFixture] public class DataRow_HasVersion_D : GHTBase
40         {
41                 public void SetUp()
42                 {
43                         Exception exp = null;
44                         BeginCase("Setup");
45                         try
46                         {
47                         }
48                         catch(Exception ex)     {exp = ex;}
49                         finally {EndCase(exp); exp = null;}
50                 }
51
52                 public void TearDown()
53                 {
54                 }
55
56                 [Test] public void Main()
57                 {
58                         DataRow_HasVersion_D tc = new DataRow_HasVersion_D();
59                         Exception exp = null;
60                         try
61                         {
62                                 tc.BeginTest("DataRow_HasVersion_D");
63                                 tc.SetUp();
64                                 tc.run();
65                                 tc.TearDown();
66                         }
67                         catch(Exception ex)
68                         {
69                                 exp = ex;
70                         }
71                         finally
72                         {
73                                 tc.EndTest(exp);
74                         }
75                 }
76
77
78                 public void run()
79                 {
80                         Exception exp = null;
81         
82
83                         DataTable t = new DataTable("atable");
84                         t.Columns.Add("id", typeof(int));
85                         t.Columns.Add("name", typeof(string));
86                         t.Columns[0].DefaultValue = 1;
87                         t.Columns[1].DefaultValue = "something";
88
89
90                         // row r is detached
91                         DataRow r = t.NewRow();
92                 
93                         try
94                         {
95                                 BeginCase("HasVersion Test #10");
96                                 Compare(r.HasVersion(DataRowVersion.Current) ,false );
97                         }
98                         catch(Exception ex)     {exp = ex;}
99                         finally {EndCase(exp); exp = null;}
100                 
101                         try
102                         {
103                                 BeginCase("HasVersion Test #11");
104                                 Compare(r.HasVersion(DataRowVersion.Original) ,false );
105                         }
106                         catch(Exception ex)     {exp = ex;}
107                         finally {EndCase(exp); exp = null;}
108                 
109                         try
110                         {
111                                 BeginCase("HasVersion Test #12");
112                                 Compare(r.HasVersion(DataRowVersion.Default) ,true );
113                         }
114                         catch(Exception ex)     {exp = ex;}
115                         finally {EndCase(exp); exp = null;}
116                 
117                         try
118                         {
119                                 BeginCase("HasVersion Test #13");
120                                 Compare(r.HasVersion(DataRowVersion.Proposed) ,true );
121                         }
122                         catch(Exception ex)     {exp = ex;}
123                         finally {EndCase(exp); exp = null;}             
124         
125                                         
126                         r[0] = 4; 
127                         r[1] = "four";
128
129                         try
130                         {
131                                 BeginCase("HasVersion Test #20");
132                                 Compare(r.HasVersion(DataRowVersion.Current) ,false );
133                         }
134                         catch(Exception ex)     {exp = ex;}
135                         finally {EndCase(exp); exp = null;}
136                 
137                         try
138                         {
139                                 BeginCase("HasVersion Test #21");
140                                 Compare(r.HasVersion(DataRowVersion.Original) ,false );
141                         }
142                         catch(Exception ex)     {exp = ex;}
143                         finally {EndCase(exp); exp = null;}
144                 
145                         try
146                         {
147                                 BeginCase("HasVersion Test #22");
148                                 Compare(r.HasVersion(DataRowVersion.Default) ,true );
149                         }
150                         catch(Exception ex)     {exp = ex;}
151                         finally {EndCase(exp); exp = null;}
152                 
153                         try
154                         {
155                                 BeginCase("HasVersion Test #23");
156                                 Compare(r.HasVersion(DataRowVersion.Proposed) ,true );
157                         }
158                         catch(Exception ex)     {exp = ex;}
159                         finally {EndCase(exp); exp = null;}     
160         
161                         t.Rows.Add(r);
162                         // now it is "added"
163
164                         try
165                         {
166                                 BeginCase("HasVersion Test #30");
167                                 Compare(r.HasVersion(DataRowVersion.Current) ,true );
168                         }
169                         catch(Exception ex)     {exp = ex;}
170                         finally {EndCase(exp); exp = null;}
171                 
172                         try
173                         {
174                                 BeginCase("HasVersion Test #31");
175                                 Compare(r.HasVersion(DataRowVersion.Original) ,false );
176                         }
177                         catch(Exception ex)     {exp = ex;}
178                         finally {EndCase(exp); exp = null;}
179                 
180                         try
181                         {
182                                 BeginCase("HasVersion Test #32");
183                                 Compare(r.HasVersion(DataRowVersion.Default) ,true );
184                         }
185                         catch(Exception ex)     {exp = ex;}
186                         finally {EndCase(exp); exp = null;}
187                 
188                         try
189                         {
190                                 BeginCase("HasVersion Test #33");
191                                 Compare(r.HasVersion(DataRowVersion.Proposed) ,false );
192                         }
193                         catch(Exception ex)     {exp = ex;}
194                         finally {EndCase(exp); exp = null;}     
195         
196
197                         t.AcceptChanges();
198                         // now it is "unchanged"
199         
200                         try
201                         {
202                                 BeginCase("HasVersion Test #40");
203                                 Compare(r.HasVersion(DataRowVersion.Current) ,true );
204                         }
205                         catch(Exception ex)     {exp = ex;}
206                         finally {EndCase(exp); exp = null;}
207                 
208                         try
209                         {
210                                 BeginCase("HasVersion Test #41");
211                                 Compare(r.HasVersion(DataRowVersion.Original) ,true );
212                         }
213                         catch(Exception ex)     {exp = ex;}
214                         finally {EndCase(exp); exp = null;}
215                 
216                         try
217                         {
218                                 BeginCase("HasVersion Test #42");
219                                 Compare(r.HasVersion(DataRowVersion.Default) ,true );
220                         }
221                         catch(Exception ex)     {exp = ex;}
222                         finally {EndCase(exp); exp = null;}
223                 
224                         try
225                         {
226                                 BeginCase("HasVersion Test #43");
227                                 Compare(r.HasVersion(DataRowVersion.Proposed) ,false );
228                         }
229                         catch(Exception ex)     {exp = ex;}
230                         finally {EndCase(exp); exp = null;}     
231         
232                 
233                         r.BeginEdit();
234                         r[1] = "newvalue";
235         
236                         try
237                         {
238                                 BeginCase("HasVersion Test #50");
239                                 Compare(r.HasVersion(DataRowVersion.Current) ,true );
240                         }
241                         catch(Exception ex)     {exp = ex;}
242                         finally {EndCase(exp); exp = null;}
243                 
244                         try
245                         {
246                                 BeginCase("HasVersion Test #51");
247                                 Compare(r.HasVersion(DataRowVersion.Original) ,true );
248                         }
249                         catch(Exception ex)     {exp = ex;}
250                         finally {EndCase(exp); exp = null;}
251                 
252                         try
253                         {
254                                 BeginCase("HasVersion Test #52");
255                                 Compare(r.HasVersion(DataRowVersion.Default) ,true );
256                         }
257                         catch(Exception ex)     {exp = ex;}
258                         finally {EndCase(exp); exp = null;}
259                 
260                         try
261                         {
262                                 BeginCase("HasVersion Test #53");
263                                 Compare(r.HasVersion(DataRowVersion.Proposed) ,true );
264                         }
265                         catch(Exception ex)     {exp = ex;}
266                         finally {EndCase(exp); exp = null;}     
267         
268                                         
269                         r.EndEdit();
270                         // now it is "modified"
271                         try
272                         {
273                                 BeginCase("HasVersion Test #60");
274                                 Compare(r.HasVersion(DataRowVersion.Current) ,true );
275                         }
276                         catch(Exception ex)     {exp = ex;}
277                         finally {EndCase(exp); exp = null;}
278                 
279                         try
280                         {
281                                 BeginCase("HasVersion Test #61");
282                                 Compare(r.HasVersion(DataRowVersion.Original) ,true );
283                         }
284                         catch(Exception ex)     {exp = ex;}
285                         finally {EndCase(exp); exp = null;}
286                 
287                         try
288                         {
289                                 BeginCase("HasVersion Test #62");
290                                 Compare(r.HasVersion(DataRowVersion.Default) ,true );
291                         }
292                         catch(Exception ex)     {exp = ex;}
293                         finally {EndCase(exp); exp = null;}
294                 
295                         try
296                         {
297                                 BeginCase("HasVersion Test #63");
298                                 Compare(r.HasVersion(DataRowVersion.Proposed) ,false );
299                         }
300                         catch(Exception ex)     {exp = ex;}
301                         finally {EndCase(exp); exp = null;}     
302         
303                         // this or t.AcceptChanges
304                         r.AcceptChanges(); 
305                         // now it is "unchanged" again
306                         try
307                         {
308                                 BeginCase("HasVersion Test #70");
309                                 Compare(r.HasVersion(DataRowVersion.Current) ,true );
310                         }
311                         catch(Exception ex)     {exp = ex;}
312                         finally {EndCase(exp); exp = null;}
313                 
314                         try
315                         {
316                                 BeginCase("HasVersion Test #71");
317                                 Compare(r.HasVersion(DataRowVersion.Original) ,true );
318                         }
319                         catch(Exception ex)     {exp = ex;}
320                         finally {EndCase(exp); exp = null;}
321                 
322                         try
323                         {
324                                 BeginCase("HasVersion Test #72");
325                                 Compare(r.HasVersion(DataRowVersion.Default) ,true );
326                         }
327                         catch(Exception ex)     {exp = ex;}
328                         finally {EndCase(exp); exp = null;}
329                 
330                         try
331                         {
332                                 BeginCase("HasVersion Test #73");
333                                 Compare(r.HasVersion(DataRowVersion.Proposed) ,false );
334                         }
335                         catch(Exception ex)     {exp = ex;}
336                         finally {EndCase(exp); exp = null;}     
337         
338                         r.Delete();
339                         // now it is "deleted"
340         
341                         try
342                         {
343                                 BeginCase("HasVersion Test #80");
344                                 Compare(r.HasVersion(DataRowVersion.Current) ,false );
345                         }
346                         catch(Exception ex)     {exp = ex;}
347                         finally {EndCase(exp); exp = null;}
348                 
349                         try
350                         {
351                                 BeginCase("HasVersion Test #81");
352                                 Compare(r.HasVersion(DataRowVersion.Original) ,true );
353                         }
354                         catch(Exception ex)     {exp = ex;}
355                         finally {EndCase(exp); exp = null;}
356                 
357                         try
358                         {
359                                 BeginCase("HasVersion Test #82");
360                                 Compare(r.HasVersion(DataRowVersion.Default) ,false );
361                         }
362                         catch(Exception ex)     {exp = ex;}
363                         finally {EndCase(exp); exp = null;}
364                 
365                         try
366                         {
367                                 BeginCase("HasVersion Test #83");
368                                 Compare(r.HasVersion(DataRowVersion.Proposed) ,false );
369                         }
370                         catch(Exception ex)     {exp = ex;}
371                         finally {EndCase(exp); exp = null;}     
372         
373
374                         r.AcceptChanges();
375                         // back to detached
376                         try
377                         {
378                                 BeginCase("HasVersion Test #90");
379                                 Compare(r.HasVersion(DataRowVersion.Current) ,false );
380                         }
381                         catch(Exception ex)     {exp = ex;}
382                         finally {EndCase(exp); exp = null;}
383                 
384                         try
385                         {
386                                 BeginCase("HasVersion Test #91");
387                                 Compare(r.HasVersion(DataRowVersion.Original) ,false );
388                         }
389                         catch(Exception ex)     {exp = ex;}
390                         finally {EndCase(exp); exp = null;}
391                 
392                         try
393                         {
394                                 BeginCase("HasVersion Test #92");
395                                 Compare(r.HasVersion(DataRowVersion.Default) ,false );
396                         }
397                         catch(Exception ex)     {exp = ex;}
398                         finally {EndCase(exp); exp = null;}
399                 
400                         try
401                         {
402                                 BeginCase("HasVersion Test #93");
403                                 Compare(r.HasVersion(DataRowVersion.Proposed) ,false );
404                         }
405                         catch(Exception ex)     {exp = ex;}
406                         finally {EndCase(exp); exp = null;}     
407                 
408         
409
410                 }
411         }
412 }