2 // Copyright (c) 2006 Mainsoft Co.
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:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
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.
26 using System.Data.OracleClient;
28 using MonoTests.System.Data.Utils;
30 using MonoTests.System.Data.Utils.Data;
32 using NUnit.Framework;
34 namespace MonoTests.System.Data.OracleClient
37 public class OracleDataReader_GetInt32_I : ADONetTesterClass
39 private Exception exp = null;
40 private int testTypesInvocations;
42 public static void Main()
44 OracleDataReader_GetInt32_I tc = new OracleDataReader_GetInt32_I();
48 tc.BeginTest("OracleDataReader_GetInt32_I");
64 DoTestTypes(ConnectedDataProvider.GetSimpleDbTypesParameters());
65 DoTestTypes(ConnectedDataProvider.GetExtendedDbTypesParameters());
68 public void DoTestTypes(DbTypeParametersCollection row)
70 testTypesInvocations++;
72 string rowId = "13286_" + this.testTypesInvocations.ToString();
73 OracleDataReader rdr = null;
74 OracleConnection con = null;
77 row.ExecuteInsert(rowId);
78 row.ExecuteSelectReader(rowId, out rdr, out con);
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++)
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.
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);
104 else //The value in the result set should NOT be Int32. In this case an Invalid case exception should be thrown.
108 BeginCase(string.Format("Calling GetInt32() on a field of dbtype {0}", row[i].DbTypeName));
109 Int32 retInt32 = rdr.GetInt32(i);
110 ExpectedExceptionNotCaught("InvalidCastException");
112 catch (InvalidCastException ex)
114 ExpectedExceptionCaught(ex);
131 row.ExecuteDelete(rowId);
132 if ( (rdr != null) && (!rdr.IsClosed) )
136 if ( (con != null) && (con.State != ConnectionState.Closed) )