diff options
author | Sureshkumar T <suresh@mono-cvs.ximian.com> | 2005-09-01 15:50:04 +0400 |
---|---|---|
committer | Sureshkumar T <suresh@mono-cvs.ximian.com> | 2005-09-01 15:50:04 +0400 |
commit | cce8383f1edb8312d8170eb0a48e25857bec63cc (patch) | |
tree | 7838db379045aa5dbb4d56d79e8628f0919308ec /mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc | |
parent | 311746b41cf500aef15a68bf4a37bddcbba86ef4 (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')
6 files changed, 563 insertions, 0 deletions
diff --git a/mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/ChangeLog b/mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/ChangeLog new file mode 100644 index 00000000000..6ba64866a4c --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/ChangeLog @@ -0,0 +1,8 @@ +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 + diff --git a/mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/OdbcCommandBuilderTest.cs b/mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/OdbcCommandBuilderTest.cs new file mode 100644 index 00000000000..3d1f084c191 --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/OdbcCommandBuilderTest.cs @@ -0,0 +1,179 @@ +// OdbcCommandBuilderTest.cs - NUnit Test Cases for testing the +// OdbcCommandBuilder Test. +// +// Authors: +// Sureshkumar T (tsureshkumar@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 OdbcCommandBuilderTest + { + [Test] + public void GetInsertCommandTest () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + string selectQuery = "select id, lname from employee where id = 1"; + OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, (OdbcConnection) conn); + DataSet ds = new DataSet (); + da.Fill (ds, "IntTest"); + Assert.AreEqual (1, ds.Tables.Count, "#1 atleast one table should be filled"); + + OdbcCommandBuilder cb = new OdbcCommandBuilder (da); + OdbcCommand cmd = cb.GetInsertCommand (); + Assert.AreEqual ("INSERT INTO employee (id, lname) VALUES (?, ?)", + cmd.CommandText, "#2"); + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + + [Test] + public void GetInsertCommandTestWithExpression () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + string selectQuery = "select id, lname, id+1 as next_id from employee where id = 1"; + OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, (OdbcConnection) conn); + DataSet ds = new DataSet (); + da.Fill (ds, "IntTest"); + Assert.AreEqual (1, ds.Tables.Count, "#1 atleast one table should be filled"); + + OdbcCommandBuilder cb = new OdbcCommandBuilder (da); + OdbcCommand cmd = cb.GetInsertCommand (); + Assert.AreEqual ("INSERT INTO employee (id, lname) VALUES (?, ?)", + cmd.CommandText, "#2"); + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + + [Test] + public void GetUpdateCommandTest () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + using (conn) { + string selectQuery = "select id, lname, id+1 as next_id from employee where id = 1"; + OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, (OdbcConnection) conn); + DataSet ds = new DataSet (); + da.Fill (ds, "IntTest"); + Assert.AreEqual (1, ds.Tables.Count, "#1 atleast one table should be filled"); + + OdbcCommandBuilder cb = new OdbcCommandBuilder (da); + OdbcCommand cmd = cb.GetUpdateCommand (); + Assert.AreEqual ("UPDATE employee SET id = ?, lname = ? WHERE ((id = ?) AND ((? = 1 AND lname IS NULL) OR (lname = ?)))", + cmd.CommandText, "#2"); + Assert.AreEqual (5, cmd.Parameters.Count, "#3"); + } + } + + [Test] + [ExpectedException (typeof (DBConcurrencyException))] + public void GetUpdateCommandDBConcurrencyExceptionTest () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + string selectQuery = "select id, lname from employee where id = 1"; + OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, (OdbcConnection) conn); + DataSet ds = new DataSet (); + da.Fill (ds, "IntTest"); + Assert.AreEqual (1, ds.Tables.Count, "#1 atleast one table should be filled"); + + OdbcCommandBuilder cb = new OdbcCommandBuilder (da); + DataRow [] rows = ds.Tables [0].Select ("id=1"); + rows [0] [0] = 6660; // non existent + ds.Tables [0].AcceptChanges (); // moves 6660 to original value + rows [0] [0] = 1; // moves 6660 as search key into db table + da.Update (rows); + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + + [Test] + public void GetDeleteCommandTest () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + string selectQuery = "select id, lname, id+1 as next_id from employee where id = 1"; + OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, (OdbcConnection) conn); + DataSet ds = new DataSet (); + da.Fill (ds, "IntTest"); + Assert.AreEqual (1, ds.Tables.Count, "#1 atleast one table should be filled"); + + OdbcCommandBuilder cb = new OdbcCommandBuilder (da); + OdbcCommand cmd = cb.GetDeleteCommand (); + Assert.AreEqual ("DELETE FROM employee WHERE ((id = ?) AND ((? = 1 AND lname IS NULL) OR (lname = ?)))", + cmd.CommandText, "#2"); + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + + [Test] + public void DefaultPropertiesTest () + { + OdbcCommandBuilder cb = new OdbcCommandBuilder (); +#if NET_1_1 || NET_1_0 || ONLY_1_1 + Assert.AreEqual (ConflictOption.CompareAllSearchableValues, cb.ConflictDetection); +#endif // NET_1_1 || NET_1_0 || ONLY_1_1 + Assert.AreEqual ("", cb.QuotePrefix, "#5"); + Assert.AreEqual ("", cb.QuoteSuffix, "#6"); +#if NET_2_0 + Assert.AreEqual (".", cb.CatalogSeparator, "#2"); + Assert.AreEqual ("", cb.DecimalSeparator, "#3"); + Assert.AreEqual (".", cb.SchemaSeparator, "#4"); + Assert.AreEqual (CatalogLocation.Start, cb.CatalogLocation, "#1"); + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + conn.Open (); + cb = new OdbcCommandBuilder (); + Assert.AreEqual ("\"monotest\"", cb.QuoteIdentifier ("monotest", (OdbcConnection) conn), "#7"); + Assert.AreEqual ("monotest", cb.UnquoteIdentifier ("\"monotest\"", (OdbcConnection) conn), "#8"); + conn.Close (); + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + // FIXME: test SetAllValues +#endif // NET_2_0 + } + + // FIXME: Add tests for examining RowError + // FIXME: Add test for ContinueUpdateOnError property + + } +} 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 (); + } + } + + } +} diff --git a/mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/OdbcDataAdapterTest.cs b/mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/OdbcDataAdapterTest.cs new file mode 100644 index 00000000000..ab7901c0bd1 --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/OdbcDataAdapterTest.cs @@ -0,0 +1,79 @@ +// OdbcDataAdapterTest.cs - NUnit Test Cases for testing the +// OdbcDataAdapter class +// Author: +// Sureshkumar T (TSureshkumar@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.Odbc; + +using NUnit.Framework; + +namespace MonoTests.System.Data.Odbc +{ + + [TestFixture] + [Category ("odbc")] + public class OdbcDataAdapterTest + { + + [Test] + public void FillTest () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + // For this Test, you must create sample table + // called person-age, with a non-zero number of rows + // and non-zero number of columns + // run the test initialization script mono_test_mysql.sql + string tableName = "employee"; + string sql= "select * from " + tableName; + OdbcDataAdapter da = new OdbcDataAdapter (sql, (OdbcConnection) conn); + DataSet ds = new DataSet (tableName); + da.Fill (ds, tableName); + Assert.AreEqual (true, + ds.Tables.Count > 0, + "#1 Table count must not be zero"); + Assert.AreEqual (true, + ds.Tables [0].Rows.Count > 0, + "#2 Row count must not be zero"); + foreach (DataColumn dc in ds.Tables [0].Columns) + Assert.AreEqual (true, + dc.ColumnName.Length > 0, + "#3 DataSet column names must noot be of size 0"); + foreach (DataRow dr in ds.Tables [0].Rows) { + foreach (DataColumn dc in ds.Tables [0].Columns) + Assert.AreEqual (true, + dc.ColumnName.Length > 0, + "#4 column values must not be of size 0"); + } + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + } +} diff --git a/mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/OdbcDataReaderTest.cs b/mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/OdbcDataReaderTest.cs new file mode 100644 index 00000000000..b670e34ca6b --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/OdbcDataReaderTest.cs @@ -0,0 +1,75 @@ +// +// OdbcDataReaderTest.cs - NUnit Test Cases for testing the +// OdbcDataReader class +// +// Author: +// Sureshkumar T (TSureshkumar@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 OdbcDataReaderTest + { + [Test] + public void OutputParametersTest () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + IDbCommand cmd = conn.CreateCommand (); + cmd.CommandText = "call {? = sp_get_age (?,?)}"; + + OdbcParameter ret = (OdbcParameter) new OdbcParameter ("ret", OdbcType.Int); + cmd.Parameters.Add (ret); + ret.Direction = ParameterDirection.ReturnValue; + + OdbcParameter name = (OdbcParameter) new OdbcParameter ("name", OdbcType.VarChar); + cmd.Parameters.Add (name); + name.Direction = ParameterDirection.Input; + name.Value = "suresh"; + + OdbcParameter age = (OdbcParameter) new OdbcParameter ("age", OdbcType.Int); + cmd.Parameters.Add (age); + name.Direction = ParameterDirection.Output; + + IDataReader reader = cmd.ExecuteReader (); + reader.Close (); + Assert.AreEqual (true, ((int) ret.Value) > 0, "#1"); + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + } +} diff --git a/mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/OdbcParameterCollectionTest.cs b/mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/OdbcParameterCollectionTest.cs new file mode 100644 index 00000000000..a05207a258b --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/System.Data.Odbc/OdbcParameterCollectionTest.cs @@ -0,0 +1,66 @@ +// +// OdbcParameterCollectionTest.cs - NUnit Test Cases for testing the +// OdbcParameterCollection class +// Author: +// Sureshkumar T (TSureshkumar@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.Text; +using System.Data; +using System.Data.Odbc; + +using NUnit.Framework; + +namespace MonoTests.System.Data.Odbc +{ + [TestFixture] + [Category ("odbc")] + public class OdbcParameterCollectionTest + { + /// <remarks> + /// This tests whether the value is trimmed to the + /// given length while passing parameters + /// </remarks> + [Test] + public void ParameterLengthTrimTest () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + OdbcCommand cmd = (OdbcCommand) conn.CreateCommand (); + cmd.CommandType = CommandType.Text; + cmd.CommandText = "SELECT count(*) FROM employee WHERE fname=?"; + + OdbcParameter param = cmd.Parameters.Add("@fname", OdbcType.Text, 15); + param.Value = DateTime.Now.ToString (); + Assert.AreEqual (15, param.Size, "#1"); + Convert.ToInt32(cmd.ExecuteScalar()); + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + } +} |