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; }
public CodeGenException(string message, Exception innerException, string sql, List <SqlParameter> parameters, RowBase obj) : base(message, innerException) { _sql = sql ?? ""; _rowBase = obj; _parameters = parameters; StringBuilder bob = new StringBuilder(); bob.Append(this.GetType().ToString()); bob.Append("\n"); bob.Append(message ?? ""); bob.Append("\n"); if (_rowBase != null) { bob.Append("object: "); bob.Append(_rowBase.GetType().ToString()); bob.Append("\n"); } if (_sql.Length > 0) { bob.Append("sql: "); bob.Append(_sql); bob.Append("\n"); } _myMessage = "\n" + bob.ToString().Trim() + "\n"; CodeGenEtc.DebugMessage("======================================================================================"); CodeGenEtc.DebugMessage("CODEGEN EXCEPTION"); CodeGenEtc.DebugMessage(_myMessage.Trim()); CodeGenEtc.DebugMessage("--------------------------------------------------------------------------------------"); if (innerException != null) { CodeGenEtc.DebugMessage(innerException.ToString()); } CodeGenEtc.DebugMessage("======================================================================================"); CodeGenEtc.DebugMessage("======================================================================================\n"); }