mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-19 01:31:17 -10:00
factory. Moved few stand-alone tests from Test/ to this framework. In Test: 2005-09-01 Sureshkumar T <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * IDbCommandTest.cs: Added. Provider independent Command tests. * DataReaderTest.cs: Added. Provider independent DataReader tests. In Test/ProviderTests: 2005-09-01 Sureshkumar T <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * 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
184 lines
6.6 KiB
C#
184 lines
6.6 KiB
C#
// SqlCommandBuilderTest.cs - NUnit Test Cases for testing the
|
|
// SqlCommandBuilder class
|
|
//
|
|
// Authors:
|
|
// Sureshkumar T ([email protected])
|
|
//
|
|
// 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
|
|
|
|
}
|
|
}
|