Adding TARGET_JVM OleDb testsuite
[mono.git] / mcs / class / System.Data / Test / ProviderTests / System.Data.OleDb.jvm / OleDbCommandBuilder / OleDbCommandBuilder_DeriveParameters_O.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 OleDbCommandBuilder_DeriveParameters_O : GHTBase
37         {
38                 OleDbConnection con;
39                 OleDbCommand cmd;
40                 Exception exp = null;
41
42                 [SetUp]
43                 public void SetUp()
44                 {
45                         exp=null;
46                         BeginCase("Setup");
47                         try
48                         {
49                                 con = new OleDbConnection(ConnectedDataProvider.ConnectionString);
50                                 con.Open();
51                                 cmd = new OleDbCommand("", con);
52                                 Compare("Setup", "Setup");
53                         }
54                         catch(Exception ex)     {exp = ex;}
55                         finally {EndCase(exp); exp = null;}
56                 }
57
58                 [TearDown]
59                 public void TearDown()
60                 {
61                         if (con != null)
62                         {
63                                 if (con.State == ConnectionState.Open) con.Close();
64                         }
65                 }
66
67                 public static void Main()
68                 {
69                         OleDbCommandBuilder_DeriveParameters_O tc = new OleDbCommandBuilder_DeriveParameters_O();
70                         try
71                         {
72                                 tc.BeginTest("OleDbCommandBuilder_DeriveParameters_O");
73                                 tc.SetUp();
74                                 tc.run();
75                                 tc.TearDown();
76                         }
77                         catch(Exception ex)
78                         {
79                                 tc.exp = ex;
80                         }
81                         finally
82                         {
83                                 tc.EndTest(tc.exp);
84                         }
85                 }
86
87
88                 public void run()
89                 {
90             RetrieveParameters();
91                 }
92
93                 [Test]
94                 public void RetrieveParameters()
95                 {
96                         exp = null;
97
98                         try
99                         {
100                                 BeginCase("retrieve parameters");
101                                 
102                                 if (ConnectedDataProvider.GetDbType(con) == DataBaseServer.DB2)
103                                 {
104                                         this.Skip("Not Implemented on DB2.");
105                                         return;
106                                 }
107
108                                 switch (ConnectedDataProvider.GetDbType(con))
109                                 {
110 //                                      case MonoTests.Utils.DataBaseServer.PostgreSQL:
111 //                                              cmd = new OleDbCommand("GH_MULTIRECORDSETS('a','b','c')", con);
112 //                                              break;
113                                         default:
114                                                 cmd = new OleDbCommand("GH_MultiRecordSets", con);
115                                                 break;
116                                 }
117                                 
118                                 cmd.CommandType = CommandType.StoredProcedure;
119                                 OleDbCommandBuilder.DeriveParameters(cmd);
120
121                                 switch (ConnectedDataProvider.GetDbType(con))
122                                 {
123                                         case DataBaseServer.SQLServer:
124                                         case DataBaseServer.Sybase:
125                                                 Compare(cmd.Parameters.Count, 1);
126                                                 Compare(cmd.Parameters[0].Direction, ParameterDirection.ReturnValue);
127                                                 Compare(cmd.Parameters[0].ParameterName, "RETURN_VALUE");
128                                                 break;
129                                 
130                                         case DataBaseServer.Oracle:
131                                                 Compare(cmd.Parameters.Count, 3);
132                                                 Compare(cmd.Parameters[0].Direction, ParameterDirection.Output);
133                                                 Compare(cmd.Parameters[1].Direction, ParameterDirection.Output);
134                                                 Compare(cmd.Parameters[2].Direction, ParameterDirection.Output);
135                                                 Compare(cmd.Parameters[0].ParameterName, "RCT_EMPLOYEES");
136                                                 break;
137
138                                         case DataBaseServer.PostgreSQL:
139                                                 Compare(cmd.Parameters.Count, 1);
140                                                 Compare(cmd.Parameters[0].Direction, ParameterDirection.ReturnValue);
141                                                 Compare(cmd.Parameters[0].ParameterName, "returnValue");
142                                                 break;
143
144                                         default:
145                                                 throw new ApplicationException(string.Format("GHT: Test not implemented for DB type {0}", ConnectedDataProvider.GetDbType(con)));
146                                 }
147                         } 
148                         catch(Exception ex)
149                         {
150                                 exp = ex;
151                         }
152                         finally
153                         {
154                                 EndCase(exp);
155                                 exp = null;
156                         }
157                 }
158         }
159 }