示例#1
0
 public virtual void Dispose()
 {
     _throwawayDatabase.Dispose();
 }
示例#2
0
        public void BaseTearDown()
        {
            if (UseThrowawayDb)
            {
                if (_connection != null)
                {
                    _connection.Close();
                    _connection.Dispose();
                }
                if (_throwaway != null)
                {
                    _throwaway.Dispose();
                    _throwaway = null;
                }
            }
            else
            {
                _connection.Close();
                _connection.Dispose();

                _connectionStringBuilder.InitialCatalog = _dbOpsDb;
                _connectionString = _connectionStringBuilder.ToString();
                _connection       = new SqlConnection(_connectionString);
                _connection.Execute($"alter database [{_databaseName}] set single_user with rollback immediate");

                if (_configuration.Test.OnPersistenceTestCompletion == TestConfiguration.PersistenceTestCompletionAction.DropOnComplete)
                {
                    Drop(_connection, _databaseName);
                }
                else if (_configuration.Test.OnPersistenceTestCompletion == TestConfiguration.PersistenceTestCompletionAction.RenameOnComplete)
                {
                    _databaseName = RenameWithRunTime(_connection, _databaseName, _runTime);
                }
                else if (_configuration.Test.OnPersistenceTestCompletion == TestConfiguration.PersistenceTestCompletionAction.DropIfSuccessRenameIfFailures)
                {
                    if (NUnit.Framework.TestContext.CurrentContext.Result.Outcome == NUnit.Framework.Interfaces.ResultState.Failure)
                    {
                        _databaseName = RenameWithRunTime(_connection, _databaseName, _runTime);
                    }
                    else
                    {
                        Drop(_connection, _databaseName);
                    }
                }
                else if (_configuration.Test.OnPersistenceTestCompletion == TestConfiguration.PersistenceTestCompletionAction.DropIfSuccess)
                {
                    if (NUnit.Framework.TestContext.CurrentContext.Result.Outcome == NUnit.Framework.Interfaces.ResultState.Success)
                    {
                        Drop(_connection, _databaseName);
                    }
                }
                else
                {
                    throw new InvalidOperationException("Unknown PersistenceTestCompletionAction");
                }

                _connection.Close();
                _connection.Dispose();
            }


            _databaseName     = "";
            _connectionString = "";
            _connection       = null;
        }