Kill all executable flags on *.cs and ChangeLog files.
[mono.git] / mcs / class / System.Data / Test / ProviderTests / System.Data.OleDb.jvm / OleDbDataReader / OleDbDataReader_GetValues.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.OleDb;
27
28 using MonoTests.System.Data.Utils;
29
30
31 using NUnit.Framework;
32
33 namespace MonoTests.System.Data.OleDb
34 {
35         [TestFixture]
36         public class OleDbDataReader_GetValues : ADONetTesterClass 
37         {
38                 public static void Main()
39                 {
40                         OleDbDataReader_GetValues tc = new OleDbDataReader_GetValues();
41                         Exception exp = null;
42                         try
43                         {
44                                 tc.BeginTest("OleDbDataReader_GetValues");
45                                 tc.run();
46                         }
47                         catch(Exception ex){exp = ex;}
48                         finally {tc.EndTest(exp);}
49                 }
50
51                 [Test]
52                 public void run()
53                 {
54                         Exception exp = null;
55                         int intValuesCount = 0;
56
57                         //prepare data
58                         base.PrepareDataForTesting(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
59
60                         OleDbConnection con = new OleDbConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
61                         con.Open();
62                         OleDbCommand cmd = new OleDbCommand("Select CustomerID, ContactName , CompanyName From Customers where CustomerID = 'GH100'", con);
63                         OleDbDataReader rdr = cmd.ExecuteReader();
64                         rdr.Read();
65
66                         object [] values = null;
67
68
69                         //------ check big array
70                         try
71                         {
72                                 BeginCase("GetValues - bigger array - check count");
73                                 values = new object[50];
74                                 intValuesCount = rdr.GetValues(values);
75                                 Compare(intValuesCount ,3 );
76                         } 
77                         catch(Exception ex){exp = ex;}
78                         finally{EndCase(exp); exp = null;}
79
80                         try
81                         {
82                                 BeginCase("GetValues - bigger array - check CustomerID");
83                                 Compare(values[0].ToString().Trim() ,"GH100" );
84                         } 
85                         catch(Exception ex){exp = ex;}
86                         finally{EndCase(exp); exp = null;}
87
88                         try
89                         {
90                                 BeginCase("GetValues - bigger array - check CompanyName");
91                                 Compare(values[2].ToString() ,"Company100" );
92                         } 
93                         catch(Exception ex){exp = ex;}
94                         finally{EndCase(exp); exp = null;}
95
96                         try
97                         {
98                                 BeginCase("GetValues - bigger array - check DBNull");
99                                 Compare(values[3] == null ,true);
100                         } 
101                         catch(Exception ex){exp = ex;}
102                         finally{EndCase(exp); exp = null;}
103
104                         //------ check small array
105                         try
106                         {
107                                 BeginCase("GetValues - smaller array - check count");
108                                 values = new object[2];
109                                 intValuesCount = rdr.GetValues(values);
110                                 Compare(intValuesCount ,2 );
111                         } 
112                         catch(Exception ex){exp = ex;}
113                         finally{EndCase(exp); exp = null;}
114
115                         try
116                         {
117                                 BeginCase("GetValues - smaller array - check CustomerID");
118                                 Compare(values[0].ToString().Trim() ,"GH100" );
119                         } 
120                         catch(Exception ex){exp = ex;}
121                         finally{EndCase(exp); exp = null;}
122
123
124                         //------ check exact array
125                         try
126                         {
127                                 BeginCase("GetValues - exact array - check count");
128                                 values = new object[3];
129                                 intValuesCount = rdr.GetValues(values);
130                                 Compare(intValuesCount ,3 );
131                         } 
132                         catch(Exception ex){exp = ex;}
133                         finally{EndCase(exp); exp = null;}
134
135                         try
136                         {
137                                 BeginCase("GetValues - exact array - check CustomerID");
138                                 Compare(values[0].ToString().Trim() ,"GH100" );
139                         } 
140                         catch(Exception ex){exp = ex;}
141                         finally{EndCase(exp); exp = null;}
142
143                         try
144                         {
145                                 BeginCase("GetValues - exact array - check CompanyName");
146                                 Compare(values[2].ToString() ,"Company100" );
147                         } 
148                         catch(Exception ex){exp = ex;}
149                         finally{EndCase(exp); exp = null;}
150
151                         if (con.State == ConnectionState.Open) con.Close();
152
153
154                 }
155         }
156 }