public void TransactionInsertLoadWithRollBackTask() { object savedId; using (var txscope = new TransactionScope()) { using (ISession s = sessions.OpenSession()) { var person = new Person {CreatedAt = DateTime.Now}; savedId = s.Save(person); } txscope.Complete(); } try { using (var txscope = new TransactionScope()) { using (ISession s = sessions.OpenSession()) { var person = s.Get<Person>(savedId); person.CreatedAt = DateTime.Now; s.Update(person); } new ForceEscalationToDistributedTx(true); log.Debug("completing the tx scope"); txscope.Complete(); } log.Debug("Transaction fail."); Assert.Fail("Expected tx abort"); } catch (TransactionAbortedException) { log.Debug("Transaction aborted."); } finally { using (var txscope = new TransactionScope()) { using (ISession s = sessions.OpenSession()) { var person = s.Get<Person>(savedId); s.Delete(person); } txscope.Complete(); } } }
public void RollbackOutsideNh() { try { using (var txscope = new TransactionScope()) { using (ISession s = sessions.OpenSession()) { var person = new Person { CreatedAt = DateTime.Now }; s.Save(person); } new ForceEscalationToDistributedTx(true); //will rollback tx txscope.Complete(); } log.DebugFormat("Transaction fail."); Assert.Fail("Expected tx abort"); } catch (TransactionAbortedException) { log.DebugFormat("Transaction aborted."); } }
public void TransactionInsertWithRollBackTask() { if (Dialect is FirebirdDialect) Assert.Ignore("Firebird driver does not support distributed transactions"); try { using (var txscope = new TransactionScope()) { using (ISession s = sessions.OpenSession()) { var person = new Person {CreatedAt = DateTime.Now}; s.Save(person); new ForceEscalationToDistributedTx(true); //will rollback tx person.CreatedAt = DateTime.Now; s.Update(person); } txscope.Complete(); } log.DebugFormat("Transaction fail."); Assert.Fail("Expected tx abort"); } catch (TransactionAbortedException) { log.DebugFormat("Transaction aborted."); } }