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 | |
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')
41 files changed, 2444 insertions, 756 deletions
diff --git a/mcs/class/System.Data/System.Data_test.dll.sources b/mcs/class/System.Data/System.Data_test.dll.sources index 1c6e33c3ac9..4ed5ba243ae 100644 --- a/mcs/class/System.Data/System.Data_test.dll.sources +++ b/mcs/class/System.Data/System.Data_test.dll.sources @@ -70,6 +70,7 @@ System.Data.Common/DBDataPermissionTest.cs System.Data.Common/DbConnectionStringBuilderTest.cs System.Data.Odbc/OdbcPermissionAttributeTest.cs System.Data.Odbc/OdbcPermissionTest.cs +System.Data.Odbc/OdbcParameterCollectionTest.cs System.Data.OleDb/OleDbPermissionAttributeTest.cs System.Data.OleDb/OleDbPermissionTest.cs System.Data.SqlClient/SqlConnectionTest.cs diff --git a/mcs/class/System.Data/Test/ChangeLog b/mcs/class/System.Data/Test/ChangeLog index 6d7f5d65a5f..4df6e13f406 100644 --- a/mcs/class/System.Data/Test/ChangeLog +++ b/mcs/class/System.Data/Test/ChangeLog @@ -1,3 +1,9 @@ +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. + 2005-09-01 Boris Kirzner <borisk@mainsoft.com> * System.Data/DataRowCollectionTest.cs: Added another test case for Find(). diff --git a/mcs/class/System.Data/Test/ProviderTests/ChangeLog b/mcs/class/System.Data/Test/ProviderTests/ChangeLog new file mode 100644 index 00000000000..87fcaab9c24 --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/ChangeLog @@ -0,0 +1,20 @@ +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. + diff --git a/mcs/class/System.Data/Test/ProviderTests/Common/ChangeLog b/mcs/class/System.Data/Test/ProviderTests/Common/ChangeLog new file mode 100644 index 00000000000..63d82ce2712 --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/Common/ChangeLog @@ -0,0 +1,6 @@ +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 + diff --git a/mcs/class/System.Data/Test/ProviderTests/Common/ConnectionManager.cs b/mcs/class/System.Data/Test/ProviderTests/Common/ConnectionManager.cs new file mode 100644 index 00000000000..b41458ce5bb --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/Common/ConnectionManager.cs @@ -0,0 +1,89 @@ +// ConnectionManager.cs - Singleton ConnectionManager class to manage +// database connections for test cases. +// +// Authors: +// Sureshkumar T (tsureshkumar@novell.com) +// +// Copyright 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.Configuration; +using System.Data; +using Mono.Data; + +namespace MonoTests.System.Data +{ + public class ConnectionManager + { + private static ConnectionManager Instance; + private IDbConnection _connection; + private string _connectionString; + + static ConnectionManager () + { + Instance = new ConnectionManager (); + } + + private ConnectionManager () + { + string connectionString = ConfigurationSettings.AppSettings ["ConnString"]; + if (connectionString == null || connectionString.Equals (String.Empty)) { + throw new ArgumentException ("Connection string is invalid!"); + } + _connection = ProviderFactory.CreateConnectionFromConfig ("ConnString"); + _connectionString = Connection.ConnectionString; + } + + public static ConnectionManager Singleton + { + get {return Instance;} + } + + public IDbConnection Connection + { + get {return _connection;} + } + + public string ConnectionString + { + get {return _connectionString;} + } + + public void OpenConnection () + { + if (_connection == null) + _connection = ProviderFactory.CreateConnectionFromConfig ("ConnString"); + _connection.ConnectionString = _connectionString; + _connection.Open (); + } + + public void CloseConnection () + { + if (_connection != null && _connection.State != ConnectionState.Closed) + _connection.Close (); + } + + } +} diff --git a/mcs/class/System.Data/Test/ProviderTests/Common/DBHelper.cs b/mcs/class/System.Data/Test/ProviderTests/Common/DBHelper.cs new file mode 100644 index 00000000000..66f0a9906dc --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/Common/DBHelper.cs @@ -0,0 +1,85 @@ +// DBHelper.cs : Helper class for executing queries with database. +// +// 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.Text; +using System.Data.Common; +using System.Data.Odbc; +using Mono.Data; + +using NUnit.Framework; + +namespace MonoTests.System.Data +{ + public sealed class DBHelper + { + public static Random random = new Random ( (int) DateTime.Now.Ticks); + + public static int ExecuteNonQuery (IDbConnection connection ,string query) + { + IDbCommand command = connection.CreateCommand (); + command.CommandType = CommandType.Text; + command.CommandText = query; + int result = -1; + try { + result = command.ExecuteNonQuery (); + } catch (Exception e) { + return -2; + } + return result; + } + + public static int ExecuteSimpleSP (IDbConnection connection ,string proc) + { + IDbCommand command = connection.CreateCommand (); + command.CommandType = CommandType.StoredProcedure; + command.CommandText = proc; + int result = -1; + try { + result = command.ExecuteNonQuery (); + } catch (Exception e) { + return -2; + } + return result; + } + + public static string GetRandomName (string prefix, int length) + { + StringBuilder s = new StringBuilder (prefix.Length + 1 + length); + s.Append (prefix); + s.Append ("_"); + for (int i = 0; i < length; i++) { + s.Append (random.Next (25) + 'A'); + } + return s.ToString (); + } + } +} diff --git a/mcs/class/System.Data/Test/ProviderTests/Makefile b/mcs/class/System.Data/Test/ProviderTests/Makefile new file mode 100644 index 00000000000..aeb7224e96a --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/Makefile @@ -0,0 +1,37 @@ +thisdir=class/System.Data/Test/ProviderTests + + +include ../../../../build/rules.make + +LIB_MCS_FLAGS = /r:System.Data,System.Data.OracleClient,ByteFX.Data,Npgsql,System,System.Xml,nunit.framework,Mono.Data + +DATABASE=sql92 + +LIBRARY = System.Data.Connected.Tests.dll +NO_INSTALL=yes +NO_SIGN_ASSEMBLY=yes + + +${LIBRARY}: + $(MCS) $(LIB_MCS_FLAGS) /target:library /out:$@ /debug @$(LIBRARY).sources + +run-test-local: run-test-db +run-test-db: ${LIBRARY} +ifdef OSQLCMD + $(OSQLCMD) sql/$(DATABASE).sql +endif + cp app-$(PROFILE).config $(LIBRARY).config + unlink conn_string || : + ln -s $(DATABASE).config conn_string + ok=:; \ + $(TEST_RUNTIME) $(TEST_HARNESS) $(TEST_HARNESS_FLAGS) $(LOCAL_TEST_HARNESS_FLAGS) /output:TestResult-$(PROFILE).log /include=$(DATABASE) /xml:TestResult-$(PROFILE).xml $< || ok=false; \ + sed '1,/^Tests run: /d' TestResult-$(PROFILE).log; \ + $$ok + + +test-local: run-test-db + +CLEAN_FILES = *.exe *.dll *.log ${LIBRARY}.config *.mdb TestResult*.xml + +clean-local: + rm $(CLEAN_FILES) || : diff --git a/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/ChangeLog b/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/ChangeLog new file mode 100644 index 00000000000..31f00dcb7e0 --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/ChangeLog @@ -0,0 +1,6 @@ +2005-09-01 Sureshkumar T <tsureshkumar@novell.com> + + * IDbCommandTest.cs: Added. Provider independent Command tests. + + * DataReaderTest.cs: Added. Provider independent DataReader tests. + diff --git a/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/DataReaderTest.cs b/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/DataReaderTest.cs new file mode 100644 index 00000000000..b41fa2e6e43 --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/DataReaderTest.cs @@ -0,0 +1,230 @@ +// DataReaderTest.cs - NUnit Test Cases for testing the +// DataReader family of classes +// +// 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 Mono.Data; + +using NUnit.Framework; + +namespace MonoTests.System.Data +{ + [TestFixture] + [Category ("odbc"), Category ("sqlserver")] + public class DataReaderTest + { + [Test] + public void GetSchemaTableTest () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + IDbCommand cmd = conn.CreateCommand (); + cmd.CommandText = "select id, fname, id + 20 as plustwenty from employee"; + IDataReader reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly); + DataTable schema = reader.GetSchemaTable (); + reader.Close (); + Assert.AreEqual (3, schema.Rows.Count, "#1"); + + // Primary Key Test + DataRow pkRow = schema.Select ("ColumnName = 'id'") [0]; + Assert.AreEqual (false, pkRow.IsNull ("IsKey"), "#2"); + Assert.AreEqual (true, (bool) pkRow ["IsKey"], "#3"); + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + + + [Test] + public void GetNameTest () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + IDbCommand dbcmd = conn.CreateCommand (); + string sql = "SELECT type_tinyint from numeric_family"; + dbcmd.CommandText = sql; + using (IDataReader reader = dbcmd.ExecuteReader ()) { + Assert.AreEqual ("type_tinyint", reader.GetName (0), "#1 GetName failes"); + } + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + + [Test] + public void NumericTest() + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + IDbCommand dbCommand = conn.CreateCommand (); + dbCommand.CommandText = "select type_numeric from numeric_family where id = 1;"; + using(IDataReader reader = dbCommand.ExecuteReader ()) { + if (reader.Read()) { + object value = reader.GetValue(0); + Assert.AreEqual (typeof (decimal), value.GetType(), "#1 wrong type"); + Assert.AreEqual ( (decimal) 1000, value, "#2 value is wrong"); + } else + Assert.Fail ("#3 does not have test data"); + } + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + + [Test] + public void TinyIntTest () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + IDbCommand dbCommand = conn.CreateCommand (); + dbCommand.CommandText = "select type_tinyint from numeric_family where id = 1;"; + using(IDataReader reader = dbCommand.ExecuteReader ()) { + if (reader.Read()) { + object value = reader.GetValue (0); + Assert.AreEqual (typeof (byte), value.GetType(), "#1 wrong type"); + Assert.AreEqual (127, value, "#2 value is wrong"); + } else + Assert.Fail ("#3 does not have test data"); + } + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + + [Test] + public void GetByteTest () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + IDbCommand cmd = conn.CreateCommand (); + string query = "select type_tinyint from numeric_family where id = 1"; + cmd.CommandText = query; + using (IDataReader reader = cmd.ExecuteReader ()) { + if (reader.Read ()) { + byte b = reader.GetByte (0); + Assert.AreEqual (255, b, "GetByte returns wrong result"); + } else // This should not happen while testing + Assert.Fail ("test table does not have a test data!"); + } + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + + [Test] + public void GetValueBinaryTest () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + IDbCommand cmd = conn.CreateCommand (); + string sql = "select type_binary from binary_family where id = 1"; + cmd.CommandText = sql; + using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) { + if (reader.Read ()) { + object ob = reader.GetValue (0); + Assert.AreEqual (typeof (byte []), ob.GetType (), "#1 Type of binary column is wrong!"); + } else + Assert.Fail ("#2 test data not available"); + } + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + + [Test] + public void GetBytesNullBufferTest () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + IDbCommand cmd = conn.CreateCommand (); + // 4th row is null + string sql = "SELECT type_blob FROM binary_family where id = 1 or id = 4 order by id"; + cmd.CommandText = sql; + using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) { + if (reader.Read ()) { + Assert.AreEqual (8, reader.GetBytes (0, 0, null, 0, 0), + "#1 getbytes should return length of column"); + } else + Assert.Fail ("#2 No test data"); + // for null value, length in bytes should return 0 + if (reader.Read ()) + Assert.AreEqual (-1, reader.GetBytes (0, 0, null, 0, 0), + "#3 on null value, it should return -1"); + else + Assert.Fail ("#4 No test data"); + } + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + + [Test] + public void GetBytesTest () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + IDbCommand cmd = conn.CreateCommand (); + string sql = "SELECT type_blob FROM binary_family where id = 1"; + cmd.CommandText = sql; + using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) { + if (reader.Read ()) { + // Get By Parts for the column blob + long totalsize = reader.GetBytes (0, 0, null, 0, 0); + int buffsize = 5; + int start = 0; + int offset = 0; + long ret = 0; + long count = 0; + byte [] val = new byte [totalsize]; + do { + ret = reader.GetBytes (0, offset, val, offset, buffsize); + offset += (int) ret; + count += ret; + } while (count < totalsize); + Assert.AreEqual (8, count, + "#1 The assembled value length does not match"); + } else + Assert.Fail ("#2 no test data"); + } + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + } +} diff --git a/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/IDbCommandTest.cs b/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/IDbCommandTest.cs new file mode 100644 index 00000000000..c8caa32a203 --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/IDbCommandTest.cs @@ -0,0 +1,59 @@ +// IDbCommandTest.cs - NUnit Test Cases for testing the +// IDbCommand implemented classes. +// +// 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 Mono.Data; + +using NUnit.Framework; + +namespace MonoTests.System.Data +{ + [TestFixture] + [Category ("odbc"), Category ("sqlserver")] + public class CommandTest + { + [Test] + public void ExecuteScalarTest () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + IDbCommand cmd = conn.CreateCommand (); + cmd.CommandType = CommandType.Text; + cmd.CommandText = "select count(*) from employee where id < 3"; + Assert.AreEqual (2, cmd.ExecuteScalar (), "#1 there should be 2 records"); + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + } +} diff --git a/mcs/class/System.Data/Test/ProviderTests/README b/mcs/class/System.Data/Test/ProviderTests/README new file mode 100644 index 00000000000..eeef2c4e66e --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/README @@ -0,0 +1,99 @@ +RUN +=== + +Do this Once before running tests +--------------------------------- + * edit the connection string (app setting entry "ConnString") + - if you want to run odbc test cases, edit odbc.config + and edit the entry with "ConnString" with appropriate + DSN, User Id and Password. + + * run the sql schema and test pool data under directory sql to + the respective databases, using a appropriate client. + + eg. + tsql -S server -U user -P pwd < sql/sqlserver.sql + mysql -u user -p < sql/mysql.sql + +To run the tests +---------------- + + * make clean + * make run-test DATABASE=<ur-database> + valid database strings are : + sqlserver, odbc + +GUIDELINES for test-case developers +---------------------------------- + + general + ======= + + * Provider specific test case to go into their specific + subfolders named after their namespaces. All odbc specific + test-cases to go into System.Data.Odbc, etc. + + * all tables to have a unique id column + + * if you modify any data from a test case make sure, you + revert it at the end of test case, either through + try..finally block or using transactions + + * if you intend to insert from code, insert value above 6000 + (randomly chosen) + + + * if you create a stored procedure from code, create with a + prefix 'tmp_'. + + * if you create a table from code, create with a prefix + 'tmp_'. + + sqlserver + ========= + + * for temporary per-test-case tables/stored-procedures, prefix + the name with "#" so that mssql removes the object + automatically. + + +Extending to a new database +--------------------------- + + * All new databases can run the tests provided in + ProviderIndependant tests. Include your category in each of + the test cases. Say, if you want to extend these test cases + to a database provider 'xyz', include a line [Category + ("xyz")] with each of the test cases. + + * add a sql script file for you database to generate the test + data with same name you have given to the category with an + extension ".sql". For example, write a script file "xyz.sql" + under the sub-directory "sql". + + The test pool data can be obtained from either of the + existing sql script files say "mysql.sql". + + If your database does not support a datatype that are + used in other database script files, do *not* remove the + datatype instead, add a datatype nearly matching your local + type. For example, if your database does not support bigint, + add a column named type_bigint, but with type as "numeric + (19,0)". + + * Add a subdirectory with the name of the your provider's + namespace. If your provider is, say, XYZ, with namespace + System.Data.XYZ, Add a sub-directory System.Data.XYZ. Add + your provider specific tests to this directory with each + test case assigned to your category. + + * Add an application config file named after your database + name, same as the category name. Add an application key + called ConnString with the correct Connection String to your + database. This entry will be changed by the user when he + wants to run test on a different physical database. + + + IMPORTANT: + * Do *not* move any of the test cases to generic until you are + sure that they will run in all databases that are categorized.
\ No newline at end of file diff --git a/mcs/class/System.Data/Test/ProviderTests/System.Data.Connected.Tests.dll.sources b/mcs/class/System.Data/Test/ProviderTests/System.Data.Connected.Tests.dll.sources new file mode 100644 index 00000000000..1b414512c56 --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/System.Data.Connected.Tests.dll.sources @@ -0,0 +1,14 @@ +Common/ConnectionManager.cs +Common/DBHelper.cs +System.Data.Odbc/OdbcCommandBuilderTest.cs +System.Data.Odbc/OdbcCommandTest.cs +System.Data.Odbc/OdbcDataReaderTest.cs +System.Data.Odbc/OdbcDataAdapterTest.cs +System.Data.Odbc/OdbcParameterCollectionTest.cs +ProviderIndependant/DataReaderTest.cs +ProviderIndependant/IDbCommandTest.cs +System.Data.SqlClient/SqlCommandBuilderTest.cs +System.Data.SqlClient/SqlCommandTest.cs +System.Data.SqlClient/SqlDataReaderTest.cs +System.Data.SqlClient/SqlDataAdapterTest.cs +System.Data.SqlClient/SqlTransactionTest.cs 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 (); + } + } + } +} diff --git a/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/ChangeLog b/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/ChangeLog new file mode 100644 index 00000000000..155e8884489 --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/ChangeLog @@ -0,0 +1,13 @@ +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. + + diff --git a/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlCommandBuilderTest.cs b/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlCommandBuilderTest.cs new file mode 100644 index 00000000000..1640636dd1c --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlCommandBuilderTest.cs @@ -0,0 +1,183 @@ +// SqlCommandBuilderTest.cs - NUnit Test Cases for testing the +// SqlCommandBuilder class +// +// 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.SqlClient; +using Mono.Data; + +using NUnit.Framework; + +namespace MonoTests.System.Data +{ + [TestFixture] + [Category ("sqlserver")] + public class SqlCommandBuilderTest + { + [Test] + public void GetInsertCommandTest () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + string selectQuery = "select id, fname from employee where id = 1"; + SqlDataAdapter da = new SqlDataAdapter (selectQuery, (SqlConnection) conn); + DataSet ds = new DataSet (); + da.Fill (ds, "IntTest"); + Assert.AreEqual (1, ds.Tables.Count, "#1 atleast one table should be filled"); + + SqlCommandBuilder cb = new SqlCommandBuilder (da); + SqlCommand cmd = cb.GetInsertCommand (); + Assert.AreEqual ("INSERT INTO employee (id, fname) VALUES (?, ?)", + cmd.CommandText, "#2"); + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + + [Test] + public void GetInsertCommandTestWithExpression () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + string selectQuery = "select id, fname, id+1 as next_id from employee where id = 1"; + SqlDataAdapter da = new SqlDataAdapter (selectQuery, (SqlConnection) conn); + DataSet ds = new DataSet (); + da.Fill (ds, "IntTest"); + Assert.AreEqual (1, ds.Tables.Count, "#1 atleast one table should be filled"); + + SqlCommandBuilder cb = new SqlCommandBuilder (da); + SqlCommand cmd = cb.GetInsertCommand (); + Assert.AreEqual ("INSERT INTO employee (id, fname) VALUES (?, ?)", + cmd.CommandText, "#2"); + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + + [Test] + public void GetUpdateCommandTest () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + using (conn) { + string selectQuery = "select id, fname, id+1 as next_id from employee where id = 1"; + SqlDataAdapter da = new SqlDataAdapter (selectQuery, (SqlConnection) conn); + DataSet ds = new DataSet (); + da.Fill (ds, "IntTest"); + Assert.AreEqual (1, ds.Tables.Count, "#1 atleast one table should be filled"); + + SqlCommandBuilder cb = new SqlCommandBuilder (da); + SqlCommand cmd = cb.GetUpdateCommand (); + Assert.AreEqual ("UPDATE employee SET id = ?, fname = ? WHERE ((id = ?) AND ((? = 1 AND age IS NULL) OR (fname = ?)))", + cmd.CommandText, "#2"); + Assert.AreEqual (5, cmd.Parameters.Count, "#3"); + } + } + + [Test] + [ExpectedException (typeof (DBConcurrencyException))] + public void GetUpdateCommandDBConcurrencyExceptionTest () + { + IDbConnection conn = ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + string selectQuery = "select id, fname from employee where id = 1"; + SqlDataAdapter da = new SqlDataAdapter (selectQuery, (SqlConnection) conn); + DataSet ds = new DataSet (); + da.Fill (ds, "IntTest"); + Assert.AreEqual (1, ds.Tables.Count, "#1 atleast one table should be filled"); + + SqlCommandBuilder cb = new SqlCommandBuilder (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 { + ConnectionManager.Singleton.OpenConnection (); + string selectQuery = "select id, fname, id+1 as next_id from employee where id = 1"; + SqlDataAdapter da = new SqlDataAdapter (selectQuery, (SqlConnection) conn); + DataSet ds = new DataSet (); + da.Fill (ds, "IntTest"); + Assert.AreEqual (1, ds.Tables.Count, "#1 atleast one table should be filled"); + + SqlCommandBuilder cb = new SqlCommandBuilder (da); + SqlCommand cmd = cb.GetDeleteCommand (); + Assert.AreEqual ("DELETE FROM employee WHERE ((id = ?) AND ((? = 1 AND fname IS NULL) OR (fname = ?)))", + cmd.CommandText, "#2"); + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + + [Test] + public void DefaultPropertiesTest () + { + SqlCommandBuilder cb = new SqlCommandBuilder (); +#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 SqlCommandBuilder (); + Assert.AreEqual ("\"monotest\"", cb.QuoteIdentifier ("monotest", (SqlConnection) conn), "#7"); + Assert.AreEqual ("monotest", cb.UnquoteIdentifier ("\"monotest\"", (SqlConnection) 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.SqlClient/SqlCommandTest.cs b/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlCommandTest.cs new file mode 100644 index 00000000000..7180bd2f038 --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlCommandTest.cs @@ -0,0 +1,163 @@ +// +// SqlCommandTest.cs - NUnit Test Cases for testing the +// SqlCommand class +// Author: +// Umadevi S (sumadevi@novell.com) +// 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.SqlClient; + +using NUnit.Framework; + +namespace MonoTests.System.Data.SqlClient +{ + [TestFixture] + [Category ("sqlserver")] + public class SqlCommandTest + { + + public SqlConnection conn; + + [Test] + public void ExecuteNonQueryTempProcedureTest () { + conn = (SqlConnection) ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + // create temp sp here, should normally be created in Setup of test + // case, but cannot be done right now because of ug #68978 + DBHelper.ExecuteNonQuery (conn, CREATE_TMP_SP_TEMP_INSERT_PERSON); + SqlCommand cmd = new SqlCommand(); + cmd.Connection = conn; + cmd.CommandText = "#sp_temp_insert_employee"; + cmd.CommandType = CommandType.StoredProcedure; + Object TestPar = "test"; + cmd.Parameters.Add("@fname", SqlDbType.VarChar); + cmd.Parameters ["@fname"].Value = TestPar; + Assert.AreEqual(-1,cmd.ExecuteNonQuery()); + } finally { + DBHelper.ExecuteNonQuery (conn, DROP_TMP_SP_TEMP_INSERT_PERSON); + DBHelper.ExecuteSimpleSP (conn, "sp_clean_person_table"); + ConnectionManager.Singleton.CloseConnection (); + } + } + + /** + * Verifies whether an enum value is converted to a numeric value when + * used as value for a numeric parameter (bug #66630) + */ + [Test] + public void EnumParameterTest() { + conn = (SqlConnection) ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + // create temp sp here, should normally be created in Setup of test + // case, but cannot be done right now because of ug #68978 + DBHelper.ExecuteNonQuery (conn, "CREATE PROCEDURE #Bug66630 (" + + "@Status smallint = 7" + + ")" + + "AS" + Environment.NewLine + + "BEGIN" + Environment.NewLine + + "SELECT CAST(5 AS int), @Status" + Environment.NewLine + + "END"); + + SqlCommand cmd = new SqlCommand("#Bug66630", conn); + cmd.CommandType = CommandType.StoredProcedure; + cmd.Parameters.Add("@Status", SqlDbType.Int).Value = Status.Error; + + using (SqlDataReader dr = cmd.ExecuteReader()) { + // one record should be returned + Assert.IsTrue(dr.Read(), "EnumParameterTest#1"); + // we should get two field in the result + Assert.AreEqual(2, dr.FieldCount, "EnumParameterTest#2"); + // field 1 + Assert.AreEqual("int", dr.GetDataTypeName(0), "EnumParameterTest#3"); + Assert.AreEqual(5, dr.GetInt32(0), "EnumParameterTest#4"); + // field 2 + Assert.AreEqual("smallint", dr.GetDataTypeName(1), "EnumParameterTest#5"); + Assert.AreEqual((short) Status.Error, dr.GetInt16(1), "EnumParameterTest#6"); + // only one record should be returned + Assert.IsFalse(dr.Read(), "EnumParameterTest#7"); + } + } finally { + DBHelper.ExecuteNonQuery (conn, "if exists (select name from sysobjects " + + " where name like '#temp_Bug66630' and type like 'P') " + + " drop procedure #temp_Bug66630; "); + ConnectionManager.Singleton.CloseConnection (); + } + } + + /** + * The below test does not need a connection but since the setup opens + * the connection i will need to close it + */ + [Test] + public void CloneTest() { + ConnectionManager.Singleton.OpenConnection (); + SqlCommand cmd = new SqlCommand(); + cmd.Connection = null; + cmd.CommandText = "sp_insert"; + cmd.CommandType = CommandType.StoredProcedure; + Object TestPar = DBNull.Value; + cmd.Parameters.Add("@TestPar1", SqlDbType.Int); + cmd.Parameters["@TestPar1"].Value = TestPar; + cmd.Parameters.Add("@BirthDate", DateTime.Now); + cmd.DesignTimeVisible = true; + cmd.CommandTimeout = 100; + Object clone1 = ((ICloneable)(cmd)).Clone(); + SqlCommand cmd1 = (SqlCommand) clone1; + Assert.AreEqual(2, cmd1.Parameters.Count); + Assert.AreEqual(100, cmd1.CommandTimeout); + cmd1.Parameters.Add("@test", DateTime.Now); + // to check that it is deep copy and not a shallow copy of the + // parameter collection + Assert.AreEqual(3, cmd1.Parameters.Count); + Assert.AreEqual(2, cmd.Parameters.Count); + } + + private enum Status { + OK = 0, + Error = 3 + } + + private readonly string CREATE_TMP_SP_TEMP_INSERT_PERSON = ("create procedure #sp_temp_insert_employee ( " + Environment.NewLine + + "@fname varchar (20), " + Environment.NewLine + + "as " + Environment.NewLine + + "begin" + Environment.NewLine + + "declare @id int;" + Environment.NewLine + + "select @id = max (id) from employee;" + Environment.NewLine + + "set @id = @id + 6000 + 1;" + Environment.NewLine + + "insert into employee (id, fname, dob, doj) values (@id, @fname, '1980-02-11', getdate ());" + Environment.NewLine + + "return @id;" + Environment.NewLine + + "end"); + + private readonly string DROP_TMP_SP_TEMP_INSERT_PERSON = ("if exists (select name from sysobjects where " + Environment.NewLine + + "name = '#sp_temp_insert_employee' and type = 'P') " + Environment.NewLine + + "drop procedure #sp_temp_insert_employee; "); + } +} diff --git a/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlConnectionStringBuilderTest.cs b/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlConnectionStringBuilderTest.cs new file mode 100644 index 00000000000..9dea85d9c81 --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlConnectionStringBuilderTest.cs @@ -0,0 +1,129 @@ +// SqlConnectionStringBuilderTest.cs - NUnit Test Cases for Testing the +// SqlConnectionStringBuilder class +// +// Author: +// Sureshkumar T (tsureshkumar@novell.com) +// +// +// Copyright (C) 2004 Novell, Inc (http://www.novell.com) +// +// 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. +// + +#if NET_2_0 + +#region Using directives + +using System; +using System.Text; +using System.Collections; + +using System.Data; +using System.Data.SqlClient; + +using NUnit.Framework; + +#endregion + +namespace MonoTests.System.Data.Common +{ + + [TestFixture] + public class SqlConnectionStringBuilderTest + { + private SqlConnectionStringBuilder builder = null; + + [Test] + public void DefaultValuestTest () + { + builder = new SqlConnectionStringBuilder (); + Assert.AreEqual ("", builder.ConnectionString, "#DV1 default values is wrong"); + } + + [Test] + public void DefaultValuestTest2 () + { + builder = new SqlConnectionStringBuilder ("SERVER=localhost;"); + Assert.AreEqual ("Data Source=localhost", builder.ConnectionString, "#DVT1 default values is wrong"); + } + + [Test] + public void PropertiesTest () + { + builder = new SqlConnectionStringBuilder ("SERVER=localhost;"); + builder.AsynchronousProcessing = true; + builder.ApplicationName = "mono test"; + Assert.AreEqual (true, + builder.ConnectionString.Contains ("Asynchronous Processing=True"), + "#PT1 boolean value must be true"); + } + + [Test] + public void ItemTest () + { + builder = new SqlConnectionStringBuilder ("SERVER=localhost;"); + builder ["Network Library"] = "DBMSSOCN"; + Assert.AreEqual (true, + builder.ConnectionString.Contains ("Network Library=dbmssocn"), + "#PT1 network library should exist"); + } + + public void NullTest () + { + builder = new SqlConnectionStringBuilder ("SERVER=localhost;Network=DBMSSOCN"); + builder ["Network Library"] = null; + Assert.AreEqual ("Data Source=localhost", builder.ConnectionString, + "#NT1 should remove the key if set with null"); + } + + public void ContainsKeyTest () + { + builder = new SqlConnectionStringBuilder ("SERVER=localhost;Network=DBMSSOCN"); + Assert.AreEqual (true, builder.ContainsKey ("NETWORK"), + "#CKT1 should say true"); + Assert.AreEqual (false, builder.ContainsKey ("ABCD"), + "#CKT2 should say false"); + } + + [Test, ExpectedException (typeof (ArgumentException))] + public void InvalidKeyTest () + { + builder = new SqlConnectionStringBuilder ("SERVER=localhost;Network=DBMSSOCN"); + int value = (int) builder ["ABCD"]; + value++; // to avoid warning + } + + [Test] + public void RemoveTest () + { + builder = new SqlConnectionStringBuilder ("SERVER = localhost ;Network=DBMSSOCN"); + // non existing key + Assert.AreEqual (false, builder.Remove ("ABCD"), + "#RT1 cannot remove non existant key"); + Assert.AreEqual (true, builder.Remove ("NETWORK library"), + "#RT2 should remove the key"); + Assert.AreEqual ("Data Source=localhost", builder.ConnectionString, + "#RT3 should have removed the key"); + } + + } +} + +#endif // NET_2_0 diff --git a/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlDataAdapterTest.cs b/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlDataAdapterTest.cs new file mode 100644 index 00000000000..6121b4a924a --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlDataAdapterTest.cs @@ -0,0 +1,130 @@ +// +// SqlDataAdapterTest.cs - NUnit Test Cases for testing the +// SqlDataAdapter class +// Author: +// Umadevi S (sumadevi@novell.com) +// 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.SqlClient; + +using NUnit.Framework; + +namespace MonoTests.System.Data.SqlClient +{ + + [TestFixture] + [Category ("sqlserver")] + public class SqlDataAdapterTest + { + SqlConnection conn; + + [Test] + /** + The below test will not run everytime, since the region id column is unique + so change the regionid if you want the test to pass. + **/ + public void UpdateTest () { + conn = (SqlConnection) ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + DataTable dt = new DataTable(); + SqlDataAdapter da = null; + da = new SqlDataAdapter("Select * from employee;", conn); + SqlCommandBuilder cb = new SqlCommandBuilder (da); + da.Fill(dt); + DataRow dr = dt.NewRow(); + dr ["id"] = 6002; + dr ["fname"] = "boston"; + dr ["dob"] = DateTime.Now.Subtract (new TimeSpan (20*365, 0, 0, 0)); + dr ["doj"] = DateTime.Now; + dt.Rows.Add(dr); + + da.Update(dt); + } finally { + DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table"); + ConnectionManager.Singleton.CloseConnection (); + } + } + + [Test] + public void FillSchemaTest() + { + conn = (SqlConnection) ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + string sql = "select * from employee;"; + SqlCommand c = conn.CreateCommand(); + c.CommandText = sql; + SqlDataReader dr = c.ExecuteReader(CommandBehavior.KeyInfo|CommandBehavior.SchemaOnly); + DataTable schema = dr.GetSchemaTable(); + DataRowCollection drc = schema.Rows; + DataRow r = drc[0]; + Assert.AreEqual("id",r["ColumnName"].ToString()); + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + + /** + This needs a errortable created as follows + id uniqueidentifier,name char(10) , with values + Guid name + {A12...} NULL + NULL bbbbbb + **/ + [Test] + public void NullGuidTest() + { + conn = (SqlConnection) ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + DBHelper.ExecuteNonQuery (conn, "create table #tmp_guid_table ( " + + " id uniqueidentifier default newid (), " + + " name char (10))"); + DBHelper.ExecuteNonQuery (conn, "insert into #tmp_guid_table (name) values (null)"); + DBHelper.ExecuteNonQuery (conn, "insert into #tmp_guid_table (id, name) values (null, 'bbbb')"); + SqlDataAdapter da = new SqlDataAdapter("select * from #tmp_guid_table", conn); + DataSet ds = new DataSet(); + da.Fill(ds); + Assert.AreEqual (1, ds.Tables.Count, "#1"); + Assert.AreEqual (DBNull.Value, ds.Tables [0].Rows [1] ["id"], "#2"); + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + // the bug 68804 - is that the fill hangs! + Assert.AreEqual("Done","Done"); + + } + + + + + + } +} diff --git a/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlDataReaderTest.cs b/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlDataReaderTest.cs new file mode 100644 index 00000000000..fb786536128 --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlDataReaderTest.cs @@ -0,0 +1,91 @@ +// +// SqlDataReaderTest.cs - NUnit Test Cases for testing the +// SqlDataReader class +// Author: +// Umadevi S (sumadevi@novell.com) +// Kornél Pál <http://www.kornelpal.hu/> +// 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.SqlClient; + +using NUnit.Framework; + +namespace MonoTests.System.Data.SqlClient +{ + + [TestFixture] + [Category ("sqlserver")] + public class SqlDataReaderTest + { + SqlConnection conn; + + [Test] + public void ReadEmptyNTextFieldTest () { + conn = (SqlConnection) ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + DBHelper.ExecuteNonQuery (conn, "create table #tmp_monotest (name ntext)"); + DBHelper.ExecuteNonQuery (conn, "insert into #tmp_monotest values ('')"); + + SqlCommand cmd = (SqlCommand) conn.CreateCommand (); + cmd.CommandText = "select * from #tmp_monotest"; + SqlDataReader dr = cmd.ExecuteReader (); + if (dr.Read()) { + Assert.AreEqual("System.String",dr["NAME"].GetType().FullName); + } + Assert.AreEqual (false, dr.Read (), "#2"); + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + + [Test] + public void ReadBingIntTest() + { + conn = (SqlConnection) ConnectionManager.Singleton.Connection; + try { + ConnectionManager.Singleton.OpenConnection (); + string query = "SELECT CAST(548967465189498 AS bigint) AS Value"; + SqlCommand cmd = new SqlCommand(); + cmd.Connection = conn; + cmd.CommandText = query; + SqlDataReader r = cmd.ExecuteReader(); + using (r) { + Assert.AreEqual (true, r.Read(), "#1"); + long id = r.GetInt64(0); + Assert.AreEqual(548967465189498, id, "#2"); + id = r.GetSqlInt64(0).Value; + Assert.AreEqual(548967465189498, id, "#3"); + } + } finally { + ConnectionManager.Singleton.CloseConnection (); + } + } + } +} diff --git a/mcs/class/System.Data/Test/System.Data.SqlClient/SqlTransactionTest.cs b/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlTransactionTest.cs index b065effc0a1..b174470617b 100644 --- a/mcs/class/System.Data/Test/System.Data.SqlClient/SqlTransactionTest.cs +++ b/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlTransactionTest.cs @@ -1,85 +1,71 @@ -//
-// SqlTransactionTest.cs - NUnit Test Cases for testing the
-// SqlTransaction class
-// Author:
-// 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;
+// +// SqlTransactionTest.cs - NUnit Test Cases for testing the +// SqlTransaction class +// Author: +// Umadevi S (sumadevi@novell.com) +// 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.SqlClient;
-
-using NUnit.Framework;
-
+using System.Data.SqlClient; + +using NUnit.Framework; + namespace MonoTests.System.Data.SqlClient -{
-
- [TestFixture]
- public class SqlTransactionTest : MSSqlTestClient {
-
- [SetUp]
- public void GetReady () {
- OpenConnection ();
- }
-
- [TearDown]
- public void Clean () {
- CloseConnection ();
- } +{ - [Test]
- /** - The below test expects a table table4 with a bigint column. - **/ - public void TransactionCommitTest () { - - using (SqlTransaction transaction = conn.BeginTransaction()) + [TestFixture] + [Category ("sqlserver")] + public class SqlTransactionTest + { + [Test] + public void TransactionCommitTest () { - try - { - string sSql = "Insert into Region(RegionID,RegionDescription) Values ('10112', 'NovellBangalore')"; - SqlCommand command = new SqlCommand(); - command.Connection = conn; - command.CommandText = sSql; - command.Transaction = transaction; - command.CommandType = CommandType.Text; - command.ExecuteNonQuery(); - transaction.Commit(); - } - catch (Exception) - { - transaction.Rollback(); + SqlConnection conn = new SqlConnection (ConnectionManager.Singleton.ConnectionString); + try { + conn.Open (); + using (SqlTransaction transaction = conn.BeginTransaction()) + { + string sSql = "Insert into employee (id, fname, dob, doj) Values (6005, 'NovellBangalore', '1989-02-11', '2005-07-22')"; + SqlCommand command = new SqlCommand(); + command.Connection = conn; + command.CommandText = sSql; + command.Transaction = transaction; + command.CommandType = CommandType.Text; + command.ExecuteNonQuery(); + transaction.Commit(); + } + } finally { + DBHelper.ExecuteSimpleSP (conn, "sp_clean_person_table"); + if (conn != null && conn.State != ConnectionState.Closed) + conn.Close (); } - finally - { - conn.Close(); - } - + } - } - }
-}
+ } +} diff --git a/mcs/class/System.Data/Test/ProviderTests/app-default.config b/mcs/class/System.Data/Test/ProviderTests/app-default.config new file mode 100644 index 00000000000..0d82601d83e --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/app-default.config @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <configSections> + <sectionGroup name="mono.data"> + <section name="providers" type="Mono.Data.ProviderSectionHandler,Mono.Data" /> + </sectionGroup> + </configSections> + <appSettings file="conn_string"> + </appSettings> + <mono.data> + <providers> + <provider name="System.Data.SqlClient" connection="System.Data.SqlClient.SqlConnection" + adapter="System.Data.SqlClient.SqlDataAdapter" + command="System.Data.SqlClient.SqlCommand" + assembly="System.Data, Version=1.0.5000.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089"/> + <provider name="System.Data.OleDb" connection="System.Data.OleDb.OleDbConnection" + adapter="System.Data.OleDb.OleDbDataAdapter" + command="System.Data.OleDb.OleDbCommand" + assembly="System.Data, Version=1.0.5000.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089"/> + <provider name="System.Data.Odbc" connection="System.Data.Odbc.OdbcConnection" + adapter="System.Data.OleDb.OdbcDataAdapter" + command="System.Data.OleDb.OdbcCommand" + assembly="System.Data, Version=1.0.5000.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089"/> + <provider name="Mono.Data.TdsClient" connection="Mono.Data.TdsClient.TdsConnection" + adapter="Mono.Data.TdsClient.TdsDataAdapter" + command="System.Data.OleDb.TdsCommand" + assembly="Mono.Data.TdsClient" /> + <provider name="Mono.Data.MySql" connection="Mono.Data.MySql.MySqlConnection" + adapter="Mono.Data.MySql.MySqlDataAdapter" + command="System.Data.OleDb.MySqlCommand" + assembly="Mono.Data.MySql" /> + <provider name="Mono.Data.PostgreSqlClient" + connection="Mono.Data.PostgreSqlClient.PgSqlConnection" + adapter="Mono.Data.PostgreSqlClient.PgSqlDataAdapter" + command="System.Data.OleDb.PgSqlCommand" + assembly="Mono.Data.PostgreSqlClient" /> + <provider name="Mono.Data.SqliteClient" + connection="Mono.Data.SqliteClient.SqliteConnection" + adapter="Mono.Data.SqliteClient.SqliteDataAdapter" + command="System.Data.OleDb.SqliteCommand" + assembly="Mono.Data.SqliteClient" /> + <provider name="Mono.Data.SybaseClient" + connection="Mono.Data.SybaseClient.SybaseConnection" + adapter="Mono.Data.SybaseClient.SybaseDataAdapter" + command="System.Data.OleDb.SybaseCommand" + assembly="Mono.Data.SybaseClient" /> + </providers> + </mono.data> +</configuration> diff --git a/mcs/class/System.Data/Test/ProviderTests/app-net_2_0.config b/mcs/class/System.Data/Test/ProviderTests/app-net_2_0.config new file mode 100644 index 00000000000..1e588591740 --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/app-net_2_0.config @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <configSections> + <sectionGroup name="mono.data"> + <section name="providers" type="Mono.Data.ProviderSectionHandler,Mono.Data" /> + </sectionGroup> + </configSections> + <appSettings file="conn_string"> + </appSettings> + <mono.data> + <providers> + <provider name="System.Data.SqlClient" connection="System.Data.SqlClient.SqlConnection" + adapter="System.Data.SqlClient.SqlDataAdapter" + command="System.Data.SqlClient.SqlCommand" + assembly="System.Data, Version=2.0.3600.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089"/> + <provider name="System.Data.OleDb" connection="System.Data.OleDb.OleDbConnection" + adapter="System.Data.OleDb.OleDbDataAdapter" + command="System.Data.OleDb.OleDbCommand" + assembly="System.Data, Version=2.0.3600.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089"/> + <provider name="System.Data.Odbc" connection="System.Data.Odbc.OdbcConnection" + adapter="System.Data.OleDb.OdbcDataAdapter" + command="System.Data.OleDb.OdbcCommand" + assembly="System.Data, Version=2.0.3600.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089"/> + <provider name="Mono.Data.TdsClient" connection="Mono.Data.TdsClient.TdsConnection" + adapter="Mono.Data.TdsClient.TdsDataAdapter" + command="System.Data.OleDb.TdsCommand" + assembly="Mono.Data.TdsClient" /> + <provider name="Mono.Data.MySql" connection="Mono.Data.MySql.MySqlConnection" + adapter="Mono.Data.MySql.MySqlDataAdapter" + command="System.Data.OleDb.MySqlCommand" + assembly="Mono.Data.MySql" /> + <provider name="Mono.Data.PostgreSqlClient" + connection="Mono.Data.PostgreSqlClient.PgSqlConnection" + adapter="Mono.Data.PostgreSqlClient.PgSqlDataAdapter" + command="System.Data.OleDb.PgSqlCommand" + assembly="Mono.Data.PostgreSqlClient" /> + <provider name="Mono.Data.SqliteClient" + connection="Mono.Data.SqliteClient.SqliteConnection" + adapter="Mono.Data.SqliteClient.SqliteDataAdapter" + command="System.Data.OleDb.SqliteCommand" + assembly="Mono.Data.SqliteClient" /> + <provider name="Mono.Data.SybaseClient" + connection="Mono.Data.SybaseClient.SybaseConnection" + adapter="Mono.Data.SybaseClient.SybaseDataAdapter" + command="System.Data.OleDb.SybaseCommand" + assembly="Mono.Data.SybaseClient" /> + </providers> + </mono.data> +</configuration> diff --git a/mcs/class/System.Data/Test/ProviderTests/odbc.config b/mcs/class/System.Data/Test/ProviderTests/odbc.config new file mode 100644 index 00000000000..55e205c33d2 --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/odbc.config @@ -0,0 +1,6 @@ +<appSettings> + <add key="ConnString" value="factory=System.Data.Odbc;dsn=mysql-mono-test2;UID=monotester;PWD=;"/> + <add key="postgres" value="factory=System.Data.Odbc;dsn=Postgres-Mono-monotest;UID=mono-tester;PWD=;"/> + <add key="mysql" value="factory=System.Data.Odbc;dsn=mysql-mono-test;UID=mono-tester;PWD=;"/> + <add key="sqlserver" value="factory=System.Data.Odbc;dsn=SqlServer;UID=sa;PWD=;"/> +</appSettings> diff --git a/mcs/class/System.Data/Test/ProviderTests/sql/ChangeLog b/mcs/class/System.Data/Test/ProviderTests/sql/ChangeLog new file mode 100644 index 00000000000..f560dfcf536 --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/sql/ChangeLog @@ -0,0 +1,10 @@ +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. + diff --git a/mcs/class/System.Data/Test/ProviderTests/sql/SCHEMA b/mcs/class/System.Data/Test/ProviderTests/sql/SCHEMA new file mode 100644 index 00000000000..a23cff686f4 --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/sql/SCHEMA @@ -0,0 +1,90 @@ +DATABASE: monotest + + +========================== TABLE : numeric_family ================================== +TABLE: numeric_family + id int PRIMARY KEY NOT NULL + type_bit bit NULL + type_tinyint tinyint NULL + type_smallint smallint NULL + type_int int NULL + type_bigint bigint NULL + type_decimal decimal (38, 0) NULL + type_numeric numeric (38, 0) NULL + type_money money NULL + type_smallmoney smallmoney NULL + +DATA: + +insert into numeric_family values (1,1,255,32767,2147483647,9223372036854775807,1000,1000,922337203685477.5807,214748.3647); +insert into numeric_family values (2,0,0,-32768,-2147483648,-9223372036854775808,-1000,-1000,-922337203685477.5808,-214748.3648); +insert into numeric_family values (3,0,0,0,0,0,0,0,0,0); +insert into numeric_family values (4,null,null,null,null,null,null,null,null,null); +go + +========================== END TABLE : numeric_family =============================== + + +========================== TABLE : binary_family ==================================== +TABLE: binary_family + + id int PRIMARY KEY NOT NULL + type_binary binary NULL + type_varbinary varbinary (255) NULL + type_blob image NULL + type_tinyblob image NULL + type_mediumblob image NULL + type_longblob_image image NULL + + + +insert into binary_family values (1, convert (image, '555555'), convert (image, '0123456789012345678901234567890123456789012345678901234567890123456789'), + convert (image, '66666666'), convert (image, '777777'), + convert (image, '888888'), convert (image, '999999')); +--insert into binary_family values (2, +--insert into binary_family values (3, +insert into binary_family values (4,null,null,null,null,null,null); + +========================== END TABLE : binary_family ================================ + + +=================================== TABLE: EMPLOYEE ================================ +TABLE : employee + + id int PRIMARY KEY NOT NULL + fname varchar (50) NOT NULL + lname varchar (50) NULL + dob datetime NOT NULL + doj datetime NOT NULL + email varchar (50) NULL + + +insert into employee values (1, 'suresh', 'kumar', '1978-08-22', '2001-03-12', 'suresh@gmail.com'); +insert into employee values (2, 'ramesh', 'rajendran', '1977-02-15', '2005-02-11', 'ramesh@yahoo.com'); +insert into employee values (3, 'venkat', 'ramakrishnan', '1977-06-12', '2003-12-11', 'ramesh@yahoo.com'); +insert into employee values (4, 'ramu', 'dhasarath', '1977-02-15', '2005-02-11', 'ramesh@yahoo.com'); + +=============================== END TABLE: EMPLOYEE ================================ + + +=============================== STORED PROCEDURE : sp_clean_employee_table ========= +SP : sp_clean_employee_table + +NAME: sp_clean_employee_table + +PROCESS: + delete from employee where id > 6000; + +============================ END STORED PROCEDURE : sp_clean_employee_table ========= + + +============================ STORED PROCEDURE : sp_get_age ========================== +NAME: procedure sp_get_age +PARAMETER : + NAME : fname TYPE: varchar (50) DIRECTION : in + NAME : age TYPE: int DIRECTION : out +PROCESS: + select age = datediff (day, dob, getdate ()) from employee where fname like fname; + return age; + + =================================== END PROCEDURE : sp_get_age =====================
\ No newline at end of file diff --git a/mcs/class/System.Data/Test/ProviderTests/sql/mysql.sql b/mcs/class/System.Data/Test/ProviderTests/sql/mysql.sql new file mode 100644 index 00000000000..4b1723f30bd --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/sql/mysql.sql @@ -0,0 +1,105 @@ +delimiter // +use monotest +// + +-- =================================== OBJECT NUMERIC_FAMILY ========================= +-- TABLE : INT_FAMILY +-- data with id > 6000 is not gaurenteed to be read-only. +drop table if exists numeric_family; +// + +create table numeric_family ( + id int PRIMARY KEY NOT NULL, + type_bit bit NULL, + type_tinyint tinyint NULL, + type_smallint smallint NULL, + type_int int NULL, + type_bigint bigint NULL, + type_decimal decimal (38, 0) NULL, + type_numeric numeric (38, 0) NULL, + type_money numeric (38,0) NULL, + type_smallmoney numeric (12,0) NULL); +-- does not have money & smallmoney types +// + +insert into numeric_family values (1,1,255,32767,2147483647,9223372036854775807,1000,1000,922337203685477.5807,214748.3647); +insert into numeric_family values (2,0,0,-32768,-2147483648,-9223372036854775808,-1000,-1000,-922337203685477.5808,-214748.3648); +insert into numeric_family values (3,0,0,0,0,0,0,0,0,0); +insert into numeric_family values (4,null,null,null,null,null,null,null,null,null); +// + +-- =================================== END OBJECT NUMERIC_FAMILY ======================== + +-- =================================== OBJECT BINARY_FAMILY ========================= +-- TABLE : INT_FAMILY +-- data with id > 6000 is not gaurenteed to be read-only. +drop table if exists binary_family; +// + +create table binary_family ( + id int PRIMARY KEY NOT NULL, + type_binary binary NULL, + type_varbinary varbinary (255) NULL, + type_blob blob NULL, + type_tinyblob tinyblob NULL, + type_mediumblob mediumblob NULL, + type_longblob_image longblob NULL); +// + +insert into binary_family values (1, '555555', '0123456789012345678901234567890123456789012345678901234567890123456789', '66666666', '777777', '888888', '999999'); +--insert into binary_family values (2, +--insert into binary_family values (3, +insert into binary_family values (4,null,null,null,null,null,null); +// + +-- =================================== END OBJECT BINARY_FAMILY ======================== + + +-- =================================== OBJECT EMPLOYEE ============================ +-- TABLE : EMPLOYEE +-- data with id above 6000 is not gaurenteed to be read-only. +drop table if exists employee; +// + +create table employee ( + id int PRIMARY KEY NOT NULL, + fname varchar (50) NOT NULL, + lname varchar (50), + dob datetime NOT NULL, + doj datetime NOT NULL, + email varchar (50)); + +grant all privileges on employee to monotester; + +insert into employee values (1, 'suresh', 'kumar', '1978-08-22', '2001-03-12', 'suresh@gmail.com'); +insert into employee values (2, 'ramesh', 'rajendran', '1977-02-15', '2005-02-11', 'ramesh@yahoo.com'); +insert into employee values (3, 'venkat', 'ramakrishnan', '1977-06-12', '2003-12-11', 'ramesh@yahoo.com'); +insert into employee values (4, 'ramu', 'dhasarath', '1977-02-15', '2005-02-11', 'ramesh@yahoo.com'); +// + +-- STORED PROCEDURES +-- SP : sp_clean_person_table +drop procedure if exists sp_clean_employee_table; +// + +create procedure sp_clean_employee_table () +begin + delete from employee where id > 6000; +end +// + +-- SP : sp_get_age +drop procedure if exists sp_get_age; +// + +create procedure sp_get_age ( + fname varchar (50), + OUT age int) +as +begin + select age = datediff (day, dob, getdate ()) from employee where fname like fname; + return age; +end +// + +-- =================================== END OBJECT EMPLOYEE ============================
\ No newline at end of file diff --git a/mcs/class/System.Data/Test/ProviderTests/sql/sqlserver.sql b/mcs/class/System.Data/Test/ProviderTests/sql/sqlserver.sql new file mode 100644 index 00000000000..b56e1cf7ce2 --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/sql/sqlserver.sql @@ -0,0 +1,119 @@ +use monotest +go + +-- =================================== OBJECT EMPLOYEE ============================ +-- TABLE : INT_FAMILY +-- data with id > 6000 is not gaurenteed to be read-only. +if exists (select name from sysobjects where + name = 'numeric_family' and type = 'U') + drop table numeric_family; +go + +create table numeric_family ( + id int PRIMARY KEY NOT NULL, + type_bit bit NULL, + type_tinyint tinyint NULL, + type_smallint smallint NULL, + type_int int NULL, + type_bigint bigint NULL, + type_decimal decimal (38, 0) NULL, + type_numeric numeric (38, 0) NULL, + type_money money NULL, + type_smallmoney smallmoney NULL); +go + +insert into numeric_family values (1,1,255,32767,2147483647,9223372036854775807,1000,1000,922337203685477.5807,214748.3647); +insert into numeric_family values (2,0,0,-32768,-2147483648,-9223372036854775808,-1000,-1000,-922337203685477.5808,-214748.3648); +insert into numeric_family values (3,0,0,0,0,0,0,0,0,0); +insert into numeric_family values (4,null,null,null,null,null,null,null,null,null); +go + +-- =================================== END OBJECT EMPLOYEE ======================== + +-- =================================== OBJECT BINARY_FAMILY ========================= +-- TABLE : INT_FAMILY +-- data with id > 6000 is not gaurenteed to be read-only. +if exists (select name from sysobjects where + name = 'employee' and type = 'U') + drop table binary_family; +go + +create table binary_family ( + id int PRIMARY KEY NOT NULL, + type_binary binary NULL, + type_varbinary varbinary (255) NULL, + type_blob image NULL, + type_tinyblob image NULL, + type_mediumblob image NULL, + type_longblob_image image NULL); +go + +insert into binary_family values (1, convert (image, '555555'), convert (image, '0123456789012345678901234567890123456789012345678901234567890123456789'), + convert (image, '66666666'), convert (image, '777777'), + convert (image, '888888'), convert (image, '999999')); +--insert into binary_family values (2, +--insert into binary_family values (3, +insert into binary_family values (4,null,null,null,null,null,null); +go + +-- =================================== END OBJECT BINARY_FAMILY ======================== + + +-- =================================== OBJECT EMPLOYEE ============================ +-- TABLE : EMPLOYEE +-- data with id above 6000 is not gaurenteed to be read-only. +if exists (select name from sysobjects where + name = 'employee' and type = 'U') + drop table employee; +go + +create table employee ( + id int PRIMARY KEY NOT NULL, + fname varchar (50) NOT NULL, + lname varchar (50) NULL, + dob datetime NOT NULL, + doj datetime NOT NULL, + email varchar (50) NULL); + +grant all privileges on employee to monotester; + +insert into employee values (1, 'suresh', 'kumar', '1978-08-22', '2001-03-12', 'suresh@gmail.com'); +insert into employee values (2, 'ramesh', 'rajendran', '1977-02-15', '2005-02-11', 'ramesh@yahoo.com'); +insert into employee values (3, 'venkat', 'ramakrishnan', '1977-06-12', '2003-12-11', 'ramesh@yahoo.com'); +insert into employee values (4, 'ramu', 'dhasarath', '1977-02-15', '2005-02-11', 'ramesh@yahoo.com'); +go + +-- STORED PROCEDURES +-- SP : sp_clean_person_table +if exists (select name from sysobjects where + name = 'sp_clean_employee_table' and type = 'P') + drop procedure sp_clean_employee_table; +go + +create procedure sp_clean_employee_table +as +begin + delete from employee where id > 6000; +end +go + + +-- SP : sp_get_age +if exists (select name from sysobjects where + name = 'sp_get_age' and type = 'P') + drop procedure sp_get_age; +go + +create procedure sp_get_age ( + @fname varchar (50), + @age int output) +as +begin + select @age = datediff (day, dob, getdate ()) from employee where fname like @fname; + return @age; +end +go + + + +-- =================================== END OBJECT EMPLOYEE ============================
\ No newline at end of file diff --git a/mcs/class/System.Data/Test/ProviderTests/sqlserver.config b/mcs/class/System.Data/Test/ProviderTests/sqlserver.config new file mode 100644 index 00000000000..ee3db292c0d --- /dev/null +++ b/mcs/class/System.Data/Test/ProviderTests/sqlserver.config @@ -0,0 +1,3 @@ +<appSettings> + <add key="ConnString" value="factory=System.Data.SqlClient;server=mono-server;database=monotest;user id=sa;password=;" /> +</appSettings> diff --git a/mcs/class/System.Data/Test/System.Data.Odbc/ChangeLog b/mcs/class/System.Data/Test/System.Data.Odbc/ChangeLog index 46c29042d25..57c7f8f668f 100644 --- a/mcs/class/System.Data/Test/System.Data.Odbc/ChangeLog +++ b/mcs/class/System.Data/Test/System.Data.Odbc/ChangeLog @@ -1,3 +1,12 @@ +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. + 2005-02-15 Sureshkumar T <tsureshkumar@novell.com> * OdbcParameterCollectionTest.cs: fix for namespace collision diff --git a/mcs/class/System.Data/Test/System.Data.Odbc/OdbcCommandTest.cs b/mcs/class/System.Data/Test/System.Data.Odbc/OdbcCommandTest.cs deleted file mode 100644 index 78ebeb4ab72..00000000000 --- a/mcs/class/System.Data/Test/System.Data.Odbc/OdbcCommandTest.cs +++ /dev/null @@ -1,115 +0,0 @@ -//
-// 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.Odbc;
-
-using NUnit.Framework;
-
-namespace MonoTests.System.Data.Odbc
-{
-
- [TestFixture]
- public class OdbcCommandTest : MySqlOdbcBaseClient
- {
-
- [SetUp]
- public void GetReady () {
- OpenConnection ();
- CreateTestSetup (); // create database & test tables
- }
-
- [TearDown]
- public void Clean () {
- CleanTestSetup (); // clean test database;
- CloseConnection ();
- }
-
- /// <summary>
- /// Test Execute Scalar Method
- /// </summary>
- [Test]
- public void ExecuteScalarTest ()
- {
- OdbcCommand cmd = conn.CreateCommand ();
- string query = "select count(*) from test order by col_int;";
- cmd.CommandText = query;
- object objCount = cmd.ExecuteScalar ();
- Assertion.AssertEquals( "ExecuteScalar does not return int type", 5, Convert.ToInt32(objCount));
- }
-
- /// <summary>
- /// Test String parameters to ODBC Command
- /// </summary>
- [Test]
- public void ExecuteStringParameterTest()
- {
-
- OdbcCommand dbcmd = new OdbcCommand();
- dbcmd.Connection = conn;
- dbcmd.CommandType = CommandType.Text;
- dbcmd.CommandText = "select count(*) from test where col_char=?;";
- string colvalue = "mono test#1";
- dbcmd.Parameters.Add("@un",colvalue);
- Object obj = dbcmd.ExecuteScalar();
- Assertion.AssertEquals( "String parameter not passed correctly",1, Convert.ToInt32(obj));
-
-
- }
-
- /// <summary>
- /// Test ExecuteNonQuery
- /// </summary>
- [Test]
- public void ExecuteNonQueryTest ()
- {
-
- OdbcCommand dbcmd = new OdbcCommand();
- dbcmd.Connection = conn;
- dbcmd.CommandType = CommandType.Text;
- dbcmd.CommandText = "select count(*) from test where col_char=?;";
- string colvalue = "mono test";
- dbcmd.Parameters.Add("@un",colvalue);
- int ret = dbcmd.ExecuteNonQuery();
- Assertion.AssertEquals( "ExecuteNonQuery not working",-1, ret);
- dbcmd = new OdbcCommand();
- dbcmd.Connection = conn;
- dbcmd.CommandType = CommandType.Text;
- dbcmd.CommandText = "delete from test where (col_int >257);";
- ret = dbcmd.ExecuteNonQuery();
- Assertion.AssertEquals("ExecuteNonQuery not working", 2, ret);
-
- }
-
- }
-}
diff --git a/mcs/class/System.Data/Test/System.Data.Odbc/OdbcDataAdapterTest.cs b/mcs/class/System.Data/Test/System.Data.Odbc/OdbcDataAdapterTest.cs deleted file mode 100644 index fd8408b1876..00000000000 --- a/mcs/class/System.Data/Test/System.Data.Odbc/OdbcDataAdapterTest.cs +++ /dev/null @@ -1,82 +0,0 @@ -//
-// 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]
- public class OdbcDataAdapterTest : MySqlOdbcBaseClient {
-
- [SetUp]
- public void GetReady () {
- OpenConnection ();
- CreateTestSetup (); // create test database & tables
- }
-
- [TearDown]
- public void Clean () {
- CleanTestSetup (); // clean test database
- CloseConnection ();
- }
-
- [Test]
- public void FillTest () {
- try {
- // For this Test, you must create sample table
- // called test, with a non-zero number of rows
- // and non-zero number of columns
- // run the test initialization script mono_test_mysql.sql
- string tableName = "test";
- string sql= "select * from " + tableName;
- OdbcDataAdapter da = new OdbcDataAdapter (sql, conn);
- DataSet ds = new DataSet (tableName);
- da.Fill (ds, tableName);
- Assertion.AssertEquals ("Table count must not be zero", true, ds.Tables.Count > 0 );
- Assertion.AssertEquals ("Row count must not be zero", true, ds.Tables [0].Rows.Count > 0 );
- foreach (DataColumn dc in ds.Tables [0].Columns)
- Assertion.AssertEquals ("DataSet column names must noot be of size 0", true,
- dc.ColumnName.Length > 0);
- foreach (DataRow dr in ds.Tables [0].Rows) {
- foreach (DataColumn dc in ds.Tables [0].Columns)
- Assertion.AssertEquals("column values must not be of size 0", true,
- dc.ColumnName.Length > 0);
- }
- } finally { // try/catch is necessary to gracefully close connections
- CleanTestSetup (); // clean test database
- CloseConnection ();
- }
- }
- }
-}
diff --git a/mcs/class/System.Data/Test/System.Data.Odbc/OdbcParameterCollectionTest.cs b/mcs/class/System.Data/Test/System.Data.Odbc/OdbcParameterCollectionTest.cs index df60551ea20..ad784688419 100644 --- a/mcs/class/System.Data/Test/System.Data.Odbc/OdbcParameterCollectionTest.cs +++ b/mcs/class/System.Data/Test/System.Data.Odbc/OdbcParameterCollectionTest.cs @@ -38,7 +38,7 @@ namespace MonoTests.System.Data.Odbc { [TestFixture] - public class OdbcParameterCollectionTest : MySqlOdbcBaseClient + public class OdbcParameterCollectionTest { [Test] public void OdbcParameterAddTest () @@ -76,29 +76,5 @@ namespace MonoTests.System.Data.Odbc Assert.AreEqual (0, param.Size, "#8"); } - - /// <remarks> - /// This tests whether the value is trimmed to the - /// given length while passing parameters - /// </remarks> - [Test] - public void ParameterLengthTrimTest () - { - OpenConnection (); - try { - OdbcCommand cmd = new OdbcCommand(); - cmd.Connection = conn; - cmd.CommandType = CommandType.Text; - cmd.CommandText = "SELECT count(*) FROM test WHERE col_char=?"; - - OdbcParameter param = cmd.Parameters.Add("@col_char", OdbcType.Text, 15); - param.Value = DateTime.Now.ToString (); - Assert.AreEqual (15, param.Size, "#1"); - Convert.ToInt32(cmd.ExecuteScalar()); - } finally { - CloseConnection (); - - } - } } } diff --git a/mcs/class/System.Data/Test/System.Data.SqlClient/ChangeLog b/mcs/class/System.Data/Test/System.Data.SqlClient/ChangeLog index 3a70fc53465..4bf8a9a55fd 100644 --- a/mcs/class/System.Data/Test/System.Data.SqlClient/ChangeLog +++ b/mcs/class/System.Data/Test/System.Data.SqlClient/ChangeLog @@ -1,3 +1,12 @@ +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 -- + 2005-06-23 Sureshkumar T <tsureshkumar@novell.com> * SqlConnectionStringBuilderTest.cs: Added few more tests. diff --git a/mcs/class/System.Data/Test/System.Data.SqlClient/SqlCommandTest.cs b/mcs/class/System.Data/Test/System.Data.SqlClient/SqlCommandTest.cs deleted file mode 100644 index 0cd47efc1e7..00000000000 --- a/mcs/class/System.Data/Test/System.Data.SqlClient/SqlCommandTest.cs +++ /dev/null @@ -1,159 +0,0 @@ -//
-// SqlCommandTest.cs - NUnit Test Cases for testing the
-// SqlCommand class
-// Author:
-// 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.SqlClient;
-
-using NUnit.Framework;
-
-namespace MonoTests.System.Data.SqlClient {
- [TestFixture]
- public class SqlCommandTest : MSSqlTestClient {
- [SetUp]
- public void GetReady () {
- OpenConnection ();
- }
-
- [TearDown]
- public void Clean () {
- CloseConnection ();
- }
-
- private void CreateInsertEmployeeSP() {
- string createquery = "CREATE PROCEDURE #Insert_Employee @TestPar1 varchar(50),@BirthDate datetime as insert into Employees(LastName,FirstName) VALUES('SSS','uuuu') ";
- SqlCommand cmd = new SqlCommand();
- cmd.Connection = conn;
- cmd.CommandText = createquery;
- cmd.ExecuteNonQuery();
- }
-
- private void CreateBug66630SP() {
- SqlCommand cmd = conn.CreateCommand();
- cmd.CommandType = CommandType.Text;
- cmd.CommandText = "CREATE PROCEDURE #Bug66630 ("
- + "@Status smallint = 7"
- + ")"
- + "AS" + Environment.NewLine
- + "BEGIN" + Environment.NewLine
- + "SELECT CAST(5 AS int), @Status" + Environment.NewLine
- + "END";
- cmd.ExecuteNonQuery();
- }
-
- [Test]
- public void ExecuteNonQueryTest () {
- // create temp sp here, should normally be created in Setup of test - // case, but cannot be done right now because of ug #68978 - CreateInsertEmployeeSP(); - - try {
- SqlCommand cmd = new SqlCommand();
- cmd.Connection = conn;
- cmd.CommandText = "#Insert_Employee";
- cmd.CommandType = CommandType.StoredProcedure;
- Object TestPar = DBNull.Value;
- cmd.Parameters.Add("@TestPar1", SqlDbType.Int);
- cmd.Parameters["@TestPar1"].Value = TestPar;
- cmd.Parameters.Add("@BirthDate", DateTime.Now);
- Assert.AreEqual(-1,cmd.ExecuteNonQuery());
- } catch (Exception e) {
- Assert.Fail("A#01 Got an exception");
- Console.WriteLine(e.Message);
- Console.WriteLine(e.StackTrace);
- } finally {
- // gracefully close connection
- CloseConnection ();
- }
- }
-
- /**
- * Verifies whether an enum value is converted to a numeric value when
- * used as value for a numeric parameter (bug #66630)
- */
- [Test]
- public void EnumParameterTest() {
- // create temp sp here, should normally be created in Setup of test - // case, but cannot be done right now because of ug #68978 - CreateBug66630SP(); - - SqlCommand cmd = new SqlCommand("#Bug66630", conn);
- cmd.CommandType = CommandType.StoredProcedure;
- cmd.Parameters.Add("@Status", SqlDbType.Int).Value = Status.Error;
-
- using (SqlDataReader dr = cmd.ExecuteReader()) {
- // one record should be returned
- Assert.IsTrue(dr.Read(), "EnumParameterTest#1");
- // we should get two field in the result
- Assert.AreEqual(2, dr.FieldCount, "EnumParameterTest#2");
- // field 1
- Assert.AreEqual("int", dr.GetDataTypeName(0), "EnumParameterTest#3");
- Assert.AreEqual(5, dr.GetInt32(0), "EnumParameterTest#4");
- // field 2
- Assert.AreEqual("smallint", dr.GetDataTypeName(1), "EnumParameterTest#5");
- Assert.AreEqual((short) Status.Error, dr.GetInt16(1), "EnumParameterTest#6");
- // only one record should be returned
- Assert.IsFalse(dr.Read(), "EnumParameterTest#7");
- }
- }
-
- [Test]
- /**
- * The below test does not need a connection but since the setup opens
- * the connection i will need to close it
- */
- public void CloneTest() {
- SqlCommand cmd = new SqlCommand();
- cmd.Connection = null;
- cmd.CommandText = "sp_insert";
- cmd.CommandType = CommandType.StoredProcedure;
- Object TestPar = DBNull.Value;
- cmd.Parameters.Add("@TestPar1", SqlDbType.Int);
- cmd.Parameters["@TestPar1"].Value = TestPar;
- cmd.Parameters.Add("@BirthDate", DateTime.Now);
- cmd.DesignTimeVisible = true;
- cmd.CommandTimeout = 100;
- Object clone1 = ((ICloneable)(cmd)).Clone();
- SqlCommand cmd1 = (SqlCommand) clone1;
- Assert.AreEqual(2, cmd1.Parameters.Count);
- Assert.AreEqual(100, cmd1.CommandTimeout);
- cmd1.Parameters.Add("@test", DateTime.Now);
- // to check that it is deep copy and not a shallow copy of the
- // parameter collection
- Assert.AreEqual(3, cmd1.Parameters.Count);
- Assert.AreEqual(2, cmd.Parameters.Count);
- }
-
- private enum Status {
- OK = 0,
- Error = 3
- }
- }
-}
diff --git a/mcs/class/System.Data/Test/System.Data.SqlClient/SqlDataAdapterTest.cs b/mcs/class/System.Data/Test/System.Data.SqlClient/SqlDataAdapterTest.cs deleted file mode 100644 index 1711278ef6a..00000000000 --- a/mcs/class/System.Data/Test/System.Data.SqlClient/SqlDataAdapterTest.cs +++ /dev/null @@ -1,158 +0,0 @@ -//
-// SqlDataAdapterTest.cs - NUnit Test Cases for testing the
-// SqlDataAdapter class
-// Author:
-// 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.SqlClient;
-
-using NUnit.Framework;
-
-namespace MonoTests.System.Data.SqlClient -{
-
- [TestFixture]
- public class SqlDataAdapterTest : MSSqlTestClient {
-
- [SetUp]
- public void GetReady () {
- OpenConnection ();
- }
-
- [TearDown]
- public void Clean () {
- CloseConnection ();
- } - - [Test]
- /** - The below test will not run everytime, since the region id column is unique - so change the regionid if you want the test to pass. - **/ - public void UpdateTest () { - try { - DataTable dt = new DataTable(); - SqlDataAdapter da = null; - da = new SqlDataAdapter("Select * from Region;", conn); - da.Fill(dt); - SqlCommandBuilder cb = new SqlCommandBuilder (da); - DataRow dr = dt.NewRow(); - - dr["RegionID"] = 101; - dr["RegionDescription"] = "Boston"; - - dt.Rows.Add(dr); - da.Update(dt); - - - }
- catch (Exception e) { - Assert.Fail("A#01 Got an exception"); - //Console.WriteLine(e.StackTrace); - - } - - finally { // try/catch is necessary to gracefully close connections
- - CloseConnection ();
- }
- }
- - - [Test] - public void FillSchemaTest() { - try { - - - string sql = "select * from Region;"; - SqlCommand c = conn.CreateCommand(); - c.CommandText = sql; - SqlDataReader dr = c.ExecuteReader(CommandBehavior.KeyInfo|CommandBehavior.SchemaOnly); - DataTable schema = dr.GetSchemaTable(); - // check the schema details. - /*foreach (DataColumn col in schema.Columns) - Console.Write(col.ColumnName+' ');*/ - DataRowCollection drc = schema.Rows; - DataRow r = drc[0]; - Assert.AreEqual("RegionID",r[0].ToString()); - - } - - catch (Exception e) { - Assert.Fail("A#02 : Got an exception"); - Console.WriteLine(e.StackTrace); - - } - - finally { // try/catch is necessary to gracefully close connections^M - - CloseConnection (); - } - - - - } - - /** - This needs a errortable created as follows - id uniqueidentifier,name char(10) , with values - Guid name - {A12...} NULL - NULL bbbbbb - **/ - [Test] - public void NullGuidTest() { - - SqlDataAdapter da = new SqlDataAdapter(); - da.SelectCommand = new SqlCommand(); - da.SelectCommand.Connection = conn; - da.SelectCommand.CommandText += "select * from errortable"; - DataSet ds = new DataSet(); - try { - da.Fill(ds); - } - catch (Exception e) { - Assert.Fail("A#02 : Got an exception"); - Console.WriteLine(e.StackTrace); - - } - finally { // try/catch is necessary to gracefully close connections^M - - CloseConnection (); - } - // the bug 68804 - is that the fill hangs! - Assert.AreEqual("Done","Done"); - - } - - - - - }
-}
diff --git a/mcs/class/System.Data/Test/System.Data.SqlClient/SqlDataReaderTest.cs b/mcs/class/System.Data/Test/System.Data.SqlClient/SqlDataReaderTest.cs deleted file mode 100644 index 992ac059ba9..00000000000 --- a/mcs/class/System.Data/Test/System.Data.SqlClient/SqlDataReaderTest.cs +++ /dev/null @@ -1,139 +0,0 @@ -//
-// SqlDataReaderTest.cs - NUnit Test Cases for testing the
-// SqlDataReader class
-// Author:
-// Umadevi S (sumadevi@novell.com)
-// Kornél Pál <http://www.kornelpal.hu/> -//
-// 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.SqlClient;
-
-using NUnit.Framework;
-
-namespace MonoTests.System.Data.SqlClient -{
-
- [TestFixture]
- public class SqlDataReaderTest : MSSqlTestClient {
-
- [SetUp]
- public void GetReady () {
- OpenConnection ();
- }
-
- [TearDown]
- public void Clean () {
- CloseConnection ();
- } - - - [Test] - public void ReadEmptyNTextFieldTest () { - try { - using (conn) { - SqlCommand sqlCommand = conn.CreateCommand(); - sqlCommand.CommandText = "CREATE TABLE #MonoTest (NAME ntext)"; - sqlCommand.ExecuteNonQuery(); - - sqlCommand.CommandText = "INSERT INTO #MonoTest VALUES ('')"; //('')"; - sqlCommand.ExecuteNonQuery(); - - sqlCommand.CommandText = "SELECT * FROM #MonoTest"; - SqlDataReader dr = sqlCommand.ExecuteReader(); - while (dr.Read()) { - Console.WriteLine(dr["NAME"].GetType().FullName); - Assert.AreEqual("System.String",dr["NAME"].GetType().FullName); - } - } - } - catch (Exception e) { - Assert.Fail("A#01 Got an exception"); - //Console.WriteLine(e.StackTrace); - - } - - finally { // try/catch is necessary to gracefully close connections^M - - CloseConnection (); - } - - - - } - - [Test] - public void ReadBingIntTest()
- { - try
- { - string createquery = "SELECT CAST(548967465189498 AS bigint) AS Value"; - SqlCommand cmd = new SqlCommand(); - cmd.Connection = conn; - cmd.CommandText = createquery; - SqlDataReader r = cmd.ExecuteReader(); - using (r)
- { - if (r.Read())
- { - long id = 0; - try
- { - id = r.GetInt64(0); - } - catch (Exception e)
- { - Assert.Fail("A#01 Got an exception in GetInt64"); - } - Assert.AreEqual(548967465189498, id); - try
- { - id = r.GetSqlInt64(0).Value; - } - catch (Exception e)
- { - Assert.Fail("A#02 Got an exception in GetSqlInt64"); - } - Assert.AreEqual(548967465189498, id); - } - else - Assert.Fail("A#03 No rows returned"); - } - } - catch (Exception e)
- { - Assert.Fail("A#04 Got an exception"); - //Console.WriteLine(e.StackTrace); - } - finally
- { - // try/catch is necessary to gracefully close connections - CloseConnection(); - } - } - }
-}
|