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

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mcs/class/System.Data/Test')
-rw-r--r--mcs/class/System.Data/Test/ChangeLog10
-rw-r--r--mcs/class/System.Data/Test/MSSqlTestBed.cs100
-rw-r--r--mcs/class/System.Data/Test/MySqlTestBed.cs15
-rw-r--r--mcs/class/System.Data/Test/System.Data.Common/ChangeLog3
-rw-r--r--mcs/class/System.Data/Test/System.Data.Common/DataContainerTest.cs104
-rw-r--r--mcs/class/System.Data/Test/System.Data.Odbc/ChangeLog21
-rw-r--r--mcs/class/System.Data/Test/System.Data.Odbc/OdbcCommandTest.cs113
-rw-r--r--mcs/class/System.Data/Test/System.Data.Odbc/OdbcDataReaderTest.cs101
-rw-r--r--mcs/class/System.Data/Test/System.Data.SqlClient/SqlCommandTest.cs99
-rw-r--r--mcs/class/System.Data/Test/System.Data.SqlClient/SqlTransactionTest.cs85
-rw-r--r--mcs/class/System.Data/Test/System.Data/ChangeLog12
-rw-r--r--mcs/class/System.Data/Test/System.Data/DataRowTest.cs37
-rw-r--r--mcs/class/System.Data/Test/System.Data/DataSetTest.cs69
13 files changed, 763 insertions, 6 deletions
diff --git a/mcs/class/System.Data/Test/ChangeLog b/mcs/class/System.Data/Test/ChangeLog
index 49630c2d5d8..65c8719353a 100644
--- a/mcs/class/System.Data/Test/ChangeLog
+++ b/mcs/class/System.Data/Test/ChangeLog
@@ -1,3 +1,13 @@
+2004-08-26 Sureshkumar T <TSureshkumar@novell.com>
+ * MySqlTestBed.cs - Added few more fields for DateTime testing
+
+2004-08-13 Umadevi S <sumadevi@novell.com>
+ * Added standalone nunit testcases for datacontainer class.
+ * Currently will use MSSQL server
+ * New File
+ MSSqlTestBed.cs - Base class for MSSql testing
+ (similar to the mysqltestbed)
+
2004-06-16 Sureshkumar T <TSureshkumar@novell.com>
* Added standalone NUnit test cases for MySql db related tests.
* Created sub-directory for System.Data.Odbc
diff --git a/mcs/class/System.Data/Test/MSSqlTestBed.cs b/mcs/class/System.Data/Test/MSSqlTestBed.cs
new file mode 100644
index 00000000000..bb2ed3bd160
--- /dev/null
+++ b/mcs/class/System.Data/Test/MSSqlTestBed.cs
@@ -0,0 +1,100 @@
+//
+// MSSqlTestBed.cs : This is base class which manages the connections to
+// MSSql database. This serves as a base class for all
+// MSSql database dependant tests.
+//
+// To run :
+//
+// * compile using following command
+// mcs /r:System.Data.dll,nunit.framework.dll /t:library /debug
+// /out:MSSqlTestBed.dll MSSqlTestBed.cs System.Data.Common/*.cs
+// * To run the tests
+// mono /usr/local/bin/nunit-console.exe MSSqlTestBed.dll
+//
+// 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 System.Collections.Specialized;
+
+namespace MonoTests.System.Data
+{
+ public class MSSqlTestClient
+ {
+ #region protected members
+ protected string connectionString = null;
+ protected SqlConnection conn = null;
+ protected bool isConnAlive = false;
+ #endregion
+
+ public MSSqlTestClient ()
+ {
+ connectionString =
+ "Server=164.99.168.131;" +
+ "Database=Northwind;" +
+ "User ID=sa;" +
+ "Password=novell";
+ conn = new SqlConnection(connectionString);
+ }
+
+ protected void OpenConnection ()
+ {
+ conn.ConnectionString = connectionString;
+ conn.Open ();
+ // run tests only if the connection is open,
+ // otherwise make it fail, to setup with correct
+ // database settings
+ if (conn != null && conn.State != ConnectionState.Closed)
+ isConnAlive = true;
+ }
+
+ protected void CloseConnection ()
+ {
+ if (conn != null && conn.State != ConnectionState.Closed) {
+ conn.Close ();
+ isConnAlive = false;
+ }
+ }
+
+ internal void ExecuteQuery (string query)
+ {
+ SqlCommand cmd = new SqlCommand ();
+ cmd.Connection = conn;
+ cmd.CommandText = query;
+ try {
+ int recordsAff = cmd.ExecuteNonQuery ();
+ } catch (Exception e) {
+ Console.WriteLine("exception");
+ Console.WriteLine(e.StackTrace);
+ }
+ }
+
+
+ }
+}
diff --git a/mcs/class/System.Data/Test/MySqlTestBed.cs b/mcs/class/System.Data/Test/MySqlTestBed.cs
index a923c0d326d..1f8fef70c89 100644
--- a/mcs/class/System.Data/Test/MySqlTestBed.cs
+++ b/mcs/class/System.Data/Test/MySqlTestBed.cs
@@ -95,23 +95,26 @@ namespace MonoTests.System.Data
"pk_tint TINYINT NOT NULL PRIMARY KEY," +
"col_char CHAR(20)," +
"col_int INT," +
- "col_blob TINYBLOB" +
+ "col_blob TINYBLOB," +
+ "col_datetime DATETIME," +
+ "col_date DATE," +
+ "col_time TIME" +
");";
ExecuteQuery (createQuery);
createQuery = "INSERT INTO test VALUES (1, 'mono test" +
- "#1', 255, 127123645917568585638457243856234985 );" ;
+ "#1', 255, 127123645917568585638457243856234985, '2004-08-22', '2004-08-22', '12:00:00' );" ;
ExecuteQuery (createQuery);
createQuery = "INSERT INTO test VALUES (2, 'mono test" +
- "#2', 256, NULL );" ;
+ "#2', 256, NULL, NULL, NULL, NULL );";
ExecuteQuery (createQuery);
createQuery = "INSERT INTO test VALUES (3, 'mono test" +
- "#3', 257 , 127123645917568585638457243856234985);" ;
+ "#3', 257 , 127123645917568585638457243856234985, '2004-08-22', '2004-08-22', '12:00:00');" ;
ExecuteQuery (createQuery);
createQuery = "INSERT INTO test VALUES (4, 'mono test" +
- "#4', 258 , 127123645917568585638457243856234985);" ;
+ "#4', 258 , 127123645917568585638457243856234985, '2004-08-22', '2004-08-22', '12:00:00');" ;
ExecuteQuery (createQuery);
createQuery = "INSERT INTO test VALUES (5, 'mono test" +
- "#5', 259, 127123645917568585638457243856234985 );" ;
+ "#5', 259, 127123645917568585638457243856234985, '2004-08-22', '2004-08-22', '12:00:00' );" ;
ExecuteQuery (createQuery);
}
diff --git a/mcs/class/System.Data/Test/System.Data.Common/ChangeLog b/mcs/class/System.Data/Test/System.Data.Common/ChangeLog
index af4575be732..351489466c7 100644
--- a/mcs/class/System.Data/Test/System.Data.Common/ChangeLog
+++ b/mcs/class/System.Data/Test/System.Data.Common/ChangeLog
@@ -1,3 +1,6 @@
+2004-08-13 Umadevi S <sumadevi@novell.com>
+ * Added File DataContainerTest
+
2004-06-10 Umadevi S <sumadevi@novell.com>
* Corrected GetTableMappingBySchemaAction for DataTableMappingCollectionTest
diff --git a/mcs/class/System.Data/Test/System.Data.Common/DataContainerTest.cs b/mcs/class/System.Data/Test/System.Data.Common/DataContainerTest.cs
new file mode 100644
index 00000000000..32e6cfd878c
--- /dev/null
+++ b/mcs/class/System.Data/Test/System.Data.Common/DataContainerTest.cs
@@ -0,0 +1,104 @@
+//
+// DataContainerTest.cs - NUnit Test Cases for testing the
+// DataContainer 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.Common
+{
+
+ [TestFixture]
+ public class DataContainerTest : MSSqlTestClient {
+
+ [SetUp]
+ public void GetReady () {
+ OpenConnection ();
+ CreateTestSetup (); // create test database & tables
+ }
+
+ [TearDown]
+ public void Clean () {
+ CleanTestSetup (); // clean test database
+ CloseConnection ();
+ }
+
+ private void CreateTestSetup()
+ {
+ if (!isConnAlive)
+ return ;
+ // Create test database & tables
+ string createQuery = "DROP TABLE datetimetest;" ;
+ ExecuteQuery (createQuery);
+ createQuery = "CREATE TABLE datetimetest (" +
+ "col_char CHAR(20)," +
+ "col_date DATETIME );";
+ ExecuteQuery (createQuery);
+ createQuery = "INSERT INTO datetimetest VALUES ('one', '4/12/2004 4:59:00');" ;
+ ExecuteQuery (createQuery);
+ createQuery = "INSERT INTO datetimetest VALUES ('two',null);" ;
+ ExecuteQuery (createQuery);
+ createQuery = "INSERT INTO datetimetest (col_char) VALUES ('three');" ;
+ ExecuteQuery (createQuery);
+
+
+ }
+
+ private void CleanTestSetup()
+ {
+ if (!isConnAlive)
+ return;
+ // delete test database
+ string dropQuery = "DROP table datetimetest";
+ ExecuteQuery(dropQuery);
+
+ }
+
+
+ [Test]
+ public void DateTimeTest () {
+ try {
+
+ SqlDataAdapter myadapter = new SqlDataAdapter("select * from datetimetest;",conn);
+
+ DataTable dt = new DataTable();
+ myadapter.Fill(dt);
+ Assertion.AssertEquals ("Row count must be three", 3, dt.Rows.Count );
+ }
+
+ 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/ChangeLog b/mcs/class/System.Data/Test/System.Data.Odbc/ChangeLog
index bd7b77d4f19..7ecb34c9d29 100644
--- a/mcs/class/System.Data/Test/System.Data.Odbc/ChangeLog
+++ b/mcs/class/System.Data/Test/System.Data.Odbc/ChangeLog
@@ -1,3 +1,24 @@
+2004-08-31 Umadevi S <sumadevi@novell.com>
+ * OdbcDataReaderTest.cs - Added a test for Numeric Type
+
+2004-08-27 Sureshkumar T <tsureshkumar@novell.com>
+ * OdbcDataReaderTest.cs - Added a test for TinyInt
+
+2004-08-26 Sureshkumar T <tsureshkumar@novell.com>
+ * OdbcDataReaderTest.cs - Added a test for DateTime - GetDateTimeTest
+ * OdbcCommandTest.cs - Syntax Error Fix
+
+2004-07-29 Umadevi S <sumadevi@novell.com>
+ * OdbcCommandTest.cs - Added testcase for bug 62046. ExecuteNonQuery
+
+2004-07-28 Umadevi S <sumadevi@novell.com>
+ * OdbcCommandTest.cs - Added testcase for bug 61968. String values passed with quotes
+
+2004-07-01 Sureshkumar T <tsureshkumar@novell.com>
+ * Added test case for OdbcCommand.ExecuteScalar Method
+ * New files:
+ OdbcCommandTest.cs - test suite for OdbcCommand class.
+
2004-06-23 Sureshkumar T <TSureshkumar@novell.com>
* Added test to check whether the OdbcConnection.Close method closes
all the handles.
diff --git a/mcs/class/System.Data/Test/System.Data.Odbc/OdbcCommandTest.cs b/mcs/class/System.Data/Test/System.Data.Odbc/OdbcCommandTest.cs
new file mode 100644
index 00000000000..f46cf29c6c7
--- /dev/null
+++ b/mcs/class/System.Data/Test/System.Data.Odbc/OdbcCommandTest.cs
@@ -0,0 +1,113 @@
+//
+// 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/OdbcDataReaderTest.cs b/mcs/class/System.Data/Test/System.Data.Odbc/OdbcDataReaderTest.cs
index 0017b818681..b8ceeafbbbb 100644
--- a/mcs/class/System.Data/Test/System.Data.Odbc/OdbcDataReaderTest.cs
+++ b/mcs/class/System.Data/Test/System.Data.Odbc/OdbcDataReaderTest.cs
@@ -231,5 +231,106 @@ namespace MonoTests.System.Data.Odbc
CloseConnection ();
}
}
+
+ [Test]
+ public void GetDateTimeTest ()
+ {
+ OdbcCommand cmd = conn.CreateCommand ();
+ string sql = "SELECT * FROM test";
+ cmd.CommandText = sql;
+ OdbcDataReader reader = cmd.ExecuteReader (CommandBehavior.Default);
+ try {
+ if (reader.Read ()) {
+ object ob = reader["col_datetime"];
+ Assertion.AssertEquals ("Type of datetime column is wrong!",
+ "System.DateTime", ob.GetType ().ToString () );
+ ob = reader["col_date"];
+ Assertion.AssertEquals ("Type of date column is wrong!",
+ "System.DateTime", ob.GetType ().ToString () );
+ // FIXME : Once TIME data type is fixed, enable this check
+ //ob = reader["col_time"];
+ //Assertion.AssertEquals ("Type of time column is wrong!",
+ //"System.DateTime", ob.GetType ().ToString () );
+
+ DateTime dt = reader.GetDateTime (4);
+ Assertion.AssertEquals ("DateValue (SQL_TIMESTAMP) is wrong", new DateTime (2004, 8, 22, 0, 0, 0), dt);
+ dt = reader.GetDateTime (5);
+ Assertion.AssertEquals ("DateValue (SQL_DATE) is wrong", new DateTime (2004, 8, 22, 0, 0, 0), dt);
+ // FIXME : Once TIME data type is fixed, enable this check
+ //dt = reader.GetDateTime (7);
+ //Assertion.AssertEquals ("DateValue is wrong", "2004-08-22", dt.ToString ());
+ }
+ } finally {
+ // clean up
+ if (reader != null && !reader.IsClosed )
+ reader.Close ();
+ reader = null;
+ CleanTestSetup ();
+ CloseConnection ();
+ }
+ }
+
+
+ /// <summary>
+ /// This test for the return type &amp; value for GetValue
+ /// in case of Odbc Data type TINYINT
+ /// </summary>
+ [Test]
+ public void TinyIntTest ()
+ {
+ OdbcCommand cmd = conn.CreateCommand ();
+ string sql = "SELECT * FROM test";
+ cmd.CommandText = sql;
+ OdbcDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess);
+ try {
+ if (reader.Read ()) {
+ object ob = reader.GetValue (0);
+ Assertion.AssertEquals ("Type of tinyInt column is wrong!",
+ "System.Byte", ob.GetType ().ToString () );
+ Assertion.AssertEquals ("Value of tinyInt column is wrong!",
+ 1, System.Convert.ToInt16(ob) );
+ }
+ } finally {
+ // clean up
+ if (reader != null && !reader.IsClosed )
+ reader.Close ();
+ reader = null;
+ CleanTestSetup ();
+ CloseConnection ();
+ }
+ }
+
+ [Test]
+ public void NumericTest()
+ {
+ using(IDbConnection dbConnection = new OdbcConnection(connectionString))
+ {
+ dbConnection.Open();
+ IDbCommand dbCommand = dbConnection.CreateCommand();
+ //note this will fail if the table already exists, ie if the test has failed.
+ dbCommand.CommandText = "CREATE TABLE NumericTable (NumericField NUMERIC(10) NOT NULL)";
+ dbCommand.ExecuteNonQuery();
+ dbCommand.CommandText = "INSERT INTO NumericTable (NumericField) VALUES (125)";
+ dbCommand.ExecuteNonQuery();
+ dbCommand.CommandText = "SELECT * FROM NumericTable";
+ using(IDataReader reader = dbCommand.ExecuteReader())
+ {
+ while(reader.Read())
+ {
+ for(int index = 0; index < reader.FieldCount; index++)
+ {
+ Object dataValue = reader.GetValue(index);
+ Assert.AreEqual("System.Decimal",dataValue.GetType().ToString());
+ Assert.AreEqual("125", dataValue.ToString());
+ }
+ }
+ }
+ dbCommand.CommandText = "DROP TABLE NumericTable";
+ dbCommand.ExecuteNonQuery();
+ }
+ }
+
+
+
}
}
diff --git a/mcs/class/System.Data/Test/System.Data.SqlClient/SqlCommandTest.cs b/mcs/class/System.Data/Test/System.Data.SqlClient/SqlCommandTest.cs
new file mode 100644
index 00000000000..9d58e4c977a
--- /dev/null
+++ b/mcs/class/System.Data/Test/System.Data.SqlClient/SqlCommandTest.cs
@@ -0,0 +1,99 @@
+//
+// 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 ();
+ }
+
+ /**
+ This is required to be run only once, call this from the GetReady.
+ **/
+ private void setup(){
+ string createquery = "CREATE PROCEDURE sp_insert @TestPar1 varchar(50),@BirthDate datetime as insert into Employees(LastName,FirstName) VALUES('SSS','uuuu') ";
+ SqlCommand cmd = new SqlCommand();
+ cmd.Connection = conn;
+ cmd.CommandText = createquery;
+ int ret =cmd.ExecuteNonQuery();
+ }
+
+
+ [Test]
+ /**
+ The below test expects the stored procedure sp_insert in the database.
+ **/
+ public void ExecuteNonQueryTest () {
+ try {
+ SqlCommand cmd = new SqlCommand();
+ cmd.Connection = conn;
+ cmd.CommandText = "sp_insert";
+ cmd.CommandType = CommandType.StoredProcedure;
+ Object TestPar = System.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 { // try/catch is necessary to gracefully close connections
+
+ CloseConnection ();
+ }
+ }
+
+
+
+
+
+ }
+}
diff --git a/mcs/class/System.Data/Test/System.Data.SqlClient/SqlTransactionTest.cs b/mcs/class/System.Data/Test/System.Data.SqlClient/SqlTransactionTest.cs
new file mode 100644
index 00000000000..c91e27631cc
--- /dev/null
+++ b/mcs/class/System.Data/Test/System.Data.SqlClient/SqlTransactionTest.cs
@@ -0,0 +1,85 @@
+//
+// 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;
+using System.Data.Common;
+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())
+ {
+ 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 (System.Exception ex)
+ {
+ transaction.Rollback();
+ }
+ finally
+ {
+ conn.Close();
+ }
+
+ }
+ }
+
+ }
+}
diff --git a/mcs/class/System.Data/Test/System.Data/ChangeLog b/mcs/class/System.Data/Test/System.Data/ChangeLog
index 48ffde727ce..07f46872aea 100644
--- a/mcs/class/System.Data/Test/System.Data/ChangeLog
+++ b/mcs/class/System.Data/Test/System.Data/ChangeLog
@@ -1,3 +1,15 @@
+2004-09-24 Umadevi S <sumadevi@novell.com>
+ * DataRowTest.cs : Added a test for EnforceConstraints with relations defined.
+
+2004-09-24 Sureshkumar T <tsureshkumar@novell.com>
+
+ * DataSetTest.cs (DataSetClearTest): Added a test for DataSet.Clear. This should not
+ throw any exception and should override constraints.
+
+2004-09-21 Sureshkumar T <tsureshkumar@novell.com>
+
+ * DataSetTest.cs : Added a test for Deserialization of dataset : DeserializeModifiedDataSet
+
2004-06-23 Umadevi S <sumadevi@novell.com>
* DataTableTest.cs :Corrected Testcases to .net 1.1 specifications
diff --git a/mcs/class/System.Data/Test/System.Data/DataRowTest.cs b/mcs/class/System.Data/Test/System.Data/DataRowTest.cs
index a82637dc9cd..2f347ddd005 100644
--- a/mcs/class/System.Data/Test/System.Data/DataRowTest.cs
+++ b/mcs/class/System.Data/Test/System.Data/DataRowTest.cs
@@ -756,5 +756,42 @@ namespace MonoTests.System.Data
dt.Columns.Add (col);
dt.Rows [0] [0] = "test";
}
+
+ [Test]
+ public void EnforceConstraint ()
+ {
+ int id = 100;
+ // Setup stuff
+ DataSet ds = new DataSet();
+ DataTable parent = ds.Tables.Add("parent");
+ parent.Columns.Add("id", typeof(int));
+ DataTable child = ds.Tables.Add("child");
+ child.Columns.Add("idref", typeof(int));
+ Constraint uniqueId = null;
+ parent.Constraints.Add(uniqueId = new UniqueConstraint("uniqueId",
+ new DataColumn[] {parent.Columns["id"]}, true));
+ ForeignKeyConstraint fkc = new ForeignKeyConstraint("ParentChildConstraint", new DataColumn[] { parent.Columns["id"] },
+ new DataColumn[] { child.Columns["idref"]});
+
+ child.Constraints.Add(fkc);
+
+ DataRelation relateParentChild = new DataRelation("relateParentChild",
+ new DataColumn[] {parent.Columns["id"] },
+ new DataColumn[] {child.Columns["idref"] },
+ false);
+ ds.Relations.Add(relateParentChild);
+
+ ds.EnforceConstraints = false;
+ DataRow parentRow = parent.Rows.Add(new object[] { id });
+ DataRow childRow = child.Rows.Add(new object[] { id });
+ if (parentRow == childRow.GetParentRow(relateParentChild)) {
+ foreach(DataColumn dc in parent.Columns)
+ AssertEquals(100,parentRow[dc]);
+
+ }
+
+
+ }
+
}
}
diff --git a/mcs/class/System.Data/Test/System.Data/DataSetTest.cs b/mcs/class/System.Data/Test/System.Data/DataSetTest.cs
index 766f0e86863..95c6c3061a7 100644
--- a/mcs/class/System.Data/Test/System.Data/DataSetTest.cs
+++ b/mcs/class/System.Data/Test/System.Data/DataSetTest.cs
@@ -1235,5 +1235,74 @@ namespace MonoTests.System.Data
ds.WriteXml (xtw);
AssertEquals (xml, sw.ToString ());
}
+
+ [Test]
+ public void DeserializeModifiedDataSet ()
+ {
+ // Serialization begins
+ DataSet prevDs = new DataSet ();
+ DataTable dt = prevDs.Tables.Add ();
+ dt.Columns.Add(new DataColumn("Id", typeof(string)));
+
+ DataRow dr = dt.NewRow();
+ dr [0] = "a";
+ dt.Rows.Add (dr);
+ prevDs.AcceptChanges ();
+ dr = prevDs.Tables[0].Rows[0];
+ dr [0] = "b";
+
+ XmlSerializer serializer = new XmlSerializer (typeof (DataSet));
+ StringWriter sw = new StringWriter ();
+ XmlTextWriter xw = new XmlTextWriter (sw);
+ xw.QuoteChar = '\'';
+ serializer.Serialize (xw, prevDs);
+
+ // Deserialization begins
+ StringReader sr = new StringReader (sw.ToString ());
+ XmlTextReader reader = new XmlTextReader (sr);
+ XmlSerializer serializer1 = new XmlSerializer (typeof (DataSet));
+ DataSet ds = serializer1.Deserialize (reader) as DataSet;
+ AssertEquals ("deserialization after modification does not give original values",
+ prevDs.Tables[0].Rows [0][0,DataRowVersion.Original].ToString (),
+ ds.Tables[0].Rows [0][0,DataRowVersion.Original].ToString ());
+ AssertEquals ("deserialization after modification does not give current values",
+ prevDs.Tables[0].Rows [0][0,DataRowVersion.Current].ToString (),
+ ds.Tables[0].Rows [0][0,DataRowVersion.Current].ToString ());
+ }
+
+ /// <summary>
+ /// Test for testing DataSet.Clear method with foriegn key relations
+ /// This is expected to clear all the related datatable rows also
+ /// </summary>
+ [Test]
+ public void DataSetClearTest ()
+ {
+ DataSet ds = new DataSet ();
+ DataTable parent = ds.Tables.Add ("Parent");
+ DataTable child = ds.Tables.Add ("Child");
+
+ parent.Columns.Add ("id", typeof (int));
+ child.Columns.Add ("ref_id", typeof(int));
+
+ child.Constraints.Add (new ForeignKeyConstraint ("fk_constraint", parent.Columns [0], child.Columns [0]));
+
+ DataRow dr = parent.NewRow ();
+ dr [0] = 1;
+ parent.Rows.Add (dr);
+ dr.AcceptChanges ();
+
+ dr = child.NewRow ();
+ dr [0] = 1;
+ child.Rows.Add (dr);
+ dr.AcceptChanges ();
+
+ try {
+ ds.Clear (); // this should clear all the rows in parent & child tables
+ } catch (Exception e) {
+ throw (new Exception ("Exception should not have been thrown at Clear method" + e.ToString ()));
+ }
+ Assertion.AssertEquals ("parent table rows should not exist!", 0, parent.Rows.Count);
+ Assertion.AssertEquals ("child table rows should not exist!", 0, child.Rows.Count);
+ }
}
}