Esempio n. 1
0
        /// <summary>
        /// Gets the database.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="clientType">Type of the client.</param>
        /// <returns>NDbUnit database object to interact with the Database</returns>
        private NDbUnit.Core.INDbUnitTest GetDatabase(string connectionString, DatabaseClientType clientType)
        {
            switch (clientType)
            {
            case DatabaseClientType.SqlClient:
                return(DatabaseSpecificTypeFactory.CreateINDBUnitTest(NDBUNIT_SQLCLIENT_TYPE, NDBUNIT_SQLCLIENT_ASSEMBLY, connectionString));

            case DatabaseClientType.OleDBClient:
                return(DatabaseSpecificTypeFactory.CreateINDBUnitTest(NDBUNIT_OLEDB_TYPE, NDBUNIT_OLEDB_ASSEMBLY, connectionString));

            case DatabaseClientType.SqlCeClient:
                return(DatabaseSpecificTypeFactory.CreateINDBUnitTest(NDBUNIT_SQLCE_TYPE, NDBUNIT_SQLCE_ASSEMBLY, connectionString));

            case DatabaseClientType.SqliteClient:
                return(DatabaseSpecificTypeFactory.CreateINDBUnitTest(NDBUNIT_SQLLITE_TYPE, NDBUNIT_SQLLITE_ASSEMBLY, connectionString));

            case DatabaseClientType.MySqlClient:
                return(DatabaseSpecificTypeFactory.CreateINDBUnitTest(NDBUNIT_MYSQL_TYPE, NDBUNIT_MYSQL_ASSEMBLY, connectionString));

            case DatabaseClientType.OracleClient:
                return(DatabaseSpecificTypeFactory.CreateINDBUnitTest(NDBUNIT_ORACLE_TYPE, NDBUNIT_ORACLE_ASSEMBLY, connectionString));

            default:
                throw new InvalidOperationException(string.Format("Unsupported DatabaseClientType: {0}", clientType.ToString()));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Saves the existing database.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="schemaFilePathName">Name of the schema file path.</param>
        /// <param name="datasetFilePathName">Name of the dataset file path.</param>
        /// <param name="clientType">Type of the client.</param>
        protected virtual void SaveDatabase(string connectionString, string schemaFilePathName, string datasetFilePathName, DatabaseClientType clientType)
        {
            ValidateConnectionString(connectionString);
            ValidateSupportFileExists(schemaFilePathName);
            ValidateSupportDirectoryExists(datasetFilePathName);

            _database = GetDatabase(connectionString, clientType);

            _database.ReadXmlSchema(schemaFilePathName);

            using (DataSet ds = _database.GetDataSetFromDb())
            {
                ds.WriteXml(datasetFilePathName);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Loads the database with existing data.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="schemaFilePathName">Name of the schema file path.</param>
        /// <param name="datasetFilePathName">Name of the dataset file path.</param>
        /// <param name="clientType">Type of the client.</param>
        /// <remarks>Loads all data from the datasetFilePathName .XML file into all tables contained in the schemaFilePathName .XSD file.</remarks>
        protected virtual void LoadDatabase(string connectionString, string schemaFilePathName, string datasetFilePathName, DatabaseClientType clientType)
        {
            ValidateConnectionString(connectionString);
            ValidateSupportFileExists(schemaFilePathName);
            ValidateSupportFileExists(datasetFilePathName);

            _database = GetDatabase(connectionString, clientType);

            _database.ReadXmlSchema(schemaFilePathName);
            _database.ReadXml(datasetFilePathName);

            _database.PerformDbOperation(NDbUnit.Core.DbOperationFlag.CleanInsertIdentity);
        }
Esempio n. 4
0
 /// <summary>
 /// Resets the database.
 /// </summary>
 /// <param name="connectionString">The connection string.</param>
 /// <param name="clientType">Type of the database.</param>
 protected virtual void ResetDatabase(string connectionString, DatabaseClientType clientType)
 {
     _database = GetDatabase(connectionString, clientType);
     _database.PerformDbOperation(NDbUnit.Core.DbOperationFlag.Refresh);
 }
Esempio n. 5
0
        public void Setup(string databaseConnectionString, DatabaseClientType databaseType)
        {
            if (String.IsNullOrEmpty(databaseConnectionString))
            {
                throw new ArgumentException("databaseConnectionString is null or empty.", "databaseConnectionString");
            }

            _databaseConnectionString = databaseConnectionString;
            _databaseType             = databaseType;

            switch (_databaseType)
            {
            case DatabaseClientType.MySqlClient:
            {
                _databaseConnection = new MySql.Data.MySqlClient.MySqlConnection(_databaseConnectionString);
                _database           = new NDbUnit.Core.MySqlClient.MySqlDbUnitTest(_databaseConnectionString);
                break;
            }

            case DatabaseClientType.OleDBClient:
            {
                _databaseConnection = new System.Data.OleDb.OleDbConnection(_databaseConnectionString);
                _database           = new NDbUnit.Core.OleDb.OleDbUnitTest(_databaseConnectionString);
                break;
            }

            case DatabaseClientType.OracleClient:
            {
                _databaseConnection = new System.Data.OracleClient.OracleConnection(_databaseConnectionString);
                _database           = new NDbUnit.OracleClient.OracleClientDbUnitTest(_databaseConnectionString);
                break;
            }

            case DatabaseClientType.PostgresqlClient:
            {
                _databaseConnection = new Npgsql.NpgsqlConnection(_databaseConnectionString);
                _database           = new NDbUnit.Postgresql.PostgresqlDbUnitTest(_databaseConnectionString);
                break;
            }

            case DatabaseClientType.SqlCeClient:
            {
                _databaseConnection = new System.Data.SqlServerCe.SqlCeConnection(_databaseConnectionString);
                _database           = new NDbUnit.Core.SqlServerCe.SqlCeDbUnitTest(_databaseConnectionString);
                break;
            }

            case DatabaseClientType.SqlClient:
            {
                _databaseConnection = new System.Data.SqlClient.SqlConnection(_databaseConnectionString);
                _database           = new NDbUnit.Core.SqlClient.SqlDbUnitTest(_databaseConnectionString);
                break;
            }

            case DatabaseClientType.SqliteClient:
            {
                _databaseConnection = new System.Data.SQLite.SQLiteConnection(_databaseConnectionString);
                _database           = new NDbUnit.Core.SqlLite.SqlLiteDbUnitTest(_databaseConnectionString);
                break;
            }

            default:
                throw new InvalidOperationException("you have selected an invalid database type!");
            }
        }
        /// <summary>
        /// Gets the database.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="clientType">Type of the client.</param>
        /// <returns>NDbUnit database object to interact with the Database</returns>
        private NDbUnit.Core.INDbUnitTest GetDatabase(string connectionString, DatabaseClientType clientType)
        {
            switch (clientType)
            {
                case DatabaseClientType.SqlClient:
                    return DatabaseSpecificTypeFactory.CreateINDBUnitTest(NDBUNIT_SQLCLIENT_TYPE, NDBUNIT_SQLCLIENT_ASSEMBLY, connectionString);

                case DatabaseClientType.OleDBClient:
                    return DatabaseSpecificTypeFactory.CreateINDBUnitTest(NDBUNIT_OLEDB_TYPE, NDBUNIT_OLEDB_ASSEMBLY, connectionString);

                case DatabaseClientType.SqlCeClient:
                    return DatabaseSpecificTypeFactory.CreateINDBUnitTest(NDBUNIT_SQLCE_TYPE, NDBUNIT_SQLCE_ASSEMBLY, connectionString);

                case DatabaseClientType.SqliteClient:
                    return DatabaseSpecificTypeFactory.CreateINDBUnitTest(NDBUNIT_SQLLITE_TYPE, NDBUNIT_SQLLITE_ASSEMBLY, connectionString);

                case DatabaseClientType.MySqlClient:
                    return DatabaseSpecificTypeFactory.CreateINDBUnitTest(NDBUNIT_MYSQL_TYPE, NDBUNIT_MYSQL_ASSEMBLY, connectionString);

                case DatabaseClientType.OracleClient:
                    return DatabaseSpecificTypeFactory.CreateINDBUnitTest(NDBUNIT_ORACLE_TYPE, NDBUNIT_ORACLE_ASSEMBLY, connectionString);

                default:
                    throw new InvalidOperationException(string.Format("Unsupported DatabaseClientType: {0}", clientType.ToString()));
            }

        }
        /// <summary>
        /// Saves the existing database.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="schemaFilePathName">Name of the schema file path.</param>
        /// <param name="datasetFilePathName">Name of the dataset file path.</param>
        /// <param name="clientType">Type of the client.</param>
        protected virtual void SaveDatabase(string connectionString, string schemaFilePathName, string datasetFilePathName, DatabaseClientType clientType)
        {
            ValidateConnectionString(connectionString);
            ValidateSupportFileExists(schemaFilePathName);
            ValidateSupportDirectoryExists(datasetFilePathName);

            _database = GetDatabase(connectionString, clientType);

            _database.ReadXmlSchema(schemaFilePathName);

            using (DataSet ds = _database.GetDataSetFromDb())
            {
                ds.WriteXml(datasetFilePathName);
            }
        }
 /// <summary>
 /// Resets the database.
 /// </summary>
 /// <param name="connectionString">The connection string.</param>
 /// <param name="clientType">Type of the database.</param>
 protected virtual void ResetDatabase(string connectionString, DatabaseClientType clientType)
 {
     _database = GetDatabase(connectionString, clientType);
     _database.PerformDbOperation(NDbUnit.Core.DbOperationFlag.Refresh);
 }
        /// <summary>
        /// Loads the database with existing data.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="schemaFilePathName">Name of the schema file path.</param>
        /// <param name="datasetFilePathName">Name of the dataset file path.</param>
        /// <param name="clientType">Type of the client.</param>
        /// <remarks>Loads all data from the datasetFilePathName .XML file into all tables contained in the schemaFilePathName .XSD file.</remarks>
        protected virtual void LoadDatabase(string connectionString, string schemaFilePathName, string datasetFilePathName, DatabaseClientType clientType)
        {
            ValidateConnectionString(connectionString);
            ValidateSupportFileExists(schemaFilePathName);
            ValidateSupportFileExists(datasetFilePathName);

            _database = GetDatabase(connectionString, clientType);

            _database.ReadXmlSchema(schemaFilePathName);
            _database.ReadXml(datasetFilePathName);

            _database.PerformDbOperation(NDbUnit.Core.DbOperationFlag.CleanInsertIdentity);
        }