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.
33 using System.Data.Odbc;
35 using NUnit.Framework;
37 namespace MonoTests.System.Data.Connected.Odbc
41 public class OdbcDataAdapterTest
44 public void FillTest ()
46 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
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.Instance.Odbc.CloseConnection ();
81 public void InsertUtf8Test ()
83 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
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')"),
91 Assert.AreEqual (DoExecuteNonQuery ((OdbcConnection) conn,
92 "INSERT INTO odbc_ins_utf8_test(ival, sval) VALUES (2, 'Français')"),
94 Assert.AreEqual (DoExecuteNonQuery ((OdbcConnection) conn,
95 "INSERT INTO odbc_ins_utf8_test(ival, sval) VALUES (3, 'Español')"),
97 Assert.AreEqual (DoExecuteScalar ((OdbcConnection) conn,
98 "SELECT COUNT(*) FROM odbc_ins_utf8_test WHERE sval " +
99 "IN('English', 'Français', 'Español')"),
102 DoExecuteNonQuery ((OdbcConnection) conn, "DROP TABLE odbc_ins_utf8_test");
103 ConnectionManager.Instance.Odbc.CloseConnection ();
107 private int DoExecuteNonQuery (OdbcConnection conn, string sql)
109 OdbcCommand cmd = new OdbcCommand (sql, conn);
110 return cmd.ExecuteNonQuery ();
113 private int DoExecuteScalar (OdbcConnection conn, string sql)
115 OdbcCommand cmd = new OdbcCommand (sql, conn);
116 object value = cmd.ExecuteScalar ();
117 return (int) Convert.ChangeType (value, typeof (int));