protected void CloseConnectionAndTransaction() { if (Transaction.Current != null) { CodeGenEtc.ConsoleMessage("[CODEGEN UNIT TEST] transaction [{0}] {1}", Transaction.Current.TransactionInformation.LocalIdentifier, _commitTransaction ? "commit" : "rollback"); } // close connection if (_connection != null) { _connection.Close(); _connection.Dispose(); _connection = null; } // close transaction if (_transaction != null) { if (_commitTransaction) { _transaction.Complete(); } _transaction.Dispose(); _transaction = null; } Assert.IsNull(_connection); Assert.IsNull(_transaction); }
public virtual void TearDown() { DateTime _finishTime = DateTime.Now; TimeSpan ts = _finishTime - _startTime; CodeGenEtc.ConsoleMessage("[CODEGEN UNIT TEST] time taken [{0}] secs", ts.TotalSeconds.ToString("0.00")); // re-enable nasties if (this.DisableCheckConstraints) { AlterCheckConstraints(true); } if (this.DisableTriggers) { AlterTriggers(true); } CloseConnectionAndTransaction(); }
public virtual void SetUp() { CloseConnectionAndTransaction(); _commitTransaction = false; TransactionOptions t = new TransactionOptions(); t.IsolationLevel = this.TransactionIsolationLevel; // new transaction _transaction = new TransactionScope(TransactionScopeOption.RequiresNew, t); CodeGenEtc.ConsoleMessage("[CODEGEN UNIT TEST] transaction [{0}] start", Transaction.Current.TransactionInformation.LocalIdentifier); // new connection CodeGenEtc.ConsoleMessage("[CODEGEN UNIT TEST] connection string [{0}]", this.ConnectionString); _connection = new SqlConnection(this.ConnectionString); _connection.Open(); // adjust the volume if (this.QuietMode) { CodeGenEtc.DebugSql = false; } else { CodeGenEtc.DebugSql = true; } // neutralise nasties if (this.DisableCheckConstraints) { AlterCheckConstraints(false); } if (this.DisableTriggers) { AlterTriggers(false); } _startTime = DateTime.Now; }