1 // OdbcDataAdapterTest.cs - NUnit Test Cases for testing the
2 // OdbcDataAdapter class
4 // Sureshkumar T (TSureshkumar@novell.com)
6 // Copyright (c) 2004 Novell Inc., and the individuals listed
7 // on the ChangeLog entries.
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
31 using System.Data.Odbc;
33 using NUnit.Framework;
35 namespace MonoTests.System.Data.Odbc
40 public class OdbcDataAdapterTest
44 public void FillTest ()
46 IDbConnection conn = ConnectionManager.Singleton.Connection;
48 ConnectionManager.Singleton.OpenConnection ();
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,
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");
75 ConnectionManager.Singleton.CloseConnection ();
79 public void InsertUtf8Test ()
81 IDbConnection conn = ConnectionManager.Singleton.Connection;
83 ConnectionManager.Singleton.OpenConnection ();
84 DoExecuteNonQuery ((OdbcConnection) conn,
85 "CREATE TABLE odbc_ins_utf8_test(ival int not null, sval varchar(20))");
86 Assert.AreEqual (DoExecuteNonQuery ((OdbcConnection) conn,
87 "INSERT INTO odbc_ins_utf8_test(ival, sval) VALUES (1, 'English')"),
89 Assert.AreEqual (DoExecuteNonQuery ((OdbcConnection) conn,
90 "INSERT INTO odbc_ins_utf8_test(ival, sval) VALUES (2, 'Français')"),
92 Assert.AreEqual (DoExecuteNonQuery ((OdbcConnection) conn,
93 "INSERT INTO odbc_ins_utf8_test(ival, sval) VALUES (3, 'Español')"),
95 Assert.AreEqual (DoExecuteScalar ((OdbcConnection) conn,
96 "SELECT COUNT(*) FROM odbc_ins_utf8_test WHERE sval " +
97 "IN('English', 'Français', 'Español')"),
100 DoExecuteNonQuery ((OdbcConnection) conn, "DROP TABLE odbc_ins_utf8_test");
101 ConnectionManager.Singleton.CloseConnection ();
104 private int DoExecuteNonQuery (OdbcConnection conn, string sql) {
105 OdbcCommand cmd = new OdbcCommand (sql, conn);
106 return cmd.ExecuteNonQuery ();
109 private int DoExecuteScalar (OdbcConnection conn, string sql) {
110 OdbcCommand cmd = new OdbcCommand (sql, conn);
111 object value = cmd.ExecuteScalar ();
112 return (int) Convert.ChangeType (value, typeof (int));