Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSureshkumar T <suresh@mono-cvs.ximian.com>2005-09-01 15:50:04 +0400
committerSureshkumar T <suresh@mono-cvs.ximian.com>2005-09-01 15:50:04 +0400
commitcce8383f1edb8312d8170eb0a48e25857bec63cc (patch)
tree7838db379045aa5dbb4d56d79e8628f0919308ec /mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/OdbcCommandTest.cs
parent311746b41cf500aef15a68bf4a37bddcbba86ef4 (diff)
added a new framework for testing data providers using nunit and mono.data's provider
factory. Moved few stand-alone tests from Test/ to this framework. In Test: 2005-09-01 Sureshkumar T <tsureshkumar@novell.com> * ProviderTests: Added a new framework for testing Data Providers. This framework is based on nunit category tests and also the provider factory provided by Mono.Data. In Test/System.Data.SqlClient: 2005-09-01 Sureshkumar T <tsureshkumar@novell.com> * SqlDataReaderTest.cs: moved to ProviderTests and integrated with connected mode tests * SqlCommandTest.cs: -- do -- * SqlConnectionTest.cs: -- do -- * SqlTransactionTest.cs: -- do -- * SqlDataAdapterTest.cs: -- do -- In Test/System.Data.Odbc: 2005-09-01 Sureshkumar T <tsureshkumar@novell.com> * OdbcDataAdapterTest.cs: moved to ProviderTests and integrated with connected more framework. * OdbcCommandTest.cs: -- do --. * OdbcParameterCollectionTest.cs: Removed ParameterLengthTrimTest to ProviderTests. In Test/ProviderTests/sql: 2005-09-01 Sureshkumar T <tsureshkumar@novell.com> * SCHEMA: schema specification. * sqlserver.sql: sql script file to create test schema for mssql database. added. * mysql.sql: sql script file to create test schema for mysql database. added. In Test/ProviderTests/System.Data.Odbc: 2005-09-01 Sureshkumar T <tsureshkumar@novell.com> * OdbcCommandBuilderTest.cs: Added tests for OdbcCommandBuilder.cs * OdbcCommandTest.cs: pulled from Test/System.Data.Odbc * OdbcDataAdapterTest.cs: pulled from Test/System.Data.Odbc * OdbcDataReaderTest.cs: pulled from Test/System.Data.Odbc * OdbcParameterCollectionTest.cs: pulled from Test/System.Data.Odbc In Test/ProviderTests/ProviderIndependant: 2005-09-01 Sureshkumar T <tsureshkumar@novell.com> * IDbCommandTest.cs: Added. Provider independent Command tests. * DataReaderTest.cs: Added. Provider independent DataReader tests. In Test/ProviderTests: 2005-09-01 Sureshkumar T <tsureshkumar@novell.com> * System.Data.Connected.Tests.dll.sources: source files. * app-default.config: * app-net_2_0.config: configuration files for profiles and lists the assembly informations for the Provider factory. * odbc.config: * sqlserver.config: connection string info for respective databases. * README: initial. pulled connected mode test-cases around Test/* directory into this new framework. This framework is based on nunit category based test-cases and uses Provider Factories provided in Mono.Data.dll to write provider independent code. In Test/ProviderTests/Common: 2005-09-01 Sureshkumar T <tsureshkumar@novell.com> * DBHelper.cs: Added. Class to provide helper methods for other tests. * ConnectionManager.cs: Added. Class to manage connections In Test/ProviderTests/System.Data.SqlClient: 2005-09-01 Sureshkumar T <tsureshkumar@novell.com> * SqlCommandBuilderTest.cs: added tests for SqlCommandBuilder * SqlCommandTest.cs: pulled from Test/System.Data.SqlClient * SqlConnectionStringBuilderTest.cs: pulled from Test/System.Data.SqlClient * SqlConnectionTest.cs: pulled from Test/System.Data.SqlClient * SqlDataAdapterTest.cs: pulled from Test/System.Data.SqlClient * SqlDataReaderTest.cs: pulled from Test/System.Data.SqlClient * SqlTransactionTest.cs: pulled from Test/System.Data.SqlClient Added attribute Category ("sqlserver") to all these test fixtures. svn path=/trunk/mcs/; revision=49260
Diffstat (limited to 'mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/OdbcCommandTest.cs')
-rw-r--r--mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/OdbcCommandTest.cs156
1 files changed, 156 insertions, 0 deletions
diff --git a/mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/OdbcCommandTest.cs b/mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/OdbcCommandTest.cs
new file mode 100644
index 00000000000..da42f9fe0c8
--- /dev/null
+++ b/mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/OdbcCommandTest.cs
@@ -0,0 +1,156 @@
+// OdbcCommandTest.cs - NUnit Test Cases for testing the
+// OdbcCommand class
+//
+// Authors:
+// Sureshkumar T (TSureshkumar@novell.com)
+// Umadevi S (sumadevi@novell.com)
+//
+// Copyright (c) 2004 Novell Inc., and the individuals listed
+// on the ChangeLog entries.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Data;
+using System.Data.Common;
+using System.Data.Odbc;
+using Mono.Data;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Data
+{
+ [TestFixture]
+ [Category ("odbc")]
+ public class OdbcCommandTest
+ {
+ [Test]
+ public void PrepareAndExecuteTest ()
+ {
+ IDbConnection conn = ConnectionManager.Singleton.Connection;
+ try {
+ ConnectionManager.Singleton.OpenConnection ();
+
+ string tableName = DBHelper.GetRandomName ("PAE", 3);
+ try {
+ // setup table
+ string query = "DROP TABLE " + tableName ;
+ DBHelper.ExecuteNonQuery (conn, query);
+ query = String.Format ("CREATE TABLE {0} ( id INT, small_id SMALLINT )",
+ tableName);
+ DBHelper.ExecuteNonQuery (conn, query);
+
+ query = String.Format ("INSERT INTO {0} values (?, ?)", tableName);
+ OdbcCommand cmd = (OdbcCommand) conn.CreateCommand ();
+ cmd.CommandText = query;
+ cmd.Prepare ();
+
+ OdbcParameter param1 = cmd.Parameters.Add ("?", OdbcType.Int);
+ OdbcParameter param2 = cmd.Parameters.Add ("?", OdbcType.SmallInt);
+ param1.Value = 1;
+ param2.Value = 5;
+ cmd.ExecuteNonQuery ();
+
+ param1.Value = 2;
+ param2.Value = 6;
+ cmd.ExecuteNonQuery ();
+
+ cmd.CommandText = "select * from " + tableName;
+ cmd.Parameters.Clear ();
+
+ OdbcDataReader reader = cmd.ExecuteReader ();
+ int count = 0;
+ while (reader.Read ()){
+ count++;
+ }
+ reader.Close ();
+ Assert.AreEqual (2, count, "#1");
+ } finally {
+ DBHelper.ExecuteNonQuery (conn, "DROP TABLE " + tableName);
+ }
+ } finally {
+ ConnectionManager.Singleton.CloseConnection ();
+ }
+ }
+
+ /// <summary>
+ /// Test String parameters to ODBC Command
+ /// </summary>
+ [Test]
+ public void ExecuteStringParameterTest()
+ {
+ IDbConnection conn = ConnectionManager.Singleton.Connection;
+ try {
+ ConnectionManager.Singleton.OpenConnection ();
+ OdbcCommand dbcmd = (OdbcCommand) conn.CreateCommand ();
+ dbcmd.CommandType = CommandType.Text;
+ dbcmd.CommandText = "select count(*) from employee where fname=?;";
+ string colvalue = "suresh";
+ OdbcParameter param = dbcmd.Parameters.Add("@un", OdbcType.VarChar);
+ param.Value = colvalue;
+ int count = Convert.ToInt32 (dbcmd.ExecuteScalar ());
+ Assert.AreEqual (1, count, "#1 String parameter not passed correctly");
+ } finally {
+ ConnectionManager.Singleton.CloseConnection ();
+ }
+ }
+
+ /// <summary>
+ /// Test ExecuteNonQuery
+ /// </summary>
+ [Test]
+ public void ExecuteNonQueryTest ()
+ {
+ IDbConnection conn = ConnectionManager.Singleton.Connection;
+ try {
+ ConnectionManager.Singleton.OpenConnection ();
+ OdbcCommand dbcmd = (OdbcCommand) conn.CreateCommand ();
+ dbcmd.CommandType = CommandType.Text;
+ dbcmd.CommandText = "select count(*) from employee where id <= ?;";
+ int value = 3;
+ dbcmd.Parameters.Add("@un", OdbcType.Int).Value = value;
+ int ret = dbcmd.ExecuteNonQuery();
+ Assert.AreEqual (-1, ret, "#1 ExecuteNonQuery not working");
+
+ try {
+ // insert
+ dbcmd = (OdbcCommand) conn.CreateCommand ();
+ dbcmd.CommandType = CommandType.Text;
+ dbcmd.CommandText = "insert into employee (id, fname, dob, doj) values " +
+ " (6001, 'tttt', '1999-01-22', '2005-02-11');";
+ ret = dbcmd.ExecuteNonQuery();
+ Assert.AreEqual (1, ret, "#2 ExecuteNonQuery not working");
+ } finally {
+ // delete
+ dbcmd = (OdbcCommand) conn.CreateCommand ();
+ dbcmd.CommandType = CommandType.Text;
+ dbcmd.CommandText = "delete from employee where id > 6000";
+ ret = dbcmd.ExecuteNonQuery();
+ Assert.AreEqual (true, ret > 0, "#3 ExecuteNonQuery for deletion not working");
+ }
+
+ } finally {
+ ConnectionManager.Singleton.CloseConnection ();
+ }
+ }
+
+ }
+}