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_GetBytes_IIBII : GHTBase
39 int testTypesInvocations;
41 public static void Main()
43 OracleDataReader_GetBytes_IIBII tc = new OracleDataReader_GetBytes_IIBII();
47 tc.BeginTest("OracleDataReader_GetBytes_IIBII");
50 catch(Exception ex){exp = ex;}
51 finally {tc.EndTest(exp);}
57 DoTestTypes(ConnectedDataProvider.GetSimpleDbTypesParameters());
58 DoTestTypes(ConnectedDataProvider.GetExtendedDbTypesParameters());
60 public void DoTestTypes(DbTypeParametersCollection row)
62 testTypesInvocations++;
64 string rowId = "43966_" + this.testTypesInvocations.ToString();
65 OracleConnection con =null;
66 OracleDataReader rdr = null;
70 row.ExecuteInsert(rowId);
71 row.ExecuteSelectReader(rowId, out rdr, out con);
74 //Run over all the columns in the result set row.
75 //For each column, try to read it as a byte array.
76 for (int i=0; i<row.Count; i++)
78 if (row[i].Value.GetType() == typeof(byte[])) //The value in the result set should be a byte array.
82 BeginCase(string.Format("Calling GetBytes() on a field of dbtype {0}", row[i].DbTypeName));
83 byte[] origBytes = (byte[])row[i].Value;
84 byte[] retBytes = new byte[origBytes.Length];
85 rdr.GetBytes(i, 0, retBytes, 0, origBytes.Length);
86 Compare(origBytes, retBytes);
98 else //The value in the result set should NOT be byte array. In this case an Invalid case exception should be thrown.
102 BeginCase(string.Format("Calling GetBytes() on a field of dbtype {0}", row[i].DbTypeName));
103 byte[] retBytes = new byte[1];
104 rdr.GetBytes(i, 0, retBytes, 0, 1);
105 ExpectedExceptionNotCaught("InvalidCastException");
107 catch (InvalidCastException ex)
109 ExpectedExceptionCaught(ex);
126 row.ExecuteDelete(rowId);
127 if (rdr != null && !rdr.IsClosed)
132 if (con != null && con.State != ConnectionState.Closed)