Merge pull request #4570 from lateralusX/jlorenss/visual_studio_msbuild_fix
[mono.git] / mcs / class / System.Data / Test / ProviderTests / System.Data.Odbc / OdbcDataAdapterTest.cs
1 // OdbcDataAdapterTest.cs - NUnit Test Cases for testing the
2 //                          OdbcDataAdapter class
3 // Author:
4 //      Sureshkumar T (TSureshkumar@novell.com)
5 //
6 // Copyright (c) 2004 Novell Inc., and the individuals listed
7 // on the ChangeLog entries.
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 #if !NO_ODBC
30
31 using System;
32 using System.Data;
33 using System.Data.Odbc;
34
35 using NUnit.Framework;
36
37 namespace MonoTests.System.Data.Connected.Odbc
38 {
39         [TestFixture]
40         [Category ("odbc")]
41         public class OdbcDataAdapterTest
42         {
43                 [Test]
44                 public void FillTest ()
45                 {
46                         OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
47                         try
48                         {
49                                 // For this Test, you must create sample table
50                                 // called person-age, with a non-zero number of rows
51                                 // and non-zero number of columns
52                                 // run the test initialization script mono_test_mysql.sql
53                                 string tableName = "employee";
54                                 string sql= "select * from " + tableName; 
55                                 OdbcDataAdapter da = new OdbcDataAdapter (sql, (OdbcConnection) conn);
56                                 DataSet ds = new DataSet (tableName);
57                                 da.Fill (ds, tableName);
58                                 Assert.AreEqual (true, 
59                                                  ds.Tables.Count > 0,
60                                                  "#1 Table count must not be zero");
61                                 Assert.AreEqual (true, 
62                                                  ds.Tables [0].Rows.Count > 0,
63                                                  "#2 Row count must not be zero");
64                                 foreach (DataColumn dc in ds.Tables [0].Columns)
65                                         Assert.AreEqual (true,
66                                                          dc.ColumnName.Length > 0,
67                                                          "#3 DataSet column names must noot be of size 0");
68                                 foreach (DataRow dr in ds.Tables [0].Rows) {
69                                         foreach (DataColumn dc in ds.Tables [0].Columns) 
70                                                 Assert.AreEqual (true,
71                                                                  dc.ColumnName.Length > 0,
72                                                                  "#4 column values must not be of size 0");
73                                 }
74                         } finally {
75                                 ConnectionManager.Instance.Odbc.CloseConnection ();
76                         }
77                 }
78
79                 [Test]
80                 [Ignore]
81                 public void InsertUtf8Test ()
82                 {
83                         OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
84                         try
85                         {
86                                 DoExecuteNonQuery ((OdbcConnection) conn,
87                                                    "CREATE TABLE odbc_ins_utf8_test(ival int not null, sval varchar(20))");
88                                 Assert.AreEqual (DoExecuteNonQuery ((OdbcConnection) conn,
89                                                                     "INSERT INTO odbc_ins_utf8_test(ival, sval) VALUES (1, 'English')"),
90                                                  1);
91                                 Assert.AreEqual (DoExecuteNonQuery ((OdbcConnection) conn,
92                                                                     "INSERT INTO odbc_ins_utf8_test(ival, sval) VALUES (2, 'Français')"),
93                                                  1);
94                                 Assert.AreEqual (DoExecuteNonQuery ((OdbcConnection) conn,
95                                                                     "INSERT INTO odbc_ins_utf8_test(ival, sval) VALUES (3, 'Español')"),
96                                                  1);
97                                 Assert.AreEqual (DoExecuteScalar   ((OdbcConnection) conn,
98                                                                     "SELECT COUNT(*) FROM odbc_ins_utf8_test WHERE sval " +
99                                                                     "IN('English', 'Français', 'Español')"),
100                                                  3);
101                         } finally {
102                                 DoExecuteNonQuery ((OdbcConnection) conn, "DROP TABLE odbc_ins_utf8_test");
103                                 ConnectionManager.Instance.Odbc.CloseConnection ();
104                         }
105                 }
106
107                 private int DoExecuteNonQuery (OdbcConnection conn, string sql)
108                 {
109                         OdbcCommand cmd = new OdbcCommand (sql, conn);
110                         return cmd.ExecuteNonQuery ();
111                 }
112
113                 private int DoExecuteScalar (OdbcConnection conn, string sql)
114                 {
115                         OdbcCommand cmd = new OdbcCommand (sql, conn);
116                         object value = cmd.ExecuteScalar ();
117                         return (int) Convert.ChangeType (value, typeof (int));
118                 }
119         }
120 }
121
122 #endif