* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Data.OracleClient / Test / System.Data.OracleClient.jvm / OracleDataReader / OracleDataReader_GetInt32_I.cs
1 // 
2 // Copyright (c) 2006 Mainsoft Co.
3 // 
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23
24 using System;
25 using System.Data;
26 using System.Data.OracleClient;
27
28 using MonoTests.System.Data.Utils;
29
30 using MonoTests.System.Data.Utils.Data;
31
32 using NUnit.Framework;
33
34 namespace MonoTests.System.Data.OracleClient
35 {
36         [TestFixture]
37         public class OracleDataReader_GetInt32_I : ADONetTesterClass 
38         {
39                 private Exception exp = null;
40                 private int testTypesInvocations;
41
42                 public static void Main()
43                 {
44                         OracleDataReader_GetInt32_I tc = new OracleDataReader_GetInt32_I();
45                         Exception exp = null;
46                         try
47                         {
48                                 tc.BeginTest("OracleDataReader_GetInt32_I");
49                                 tc.run();
50                         }
51                         catch(Exception ex)
52                         {
53                                 tc.exp = ex;
54                         }
55                         finally 
56                         {
57                                 tc.EndTest(tc.exp);
58                         }
59                 }
60
61                 [Test]
62                 public void run()
63                 {
64                         DoTestTypes(ConnectedDataProvider.GetSimpleDbTypesParameters());
65                         DoTestTypes(ConnectedDataProvider.GetExtendedDbTypesParameters());
66                 }
67
68                 public void DoTestTypes(DbTypeParametersCollection row)
69                 {
70                         testTypesInvocations++;
71                         exp = null;
72                         string rowId = "13286_" + this.testTypesInvocations.ToString();
73                         OracleDataReader rdr = null;
74                         OracleConnection con = null;
75                         try
76                         {
77                                 row.ExecuteInsert(rowId);
78                                 row.ExecuteSelectReader(rowId, out rdr, out con);
79                                 while (rdr.Read())
80                                 {
81                                         //Run over all the columns in the result set row.
82                                         //For each column, try to read it as a Int32.
83                                         for (int i=0; i<row.Count; i++)
84                                         {
85                                                 if (row[i].Value.GetType() == typeof(Int32) ||
86                                                         row[i].Value.GetType() == typeof(double) ||
87                                                         row[i].Value.GetType() == typeof(decimal)) { //The value in the result set should be a Int32.
88                                                         try
89                                                         {
90                                                                 BeginCase(string.Format("Calling GetInt32() on a field of dbtype {0}", row[i].DbTypeName));
91                                                                 Int32 retInt32 = rdr.GetInt32(i);
92                                                                 Compare(Convert.ToInt32(row[i].Value), retInt32);
93                                                         }
94                                                         catch (Exception ex)
95                                                         {
96                                                                 exp = ex;
97                                                         }
98                                                         finally
99                                                         {
100                                                                 EndCase(exp);
101                                                                 exp = null;
102                                                         }
103                                                 }
104                                                 else //The value in the result set should NOT be Int32. In this case an Invalid case exception should be thrown.
105                                                 {
106                                                         try
107                                                         {
108                                                                 BeginCase(string.Format("Calling GetInt32() on a field of dbtype {0}", row[i].DbTypeName));
109                                                                 Int32 retInt32 = rdr.GetInt32(i);
110                                                                 ExpectedExceptionNotCaught("InvalidCastException");
111                                                         }
112                                                         catch (InvalidCastException ex)
113                                                         {
114                                                                 ExpectedExceptionCaught(ex);
115                                                         }
116                                                         catch (Exception ex)
117                                                         {
118                                                                 exp = ex;
119                                                         }
120                                                         finally
121                                                         {
122                                                                 EndCase(exp);
123                                                                 exp = null;
124                                                         }
125                                                 }
126                                         }
127                                 }
128                         }
129                         finally
130                         {
131                                 row.ExecuteDelete(rowId);
132                                 if ( (rdr != null) && (!rdr.IsClosed) )
133                                 {
134                                         rdr.Close();
135                                 }
136                                 if ( (con != null) && (con.State != ConnectionState.Closed) )
137                                 {
138                                         con.Close();
139                                 }
140                         }
141                 }
142         }
143         
144 }