You've already forked linux-packaging-mono
Imported Upstream version 5.2.0.175
Former-commit-id: bb0468d0f257ff100aa895eb5fe583fb5dfbf900
This commit is contained in:
parent
4bdbaf4a88
commit
966bba02bb
@@ -0,0 +1,116 @@
|
||||
//
|
||||
// ConnectionConfig.cs - Holds information on a specific connection and
|
||||
// corresponding engine to test.
|
||||
//
|
||||
// Author:
|
||||
// Gert Driesen (drieseng@users.sourceforge.net
|
||||
//
|
||||
// Copyright (c) 2008 Gert Driesen
|
||||
//
|
||||
// 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 !NO_CONFIGURATION
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Configuration;
|
||||
using System.Globalization;
|
||||
using System.Xml;
|
||||
|
||||
namespace MonoTests.System.Data.Connected
|
||||
{
|
||||
internal sealed class ConnectionConfig
|
||||
{
|
||||
private readonly string name;
|
||||
private readonly string factory;
|
||||
private readonly string connectionString;
|
||||
private readonly EngineConfig engine;
|
||||
|
||||
private ConnectionConfig (string name, string factory, string connectionString, EngineConfig engine)
|
||||
{
|
||||
this.name = name;
|
||||
this.factory = factory;
|
||||
this.connectionString = connectionString;
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
internal static ConnectionConfig FromXml (XmlNode connNode, Hashtable engines)
|
||||
{
|
||||
return new ConnectionConfig (
|
||||
GetAttribValue (connNode, "name", true),
|
||||
GetAttribValue (connNode, "factory", true),
|
||||
GetAttribValue (connNode, "connectionString", true),
|
||||
GetEngine (connNode, engines));
|
||||
}
|
||||
|
||||
public string Name {
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
public string Factory {
|
||||
get { return factory; }
|
||||
}
|
||||
|
||||
public string ConnectionString {
|
||||
get { return connectionString; }
|
||||
}
|
||||
|
||||
public EngineConfig Engine {
|
||||
get { return engine; }
|
||||
}
|
||||
|
||||
static string GetAttribValue (XmlNode node, string name, bool required)
|
||||
{
|
||||
XmlAttribute attr = node.Attributes [name];
|
||||
if (attr == null) {
|
||||
if (required)
|
||||
throw CreateAttributeMissingException (name, node);
|
||||
return null;
|
||||
}
|
||||
return attr.Value;
|
||||
}
|
||||
|
||||
static EngineConfig GetEngine (XmlNode connNode, Hashtable engines)
|
||||
{
|
||||
XmlAttribute engineAttr = connNode.Attributes ["engine"];
|
||||
if (engineAttr == null)
|
||||
throw CreateAttributeMissingException ("engine", connNode);
|
||||
|
||||
string engineName = engineAttr.Value;
|
||||
EngineConfig engine = (EngineConfig) engines [engineName];
|
||||
if (engine == null) {
|
||||
string msg = string.Format (CultureInfo.InvariantCulture,
|
||||
"Engine '{0}' does not exist.", engineName);
|
||||
throw new ConfigurationErrorsException (msg, engineAttr);
|
||||
}
|
||||
return engine;
|
||||
}
|
||||
|
||||
static Exception CreateAttributeMissingException (string name, XmlNode node)
|
||||
{
|
||||
string msg = string.Format (CultureInfo.InvariantCulture,
|
||||
"Missing '{0}' attribute.", name);
|
||||
throw new ConfigurationErrorsException (msg, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,251 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
#if !NO_ODBC
|
||||
using System.Data.Odbc;
|
||||
#endif
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MonoTests.System.Data.Connected
|
||||
{
|
||||
public class ConnectionManager
|
||||
{
|
||||
private static ConnectionManager instance;
|
||||
private ConnectionHolder<SqlConnection> sql;
|
||||
|
||||
private const string OdbcEnvVar = "SYSTEM_DATA_ODBC";
|
||||
private const string SqlEnvVar = "SYSTEM_DATA_MSSQL";
|
||||
|
||||
private ConnectionManager ()
|
||||
{
|
||||
//Environment.SetEnvironmentVariable(OdbcEnvVar, @"Driver={MySQL ODBC 5.3 Unicode Driver};server=127.0.0.1;uid=sa;pwd=qwerty123;";
|
||||
//Environment.SetEnvironmentVariable(SqlEnvVar, @"server=127.0.0.1;database=master;user id=sa;password=qwerty123";
|
||||
|
||||
// Generate a random db name
|
||||
DatabaseName = "monotest" + Guid.NewGuid().ToString().Substring(0, 7);
|
||||
|
||||
sql = CreateSqlConfig (SqlEnvVar);
|
||||
if (sql != null)
|
||||
CreateMssqlDatabase();
|
||||
|
||||
#if !NO_ODBC
|
||||
odbc = CreateOdbcConfig (OdbcEnvVar);
|
||||
if (odbc != null)
|
||||
CreateMysqlDatabase();
|
||||
#endif
|
||||
}
|
||||
|
||||
static ConnectionHolder<SqlConnection> CreateSqlConfig (string envVarName)
|
||||
{
|
||||
string connectionString = Environment.GetEnvironmentVariable (envVarName);
|
||||
if (string.IsNullOrEmpty (connectionString))
|
||||
return null;
|
||||
|
||||
SqlConnection connection;
|
||||
#if MOBILE
|
||||
connection = new SqlConnection ();
|
||||
#else
|
||||
DbProviderFactory factory = DbProviderFactories.GetFactory ("System.Data.SqlClient");
|
||||
connection = (SqlConnection)factory.CreateConnection ();
|
||||
#endif
|
||||
|
||||
var engine = new EngineConfig {
|
||||
Type = EngineType.SQLServer,
|
||||
ClientVersion = 9,
|
||||
QuoteCharacter = """,
|
||||
SupportsMicroseconds = true,
|
||||
SupportsUniqueIdentifier = true,
|
||||
SupportsTimestamp = true,
|
||||
};
|
||||
|
||||
return new ConnectionHolder<SqlConnection> (engine, connection, connectionString);
|
||||
}
|
||||
|
||||
#if !NO_ODBC
|
||||
static ConnectionHolder<OdbcConnection> CreateOdbcConfig (string envVarName)
|
||||
{
|
||||
string connectionString = Environment.GetEnvironmentVariable (envVarName);
|
||||
if (string.IsNullOrEmpty (connectionString))
|
||||
return null;
|
||||
|
||||
DbProviderFactory factory = DbProviderFactories.GetFactory ("System.Data.Odbc");
|
||||
var connection = (OdbcConnection)factory.CreateConnection ();
|
||||
|
||||
var engine = new EngineConfig {
|
||||
Type = EngineType.MySQL,
|
||||
QuoteCharacter = "`",
|
||||
RemovesTrailingSpaces = true,
|
||||
EmptyBinaryAsNull = true,
|
||||
SupportsDate = true,
|
||||
SupportsTime = true
|
||||
};
|
||||
|
||||
return new ConnectionHolder<OdbcConnection> (engine, connection, connectionString);
|
||||
}
|
||||
#endif
|
||||
|
||||
private void CreateMssqlDatabase()
|
||||
{
|
||||
DBHelper.ExecuteNonQuery(sql.Connection, $"CREATE DATABASE [{DatabaseName}]");
|
||||
sql.Connection.ChangeDatabase(DatabaseName);
|
||||
|
||||
string query = File.ReadAllText(@"Test/ProviderTests/sql/sqlserver.sql");
|
||||
|
||||
var queries = SplitSqlStatements(query);
|
||||
foreach (var subQuery in queries)
|
||||
{
|
||||
DBHelper.ExecuteNonQuery(sql.Connection, subQuery);
|
||||
}
|
||||
}
|
||||
|
||||
#if !NO_ODBC
|
||||
private void CreateMysqlDatabase()
|
||||
{
|
||||
DBHelper.ExecuteNonQuery(odbc.Connection, $"CREATE DATABASE {DatabaseName}");
|
||||
odbc.Connection.ChangeDatabase(DatabaseName);
|
||||
odbc.ConnectionString += $"database={DatabaseName}";
|
||||
|
||||
string query = File.ReadAllText("Test/ProviderTests/sql/MySQL_5.sql");
|
||||
|
||||
var groups = query.Replace("delimiter ", "")
|
||||
.Split(new[] { "//\n" }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (var subQuery in groups[0].Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries).Concat(groups.Skip(1)))
|
||||
{
|
||||
DBHelper.ExecuteNonQuery(odbc.Connection, subQuery);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private void DropMssqlDatabase()
|
||||
{
|
||||
sql.Connection.ChangeDatabase("master");
|
||||
string query = $"ALTER DATABASE [{DatabaseName}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;\nDROP DATABASE [{DatabaseName}]";
|
||||
DBHelper.ExecuteNonQuery(sql.Connection, query);
|
||||
}
|
||||
|
||||
#if !NO_ODBC
|
||||
private void DropMysqlDatabase()
|
||||
{
|
||||
string query = $"DROP DATABASE [{DatabaseName}]";
|
||||
DBHelper.ExecuteNonQuery(odbc.Connection, query);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Split SQL script by "GO" statements
|
||||
private static IEnumerable<string> SplitSqlStatements(string sqlScript)
|
||||
{
|
||||
var statements = Regex.Split(sqlScript,
|
||||
$@"^[\t ]*GO[\t ]*\d*[\t ]*(?:--.*)?$",
|
||||
RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase);
|
||||
return statements.Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim(' ', '\r', '\n'));
|
||||
}
|
||||
|
||||
public static ConnectionManager Instance => instance ?? (instance = new ConnectionManager());
|
||||
|
||||
public string DatabaseName { get; }
|
||||
|
||||
#if !NO_ODBC
|
||||
|
||||
private ConnectionHolder<OdbcConnection> odbc;
|
||||
|
||||
public ConnectionHolder<OdbcConnection> Odbc
|
||||
{
|
||||
get
|
||||
{
|
||||
if (odbc == null)
|
||||
Assert.Ignore($"{OdbcEnvVar} environment variable is not set");
|
||||
return odbc;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public ConnectionHolder<SqlConnection> Sql
|
||||
{
|
||||
get
|
||||
{
|
||||
if (sql == null)
|
||||
Assert.Ignore($"{SqlEnvVar} environment variable is not set");
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
sql?.CloseConnection();
|
||||
#if !NO_ODBC
|
||||
odbc?.CloseConnection();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public class ConnectionHolder<TConnection> where TConnection : DbConnection
|
||||
{
|
||||
private TConnection connection;
|
||||
|
||||
public EngineConfig EngineConfig { get; }
|
||||
|
||||
public TConnection Connection
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!(connection.State == ConnectionState.Closed ||
|
||||
connection.State == ConnectionState.Broken))
|
||||
connection.Close();
|
||||
connection.ConnectionString = ConnectionString;
|
||||
connection.Open();
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
|
||||
public void CloseConnection()
|
||||
{
|
||||
if (connection != null && connection.State != ConnectionState.Closed)
|
||||
connection.Close();
|
||||
}
|
||||
|
||||
public string ConnectionString { get; set; }
|
||||
|
||||
public ConnectionHolder(EngineConfig engineConfig, TConnection connection, string connectionString)
|
||||
{
|
||||
EngineConfig = engineConfig;
|
||||
this.connection = connection;
|
||||
ConnectionString = connectionString;
|
||||
}
|
||||
}
|
||||
}
|
||||
79
mcs/class/System.Data/Test/ProviderTests/Common/DBHelper.cs
Normal file
79
mcs/class/System.Data/Test/ProviderTests/Common/DBHelper.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
// 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;
|
||||
|
||||
namespace MonoTests.System.Data.Connected
|
||||
{
|
||||
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 {
|
||||
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 {
|
||||
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 ();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// DataProvider.cs - Holds the data used for Validating Reader Classes
|
||||
// Author:
|
||||
// Senganal T (tsenganal@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.SqlClient;
|
||||
|
||||
namespace MonoTests.System.Data.Connected
|
||||
{
|
||||
public class DataProvider
|
||||
{
|
||||
private readonly DataSet data;
|
||||
|
||||
// TODO : The Data is now got from the Database.
|
||||
// Needs to be modified to get the data from a config file
|
||||
public DataProvider ()
|
||||
{
|
||||
data = new DataSet ();
|
||||
string query = "Select * from numeric_family order by id ASC;";
|
||||
query += "Select * from string_family order by id ASC;";
|
||||
query += "Select * from binary_family order by id ASC;";
|
||||
query += "Select * from datetime_family order by id ASC;";
|
||||
|
||||
SqlDataAdapter adapter = new SqlDataAdapter (query,
|
||||
ConnectionManager.Instance.Sql.ConnectionString);
|
||||
adapter.TableMappings.Add ("Table", "numeric_family");
|
||||
adapter.TableMappings.Add ("Table1", "string_family");
|
||||
adapter.TableMappings.Add ("Table2", "binary_family");
|
||||
adapter.TableMappings.Add ("Table3", "datetime_family");
|
||||
|
||||
data.Tables.Add ("numeric_family");
|
||||
data.Tables.Add ("string_family");
|
||||
data.Tables.Add ("binary_family");
|
||||
data.Tables.Add ("datetime_family");
|
||||
adapter.Fill (data);
|
||||
}
|
||||
|
||||
public DataSet GetDataSet ()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
205
mcs/class/System.Data/Test/ProviderTests/Common/EngineConfig.cs
Normal file
205
mcs/class/System.Data/Test/ProviderTests/Common/EngineConfig.cs
Normal file
@@ -0,0 +1,205 @@
|
||||
//
|
||||
// EngineConfig.cs - Holds information on the capabilities and behavior of an
|
||||
// RDBMS engine.
|
||||
//
|
||||
// Author:
|
||||
// Gert Driesen (drieseng@users.sourceforge.net
|
||||
//
|
||||
// Copyright (c) 2008 Gert Driesen
|
||||
//
|
||||
// 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.Globalization;
|
||||
using System.Xml;
|
||||
|
||||
namespace MonoTests.System.Data.Connected
|
||||
{
|
||||
public sealed class EngineConfig
|
||||
{
|
||||
private string name;
|
||||
private string quoteCharacter;
|
||||
private bool removesTrailingSpaces;
|
||||
private bool emptyBinaryAsNull;
|
||||
private bool supportsMicroseconds;
|
||||
private bool supportsUniqueIdentifier;
|
||||
private bool supportsDate;
|
||||
private bool supportsTime;
|
||||
private bool supportsTimestamp;
|
||||
private EngineType type;
|
||||
private int clientVersion;
|
||||
|
||||
public EngineConfig ()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name {
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the character(s) for quoting identifiers.
|
||||
/// </summary>
|
||||
public string QuoteCharacter {
|
||||
get { return quoteCharacter; }
|
||||
set { quoteCharacter = value; }
|
||||
}
|
||||
|
||||
public EngineType Type {
|
||||
get { return type; }
|
||||
set { type = value; }
|
||||
}
|
||||
|
||||
public bool RemovesTrailingSpaces {
|
||||
get { return removesTrailingSpaces; }
|
||||
set { removesTrailingSpaces = value; }
|
||||
}
|
||||
|
||||
public bool EmptyBinaryAsNull {
|
||||
get { return emptyBinaryAsNull; }
|
||||
set { emptyBinaryAsNull = value; }
|
||||
}
|
||||
|
||||
public bool SupportsMicroseconds {
|
||||
get { return supportsMicroseconds; }
|
||||
set { supportsMicroseconds = value; }
|
||||
}
|
||||
|
||||
public bool SupportsUniqueIdentifier {
|
||||
get { return supportsUniqueIdentifier; }
|
||||
set { supportsUniqueIdentifier = value; }
|
||||
}
|
||||
|
||||
public bool SupportsDate {
|
||||
get { return supportsDate; }
|
||||
set { supportsDate = value; }
|
||||
}
|
||||
|
||||
public bool SupportsTime {
|
||||
get { return supportsTime; }
|
||||
set { supportsTime = value; }
|
||||
}
|
||||
|
||||
public bool SupportsTimestamp {
|
||||
get { return supportsTimestamp; }
|
||||
set { supportsTimestamp = value; }
|
||||
}
|
||||
|
||||
public int ClientVersion {
|
||||
get { return clientVersion; }
|
||||
set { clientVersion = value; }
|
||||
}
|
||||
|
||||
public static EngineConfig FromXml (XmlNode config)
|
||||
{
|
||||
EngineConfig engine = new EngineConfig ();
|
||||
engine.name = GetAttribValue (config, "name", true);
|
||||
engine.quoteCharacter = GetAttribValue (config, "quoteCharacter", true);
|
||||
engine.removesTrailingSpaces = ParseBoolean (config, "removesTrailingSpaces", false, true);
|
||||
engine.emptyBinaryAsNull = ParseBoolean (config, "emptyBinaryAsNull", false, true);
|
||||
engine.supportsMicroseconds = ParseBoolean (config, "supportsMicroseconds", false, true);
|
||||
engine.supportsUniqueIdentifier = ParseBoolean (config, "supportsUniqueIdentifier", false, true);
|
||||
engine.supportsDate = ParseBoolean (config, "supportsDate", false, true);
|
||||
engine.supportsTime = ParseBoolean (config, "supportsTime", false, true);
|
||||
engine.supportsTimestamp = ParseBoolean (config, "supportsTimestamp", false, true);
|
||||
engine.type = ParseEngineType (config, "type");
|
||||
engine.clientVersion = ParseClientVersion (config, "clientversion");
|
||||
return engine;
|
||||
}
|
||||
|
||||
static string GetAttribValue (XmlNode node, string name, bool required)
|
||||
{
|
||||
XmlAttribute attr = node.Attributes [name];
|
||||
if (attr == null) {
|
||||
if (required)
|
||||
throw CreateAttributeMissingException (name, node);
|
||||
return null;
|
||||
}
|
||||
return attr.Value;
|
||||
}
|
||||
|
||||
static bool ParseBoolean (XmlNode config, string attrName, bool required, bool defaultValue)
|
||||
{
|
||||
XmlAttribute attr = config.Attributes [attrName];
|
||||
if (attr == null) {
|
||||
if (required)
|
||||
throw CreateAttributeMissingException (attrName, config);
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
string value = attr.Value;
|
||||
|
||||
try {
|
||||
return bool.Parse (value);
|
||||
} catch (Exception ex) {
|
||||
throw CreateInvalidValueException (attrName,
|
||||
value, attr, ex);
|
||||
}
|
||||
}
|
||||
|
||||
static EngineType ParseEngineType (XmlNode config, string attrName)
|
||||
{
|
||||
XmlAttribute attr = config.Attributes [attrName];
|
||||
if (attr == null)
|
||||
throw CreateAttributeMissingException (attrName, config);
|
||||
|
||||
string value = attr.Value;
|
||||
|
||||
try {
|
||||
return (EngineType) Enum.Parse (typeof (EngineType), value);
|
||||
} catch (Exception ex) {
|
||||
throw CreateInvalidValueException (attrName,
|
||||
value, attr, ex);
|
||||
}
|
||||
}
|
||||
|
||||
static int ParseClientVersion (XmlNode config, string attrName)
|
||||
{
|
||||
XmlAttribute attr = config.Attributes [attrName];
|
||||
if (attr == null)
|
||||
return -1;
|
||||
|
||||
string value = attr.Value;
|
||||
|
||||
try {
|
||||
return Int32.Parse (value);
|
||||
} catch (Exception ex) {
|
||||
throw CreateInvalidValueException (attrName,
|
||||
value, attr, ex);
|
||||
}
|
||||
}
|
||||
|
||||
static Exception CreateInvalidValueException (string name, string value, XmlNode node, Exception cause)
|
||||
{
|
||||
string msg = string.Format (CultureInfo.InvariantCulture,
|
||||
"Invalid value '{0}' for attribute {1}.",
|
||||
value, name);
|
||||
throw new ArgumentOutOfRangeException (msg, cause);
|
||||
}
|
||||
|
||||
static Exception CreateAttributeMissingException (string name, XmlNode node)
|
||||
{
|
||||
string msg = string.Format (CultureInfo.InvariantCulture,
|
||||
"Missing '{0}' attribute.", name);
|
||||
throw new ArgumentException (msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// EngineType.cs : Defines different database engines supports by the
|
||||
// provider tests.
|
||||
//
|
||||
// Authors:
|
||||
// Gert Driesen (drieseng@users.sourceforge.net)
|
||||
//
|
||||
// Copyright (c) 2008 Gert Driesen
|
||||
//
|
||||
// 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.
|
||||
|
||||
namespace MonoTests.System.Data.Connected
|
||||
{
|
||||
public enum EngineType
|
||||
{
|
||||
SQLServer = 1,
|
||||
MySQL = 2,
|
||||
PostgreSQL = 3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// ProviderTestsConfigurationHandler.cs - Provides access to configuration info
|
||||
// for the connected System.Data tests.
|
||||
//
|
||||
// Author:
|
||||
// Gert Driesen (drieseng@users.sourceforge.net)
|
||||
//
|
||||
// Copyright (c) 2008 Gert Driesen
|
||||
//
|
||||
// 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 !NO_CONFIGURATION
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Configuration;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace MonoTests.System.Data.Connected
|
||||
{
|
||||
class ProviderTestsConfigurationHandler : IConfigurationSectionHandler
|
||||
{
|
||||
public object Create (object parent, object configContext, XmlNode section)
|
||||
{
|
||||
Hashtable engines = new Hashtable ();
|
||||
|
||||
foreach (XmlNode engineNode in section.SelectNodes ("engines/engine")) {
|
||||
EngineConfig engine = EngineConfig.FromXml (engineNode);
|
||||
if (engines.Contains (engine.Name)) {
|
||||
string msg = string.Format (CultureInfo.InvariantCulture,
|
||||
"A engine with name '{0}' already exists.",
|
||||
engine.Name);
|
||||
throw new ConfigurationErrorsException (msg, engineNode);
|
||||
}
|
||||
engines.Add (engine.Name, engine);
|
||||
}
|
||||
|
||||
Hashtable connections = new Hashtable ();
|
||||
|
||||
foreach (XmlNode connNode in section.SelectNodes ("connections/connection")) {
|
||||
ConnectionConfig conn = ConnectionConfig.FromXml (connNode, engines);
|
||||
if (connections.Contains (conn.Name)) {
|
||||
string msg = string.Format (CultureInfo.InvariantCulture,
|
||||
"A connection with name '{0}' already exists.",
|
||||
conn.Name);
|
||||
throw new ConfigurationErrorsException (msg, connNode);
|
||||
}
|
||||
connections.Add (conn.Name, conn);
|
||||
}
|
||||
|
||||
ConnectionConfig [] c = new ConnectionConfig [connections.Count];
|
||||
connections.Values.CopyTo (c, 0);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,114 @@
|
||||
// DbDataReaderTest.cs - NUnit Test Cases for testing the
|
||||
// DbDataReader family of classes
|
||||
//
|
||||
// Authors:
|
||||
// Gert Driesen (drieseng@users.sourceforge.net)
|
||||
//
|
||||
// Copyright (c) 2008 Gert Driesen
|
||||
//
|
||||
// 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.Data.SqlTypes;
|
||||
using System.Globalization;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MonoTests.System.Data.Connected
|
||||
{
|
||||
[TestFixture]
|
||||
[Category ("sqlserver")]
|
||||
public class DbDataReaderTest
|
||||
{
|
||||
DbConnection conn;
|
||||
DbCommand cmd;
|
||||
DbDataReader rdr;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp ()
|
||||
{
|
||||
conn = ConnectionManager.Instance.Sql.Connection;
|
||||
cmd = conn.CreateCommand ();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown ()
|
||||
{
|
||||
cmd?.Dispose ();
|
||||
rdr?.Dispose ();
|
||||
ConnectionManager.Instance.Close ();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProviderSpecificValues_Reader_Closed ()
|
||||
{
|
||||
cmd.CommandText = "SELECT * FROM employee";
|
||||
rdr = cmd.ExecuteReader ();
|
||||
rdr.Close ();
|
||||
|
||||
try {
|
||||
rdr.GetProviderSpecificValues (null);
|
||||
Assert.Fail ("#1");
|
||||
} catch (InvalidOperationException ex) {
|
||||
// Invalid attempt to call MetaData
|
||||
// when reader is closed
|
||||
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
|
||||
Assert.IsNull (ex.InnerException, "#3");
|
||||
Assert.IsNotNull (ex.Message, "#4");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProviderSpecificValues_Reader_NoData ()
|
||||
{
|
||||
cmd.CommandText = "SELECT * FROM employee where id = 6666";
|
||||
rdr = cmd.ExecuteReader ();
|
||||
|
||||
try {
|
||||
rdr.GetProviderSpecificValues (null);
|
||||
Assert.Fail ("#A1");
|
||||
} catch (InvalidOperationException ex) {
|
||||
// Invalid attempt to read when no data
|
||||
// is present
|
||||
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
|
||||
Assert.IsNull (ex.InnerException, "#A3");
|
||||
Assert.IsNotNull (ex.Message, "#A4");
|
||||
}
|
||||
|
||||
Assert.IsFalse (rdr.Read (), "B");
|
||||
|
||||
try {
|
||||
rdr.GetProviderSpecificValues (null);
|
||||
Assert.Fail ("#C1");
|
||||
} catch (InvalidOperationException ex) {
|
||||
// Invalid attempt to read when no data
|
||||
// is present
|
||||
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
|
||||
Assert.IsNull (ex.InnerException, "#C3");
|
||||
Assert.IsNotNull (ex.Message, "#C4");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
// 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;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MonoTests.System.Data.Connected
|
||||
{
|
||||
[TestFixture]
|
||||
[Category ("odbc"), Category ("sqlserver")]
|
||||
public class CommandTest
|
||||
{
|
||||
IDbConnection conn;
|
||||
IDbCommand cmd;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp ()
|
||||
{
|
||||
conn = ConnectionManager.Instance.Sql.Connection;
|
||||
cmd = conn.CreateCommand ();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown ()
|
||||
{
|
||||
if (cmd != null)
|
||||
cmd.Dispose ();
|
||||
ConnectionManager.Instance.Close ();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExecuteNonQuery_CommandText_Empty ()
|
||||
{
|
||||
try {
|
||||
cmd.ExecuteNonQuery ();
|
||||
Assert.Fail ("#A1");
|
||||
} catch (InvalidOperationException ex) {
|
||||
// ExecuteNonQuery: CommandText property
|
||||
// has not been initialized
|
||||
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
|
||||
Assert.IsNull (ex.InnerException, "#A3");
|
||||
Assert.IsNotNull (ex.Message, "#A4");
|
||||
Assert.IsTrue (ex.Message.StartsWith ("ExecuteNonQuery"), "#A5:" + ex.Message);
|
||||
}
|
||||
|
||||
cmd.CommandText = string.Empty;
|
||||
|
||||
try {
|
||||
cmd.ExecuteNonQuery ();
|
||||
Assert.Fail ("#B1");
|
||||
} catch (InvalidOperationException ex) {
|
||||
// ExecuteNonQuery: CommandText property
|
||||
// has not been initialized
|
||||
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
|
||||
Assert.IsNull (ex.InnerException, "#B3");
|
||||
Assert.IsNotNull (ex.Message, "#B4");
|
||||
Assert.IsTrue (ex.Message.StartsWith ("ExecuteNonQuery"), "#B5:" + ex.Message);
|
||||
}
|
||||
|
||||
cmd.CommandText = null;
|
||||
|
||||
try {
|
||||
cmd.ExecuteNonQuery ();
|
||||
Assert.Fail ("#C1");
|
||||
} catch (InvalidOperationException ex) {
|
||||
// ExecuteNonQuery: CommandText property
|
||||
// has not been initialized
|
||||
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
|
||||
Assert.IsNull (ex.InnerException, "#C3");
|
||||
Assert.IsNotNull (ex.Message, "#C4");
|
||||
Assert.IsTrue (ex.Message.StartsWith ("ExecuteNonQuery"), "#C5:" + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExecuteReader_CommandText_Empty ()
|
||||
{
|
||||
try {
|
||||
cmd.ExecuteReader ();
|
||||
Assert.Fail ("#A1");
|
||||
} catch (InvalidOperationException ex) {
|
||||
// ExecuteReader: CommandText property
|
||||
// has not been initialized
|
||||
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
|
||||
Assert.IsNull (ex.InnerException, "#A3");
|
||||
Assert.IsNotNull (ex.Message, "#A4");
|
||||
Assert.IsTrue (ex.Message.StartsWith ("ExecuteReader"), "#A5:" + ex.Message);
|
||||
}
|
||||
|
||||
cmd.CommandText = string.Empty;
|
||||
|
||||
try {
|
||||
cmd.ExecuteReader ();
|
||||
Assert.Fail ("#B1");
|
||||
} catch (InvalidOperationException ex) {
|
||||
// ExecuteReader: CommandText property
|
||||
// has not been initialized
|
||||
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
|
||||
Assert.IsNull (ex.InnerException, "#B3");
|
||||
Assert.IsNotNull (ex.Message, "#B4");
|
||||
Assert.IsTrue (ex.Message.StartsWith ("ExecuteReader"), "#B5:" + ex.Message);
|
||||
}
|
||||
|
||||
cmd.CommandText = null;
|
||||
|
||||
try {
|
||||
cmd.ExecuteReader ();
|
||||
Assert.Fail ("#C1");
|
||||
} catch (InvalidOperationException ex) {
|
||||
// ExecuteReader: CommandText property
|
||||
// has not been initialized
|
||||
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
|
||||
Assert.IsNull (ex.InnerException, "#C3");
|
||||
Assert.IsNotNull (ex.Message, "#C4");
|
||||
Assert.IsTrue (ex.Message.StartsWith ("ExecuteReader"), "#C5:" + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[Test] // bug #462947
|
||||
public void ExecuteReader_Connection_Reuse ()
|
||||
{
|
||||
cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
|
||||
|
||||
CommandBehavior behavior = CommandBehavior.SequentialAccess |
|
||||
CommandBehavior.SingleResult;
|
||||
|
||||
using (IDataReader reader = cmd.ExecuteReader (behavior)) {
|
||||
Assert.IsTrue (reader.Read (), "#A1");
|
||||
|
||||
long totalsize = reader.GetBytes (0, 0, null, 0, 0);
|
||||
byte [] val = new byte [totalsize];
|
||||
long ret = reader.GetBytes (0, 0, val, 0, val.Length);
|
||||
Assert.AreEqual (5, ret, "#A2");
|
||||
Assert.AreEqual (new byte [] { 0x32, 0x56, 0x00, 0x44, 0x22 }, val, "#A3");
|
||||
}
|
||||
|
||||
ConnectionManager.Instance.Sql.CloseConnection ();
|
||||
conn = ConnectionManager.Instance.Sql.Connection;
|
||||
|
||||
using (IDataReader reader = cmd.ExecuteReader (behavior)) {
|
||||
Assert.IsTrue (reader.Read (), "#B1");
|
||||
|
||||
long totalsize = reader.GetBytes (0, 0, null, 0, 0);
|
||||
byte [] val = new byte [totalsize];
|
||||
long ret = reader.GetBytes (0, 0, val, 0, val.Length);
|
||||
Assert.AreEqual (5, ret, "#B2");
|
||||
Assert.AreEqual (new byte [] { 0x32, 0x56, 0x00, 0x44, 0x22 }, val, "#B3");
|
||||
}
|
||||
|
||||
using (IDataReader reader = cmd.ExecuteReader (behavior)) {
|
||||
Assert.IsTrue (reader.Read (), "#C");
|
||||
}
|
||||
|
||||
ConnectionManager.Instance.Sql.CloseConnection ();
|
||||
conn = ConnectionManager.Instance.Sql.Connection;
|
||||
|
||||
|
||||
using (IDataReader reader = cmd.ExecuteReader (behavior)) {
|
||||
Assert.IsTrue (reader.Read (), "#D");
|
||||
}
|
||||
|
||||
using (IDataReader reader = cmd.ExecuteReader (behavior)) {
|
||||
Assert.IsTrue (reader.Read (), "#E");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExecuteScalar ()
|
||||
{
|
||||
cmd.CommandText = "select count(*) from employee where id < 3";
|
||||
Assert.AreEqual (2, (int) Convert.ChangeType (cmd.ExecuteScalar (),
|
||||
typeof (int)),
|
||||
"#1");
|
||||
cmd.Dispose ();
|
||||
|
||||
cmd = conn.CreateCommand ();
|
||||
cmd.CommandText = "select id from employee where id = 666";
|
||||
Assert.IsNull (cmd.ExecuteScalar (), "#2");
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,301 @@
|
||||
// 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.
|
||||
//
|
||||
|
||||
#if !NO_ODBC
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.Odbc;
|
||||
using NUnit.Framework;
|
||||
|
||||
|
||||
namespace MonoTests.System.Data.Connected.Odbc
|
||||
{
|
||||
[TestFixture]
|
||||
[Category ("odbc")]
|
||||
public class OdbcCommandTest
|
||||
{
|
||||
OdbcConnection conn;
|
||||
OdbcCommand cmd;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp ()
|
||||
{
|
||||
conn = ConnectionManager.Instance.Odbc.Connection;
|
||||
cmd = conn.CreateCommand ();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown ()
|
||||
{
|
||||
if (cmd != null)
|
||||
cmd.Dispose ();
|
||||
ConnectionManager.Instance.Close ();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PrepareAndExecuteTest ()
|
||||
{
|
||||
OdbcDataReader reader = null;
|
||||
|
||||
try {
|
||||
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);
|
||||
cmd = 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 id, small_id from " + tableName + " order by id asc";
|
||||
reader = cmd.ExecuteReader ();
|
||||
|
||||
Assert.IsTrue (reader.Read (), "#A1");
|
||||
Assert.AreEqual (1, reader.GetValue (0), "#A2");
|
||||
Assert.AreEqual (5, reader.GetValue (1), "#A3");
|
||||
Assert.IsTrue (reader.Read (), "#A4");
|
||||
Assert.AreEqual (2, reader.GetValue (0), "#A5");
|
||||
Assert.AreEqual (6, reader.GetValue (1), "#A6");
|
||||
Assert.IsFalse (reader.Read (), "#A7");
|
||||
reader.Close ();
|
||||
cmd.Dispose ();
|
||||
|
||||
cmd = conn.CreateCommand ();
|
||||
cmd.CommandText = "select id, small_id from " + tableName + " order by id asc";
|
||||
|
||||
reader = cmd.ExecuteReader ();
|
||||
Assert.IsTrue (reader.Read (), "#B1");
|
||||
Assert.AreEqual (1, reader.GetValue (0), "#B2");
|
||||
Assert.AreEqual (5, reader.GetValue (1), "#B3");
|
||||
Assert.IsTrue (reader.Read (), "#B4");
|
||||
Assert.AreEqual (2, reader.GetValue (0), "#B5");
|
||||
Assert.AreEqual (6, reader.GetValue (1), "#B6");
|
||||
Assert.IsFalse (reader.Read (), "#B7");
|
||||
} finally {
|
||||
DBHelper.ExecuteNonQuery (conn, "DROP TABLE " + tableName);
|
||||
}
|
||||
} finally {
|
||||
if (reader != null)
|
||||
reader.Close ();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test String parameters to ODBC Command
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void ExecuteStringParameterTest()
|
||||
{
|
||||
cmd.CommandText = "select count(*) from employee where fname=?;";
|
||||
string colvalue = "suresh";
|
||||
OdbcParameter param = cmd.Parameters.Add("@un", OdbcType.VarChar);
|
||||
param.Value = colvalue;
|
||||
int count = Convert.ToInt32 (cmd.ExecuteScalar ());
|
||||
Assert.AreEqual (1, count, "#1 String parameter not passed correctly");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test ExecuteNonQuery
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void ExecuteNonQueryTest ()
|
||||
{
|
||||
int ret;
|
||||
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.CommandText = "select count(*) from employee where id <= ?;";
|
||||
cmd.Parameters.Add ("@un", OdbcType.Int).Value = 3;
|
||||
ret = cmd.ExecuteNonQuery ();
|
||||
switch (ConnectionManager.Instance.Odbc.EngineConfig.Type) {
|
||||
case EngineType.SQLServer:
|
||||
Assert.AreEqual (-1, ret, "#1");
|
||||
break;
|
||||
case EngineType.MySQL:
|
||||
Assert.AreEqual (1, ret, "#1");
|
||||
break;
|
||||
default:
|
||||
Assert.Fail ("Engine type not supported.");
|
||||
break;
|
||||
}
|
||||
|
||||
cmd = conn.CreateCommand ();
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.CommandText = "select * from employee where id <= ?;";
|
||||
cmd.Parameters.Add ("@un", OdbcType.Int).Value = 3;
|
||||
ret = cmd.ExecuteNonQuery ();
|
||||
switch (ConnectionManager.Instance.Odbc.EngineConfig.Type) {
|
||||
case EngineType.SQLServer:
|
||||
Assert.AreEqual (-1, ret, "#2");
|
||||
break;
|
||||
case EngineType.MySQL:
|
||||
Assert.AreEqual (3, ret, "#2");
|
||||
break;
|
||||
default:
|
||||
Assert.Fail ("Engine type not supported.");
|
||||
break;
|
||||
}
|
||||
|
||||
cmd = conn.CreateCommand ();
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.CommandText = "select * from employee where id <= 3;";
|
||||
ret = cmd.ExecuteNonQuery ();
|
||||
switch (ConnectionManager.Instance.Odbc.EngineConfig.Type) {
|
||||
case EngineType.SQLServer:
|
||||
Assert.AreEqual (-1, ret, "#3");
|
||||
break;
|
||||
case EngineType.MySQL:
|
||||
Assert.AreEqual (3, ret, "#3");
|
||||
break;
|
||||
default:
|
||||
Assert.Fail ("Engine type not supported.");
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
// insert
|
||||
cmd = conn.CreateCommand ();
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.CommandText = "insert into employee (id, fname, dob, doj) values " +
|
||||
" (6001, 'tttt', '1999-01-22', '2005-02-11');";
|
||||
ret = cmd.ExecuteNonQuery ();
|
||||
Assert.AreEqual (1, ret, "#4");
|
||||
|
||||
cmd = conn.CreateCommand ();
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.CommandText = "insert into employee (id, fname, dob, doj) values " +
|
||||
" (?, 'tttt', '1999-01-22', '2005-02-11');";
|
||||
cmd.Parameters.Add (new OdbcParameter ("id", OdbcType.Int));
|
||||
cmd.Parameters [0].Value = 6002;
|
||||
cmd.Prepare ();
|
||||
ret = cmd.ExecuteNonQuery ();
|
||||
Assert.AreEqual (1, ret, "#5");
|
||||
} finally {
|
||||
// delete
|
||||
cmd = (OdbcCommand) conn.CreateCommand ();
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.CommandText = "delete from employee where id > 6000";
|
||||
ret = cmd.ExecuteNonQuery ();
|
||||
Assert.AreEqual (2, ret, "#6");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExecuteNonQuery_Query_Invalid ()
|
||||
{
|
||||
cmd.CommandText = "select id1 from numeric_family"; ;
|
||||
try {
|
||||
cmd.ExecuteNonQuery ();
|
||||
Assert.Fail ("#A1");
|
||||
} catch (OdbcException ex) {
|
||||
// Invalid column name 'id1'
|
||||
Assert.AreEqual (typeof (OdbcException), ex.GetType (), "#A2");
|
||||
Assert.IsNull (ex.InnerException, "#A3");
|
||||
Assert.IsNotNull (ex.Message, "#A5");
|
||||
}
|
||||
|
||||
// ensure connection is not closed after error
|
||||
|
||||
int result;
|
||||
|
||||
cmd.CommandText = "INSERT INTO numeric_family (id, type_int) VALUES (6100, 200)";
|
||||
result = cmd.ExecuteNonQuery ();
|
||||
Assert.AreEqual (1, result, "#B1");
|
||||
|
||||
cmd.CommandText = "DELETE FROM numeric_family WHERE id = 6100";
|
||||
result = cmd.ExecuteNonQuery ();
|
||||
Assert.AreEqual (1, result, "#B1");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Dispose ()
|
||||
{
|
||||
OdbcTransaction trans = null;
|
||||
|
||||
try {
|
||||
trans = conn.BeginTransaction ();
|
||||
|
||||
cmd.CommandText = "SELECT 'a'";
|
||||
cmd.CommandTimeout = 67;
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.DesignTimeVisible = false;
|
||||
cmd.Parameters.Add (new OdbcParameter ());
|
||||
cmd.Transaction = trans;
|
||||
cmd.UpdatedRowSource = UpdateRowSource.OutputParameters;
|
||||
|
||||
cmd.Dispose ();
|
||||
|
||||
Assert.AreEqual (string.Empty, cmd.CommandText, "#1");
|
||||
Assert.AreEqual (67, cmd.CommandTimeout, "#2");
|
||||
Assert.AreEqual (CommandType.StoredProcedure, cmd.CommandType, "#3");
|
||||
Assert.IsNull (cmd.Connection, "#4");
|
||||
Assert.IsFalse (cmd.DesignTimeVisible, "#5");
|
||||
Assert.IsNotNull (cmd.Parameters, "#6");
|
||||
Assert.AreEqual (0, cmd.Parameters.Count, "#7");
|
||||
Assert.IsNull (cmd.Transaction, "#8");
|
||||
Assert.AreEqual (UpdateRowSource.OutputParameters, cmd.UpdatedRowSource, "#9");
|
||||
} finally {
|
||||
if (trans != null)
|
||||
trans.Rollback ();
|
||||
}
|
||||
}
|
||||
|
||||
[Test] // bug #341743
|
||||
public void Dispose_Connection_Disposed ()
|
||||
{
|
||||
cmd.CommandText = "SELECT 'a'";
|
||||
cmd.ExecuteNonQuery ();
|
||||
|
||||
conn.Dispose ();
|
||||
|
||||
Assert.AreSame (conn, cmd.Connection, "#1");
|
||||
cmd.Dispose ();
|
||||
Assert.IsNull (cmd.Connection, "#2");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,122 @@
|
||||
// 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.
|
||||
//
|
||||
|
||||
#if !NO_ODBC
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.Odbc;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MonoTests.System.Data.Connected.Odbc
|
||||
{
|
||||
[TestFixture]
|
||||
[Category ("odbc")]
|
||||
public class OdbcDataAdapterTest
|
||||
{
|
||||
[Test]
|
||||
public void FillTest ()
|
||||
{
|
||||
OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
|
||||
try
|
||||
{
|
||||
// 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.Instance.Odbc.CloseConnection ();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore]
|
||||
public void InsertUtf8Test ()
|
||||
{
|
||||
OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
|
||||
try
|
||||
{
|
||||
DoExecuteNonQuery ((OdbcConnection) conn,
|
||||
"CREATE TABLE odbc_ins_utf8_test(ival int not null, sval varchar(20))");
|
||||
Assert.AreEqual (DoExecuteNonQuery ((OdbcConnection) conn,
|
||||
"INSERT INTO odbc_ins_utf8_test(ival, sval) VALUES (1, 'English')"),
|
||||
1);
|
||||
Assert.AreEqual (DoExecuteNonQuery ((OdbcConnection) conn,
|
||||
"INSERT INTO odbc_ins_utf8_test(ival, sval) VALUES (2, 'Français')"),
|
||||
1);
|
||||
Assert.AreEqual (DoExecuteNonQuery ((OdbcConnection) conn,
|
||||
"INSERT INTO odbc_ins_utf8_test(ival, sval) VALUES (3, 'Español')"),
|
||||
1);
|
||||
Assert.AreEqual (DoExecuteScalar ((OdbcConnection) conn,
|
||||
"SELECT COUNT(*) FROM odbc_ins_utf8_test WHERE sval " +
|
||||
"IN('English', 'Français', 'Español')"),
|
||||
3);
|
||||
} finally {
|
||||
DoExecuteNonQuery ((OdbcConnection) conn, "DROP TABLE odbc_ins_utf8_test");
|
||||
ConnectionManager.Instance.Odbc.CloseConnection ();
|
||||
}
|
||||
}
|
||||
|
||||
private int DoExecuteNonQuery (OdbcConnection conn, string sql)
|
||||
{
|
||||
OdbcCommand cmd = new OdbcCommand (sql, conn);
|
||||
return cmd.ExecuteNonQuery ();
|
||||
}
|
||||
|
||||
private int DoExecuteScalar (OdbcConnection conn, string sql)
|
||||
{
|
||||
OdbcCommand cmd = new OdbcCommand (sql, conn);
|
||||
object value = cmd.ExecuteScalar ();
|
||||
return (int) Convert.ChangeType (value, typeof (int));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
||||
9cb09eac042bdf5010d77bfe1ccd2ee1563518cc
|
||||
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// SqlDataAdapterTest.cs - NUnit Test Cases for testing the
|
||||
// SqlDataAdapter class
|
||||
// Author:
|
||||
// Nidhi Rawal (rawalnidhi_rawal@yahoo.com)
|
||||
//
|
||||
// Copyright (c) 2007 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.SqlClient;
|
||||
using System.Net;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using System.Security.Permissions;
|
||||
|
||||
using System.Security;
|
||||
|
||||
namespace MonoTests.System.Data.Connected.SqlClient
|
||||
{
|
||||
[TestFixture]
|
||||
[Category ("CAS")]
|
||||
public class SqlClientFactoryTest
|
||||
{
|
||||
[Test]
|
||||
public void CreatePermissionTest ()
|
||||
{
|
||||
SqlClientFactory factory = SqlClientFactory.Instance;
|
||||
CodeAccessPermission permission, perm;
|
||||
permission = factory.CreatePermission (PermissionState.None);
|
||||
perm = factory.CreatePermission (PermissionState.Unrestricted);
|
||||
Assert.AreEqual (false, perm.IsSubsetOf (permission), "#1");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,182 @@
|
||||
// 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.
|
||||
//
|
||||
|
||||
|
||||
#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.Connected.SqlClient
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
[Category ("sqlserver")]
|
||||
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");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TrustServerCertificateTest ()
|
||||
{
|
||||
builder = new SqlConnectionStringBuilder ();
|
||||
Assert.AreEqual (false, builder.TrustServerCertificate, "#1 The default value should be false");
|
||||
builder.TrustServerCertificate = true;
|
||||
Assert.AreEqual (true, builder.TrustServerCertificate, "#2 The value returned should be true after setting the value of TrustServerCertificate to true");
|
||||
Assert.AreEqual ("TrustServerCertificate=True", builder.ConnectionString, "#3 The value of the key TrustServerCertificate should be added to the connection string");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TypeSystemVersionTest ()
|
||||
{
|
||||
builder = new SqlConnectionStringBuilder ();
|
||||
Assert.AreEqual ("Latest", builder.TypeSystemVersion, "#1 The default value for the property should be Latest");
|
||||
builder.TypeSystemVersion = "SQL Server 2005";
|
||||
Assert.AreEqual ("SQL Server 2005", builder.TypeSystemVersion, "#2 The value for the property should be SQL Server 2005 after setting this value");
|
||||
Assert.AreEqual ("Type System Version=\"SQL Server 2005\"", builder.ConnectionString, "#3 The value of the key Type System Version should be added to the connection string");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UserInstanceTest ()
|
||||
{
|
||||
builder = new SqlConnectionStringBuilder ();
|
||||
Assert.AreEqual (false, builder.UserInstance, "#1 The default value for the property should be false");
|
||||
builder.UserInstance = true;
|
||||
Assert.AreEqual (true, builder.UserInstance, "#2 The value for the property should be true after setting its value to true");
|
||||
Assert.AreEqual ("User Instance=True", builder.ConnectionString, "#3 The value of the key User Instance should be added to the connection string");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SettingUserInstanceTest ()
|
||||
{
|
||||
builder = new SqlConnectionStringBuilder ();
|
||||
builder["User Instance"] = true;
|
||||
Assert.AreEqual ("User Instance=True", builder.ConnectionString, "#1 The value of the key User Instance should be added to the connection string");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContextConnectionTest ()
|
||||
{
|
||||
builder = new SqlConnectionStringBuilder ();
|
||||
Assert.AreEqual (false, builder.ContextConnection, "#1 The default value for the property should be false");
|
||||
builder.ContextConnection = true;
|
||||
Assert.AreEqual (true, builder.ContextConnection, "#2 The value for the property should be true after setting its value to true");
|
||||
Assert.AreEqual ("Context Connection=True", builder.ConnectionString, "#3 The value of the key Context Connection should be added to the connection string");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SettingContextConnectionTest ()
|
||||
{
|
||||
builder = new SqlConnectionStringBuilder ();
|
||||
builder["Context Connection"] = true;
|
||||
Assert.AreEqual ("Context Connection=True", builder.ConnectionString, "#1 The value of the key Context Connection should be added to the connection string");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user