public void ExecuteNonQuery_Transaction_Test() { using (var cmd = new DatabaseCommand(_connection)) { cmd.Log = Console.WriteLine; cmd.CommandText.AppendLine(" DELETE FROM EMP "); cmd.TransactionBegin(); cmd.ExecuteNonQuery(); cmd.TransactionRollback(); Assert.AreEqual(EMP.GetEmployeesCount(_connection), 14); } }
public async Task ExecuteNonQueryAsync_Transaction_Test() { using (var cmd = new DatabaseCommand(_connection)) { cmd.Log = Console.WriteLine; cmd.CommandText.AppendLine(" DELETE FROM EMP "); cmd.TransactionBegin(); int count = await cmd.ExecuteNonQueryAsync(); cmd.TransactionRollback(); Assert.AreEqual(14, count); Assert.AreEqual(14, EMP.GetEmployeesCount(_connection)); } }
public void Transaction_TwoBeginTransaction_Test() { // Main Transaction using (var cmd1 = new DatabaseCommand(_connection)) { cmd1.Log = Console.WriteLine; var trans1 = cmd1.TransactionBegin(); // Second Transaction using (var cmd2 = new DatabaseCommand(trans1)) { // Raise an exception var trans2 = cmd2.TransactionBegin(); } cmd1.TransactionRollback(); } }
public void ExecuteNonQuery_TransactionForTwoIncludedCommands_Test() { using (var cmd1 = new DatabaseCommand(_connection)) { cmd1.Log = Console.WriteLine; cmd1.CommandText.AppendLine(" DELETE FROM EMP "); cmd1.TransactionBegin(); cmd1.ExecuteNonQuery(); using (var cmd2 = new DatabaseCommand(cmd1.Transaction)) { cmd2.CommandText.AppendLine(" SELECT COUNT(*) FROM EMP "); int count = cmd2.ExecuteScalar <int>(); } cmd1.TransactionRollback(); } }
public void ExecuteNonQuery_TransactionForTwoCommands_Test() { DbTransaction currentTransaction; using (var cmd = new DatabaseCommand(_connection)) { cmd.Log = Console.WriteLine; cmd.CommandText.AppendLine(" DELETE FROM EMP "); currentTransaction = cmd.TransactionBegin(); cmd.ExecuteNonQuery(); Assert.AreEqual(EMP.GetEmployeesCount(currentTransaction), 0); // Inside the transaction cmd.TransactionRollback(); Assert.AreEqual(EMP.GetEmployeesCount(_connection), 14); // Ouside the transaction } }
public void Transaction_GetInternalTransaction_Test() { using (var cmd = new DatabaseCommand(_connection)) { cmd.Log = Console.WriteLine; cmd.CommandText.AppendLine(" DELETE FROM EMP "); var trans1 = DataExtensions.GetTransaction(_connection); var trans2A = cmd.TransactionBegin(); var trans2B = DataExtensions.GetTransaction(_connection); cmd.ExecuteNonQuery(); cmd.TransactionRollback(); var trans3 = DataExtensions.GetTransaction(_connection); Assert.AreEqual(EMP.GetEmployeesCount(_connection), 14); Assert.AreEqual(null, trans1); Assert.AreEqual(trans2A, trans2B); Assert.AreEqual(null, trans3); } }