From: <fab...@us...> - 2009-05-13 23:14:27
|
Revision: 4296 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4296&view=rev Author: fabiomaulo Date: 2009-05-13 23:14:26 +0000 (Wed, 13 May 2009) Log Message: ----------- Cleaned Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs 2009-05-13 23:07:09 UTC (rev 4295) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs 2009-05-13 23:14:26 UTC (rev 4296) @@ -1,156 +1,141 @@ using System; -using System.Collections.Generic; -using System.Data; -using System.Data.SqlClient; +using System.Collections; using System.Threading; using System.Transactions; -using NHibernate.Criterion; -using NHibernate.Dialect; -using NHibernate.Exceptions; -using NHibernate.Impl; using NUnit.Framework; namespace NHibernate.Test.NHSpecificTest.DtcFailures { - using System.Collections; + [TestFixture] + public class DtcFailuresFixture : TestCase + { + protected override IList Mappings + { + get { return new string[] {"NHSpecificTest.DtcFailures.Mappings.hbm.xml"}; } + } - [TestFixture] - public class DtcFailuresFixture : TestCase - { + protected override string MappingsAssembly + { + get { return "NHibernate.Test"; } + } - protected override IList Mappings - { - get { return new string[] { "NHSpecificTest.DtcFailures.Mappings.hbm.xml" }; } - } + [Test] + public void WillNotCrashOnDtcPrepareFailure() + { + var tx = new TransactionScope(); + using (ISession s = sessions.OpenSession()) + { + s.Save(new Person {CreatedAt = DateTime.MinValue // will cause SQL date failure + }); + } - protected override string MappingsAssembly - { - get { return "NHibernate.Test"; } - } + new ForceEscalationToDistributedTx(); - [Test] - public void WillNotCrashOnDtcPrepareFailure() - { - var tx = new TransactionScope(); - using (var s = sessions.OpenSession()) - { - s.Save(new Person - { - CreatedAt = DateTime.MinValue // will cause SQL date failure - }); - } + tx.Complete(); + try + { + tx.Dispose(); + Assert.Fail("Expected failure"); + } + catch (AssertionException) + { + throw; + } + catch (Exception) {} + } - new ForceEscalationToDistributedTx(); + [Test] + public void Can_roll_back_transaction() + { + var tx = new TransactionScope(); + using (ISession s = sessions.OpenSession()) + { + new ForceEscalationToDistributedTx(true); //will rollback tx + s.Save(new Person {CreatedAt = DateTime.Today}); - tx.Complete(); - try - { - tx.Dispose(); - Assert.Fail("Expected failure"); - } - catch (AssertionException) - { - throw; - } - catch (Exception) - { - } - } + tx.Complete(); + } + try + { + tx.Dispose(); + Assert.Fail("Expected tx abort"); + } + catch (TransactionAbortedException) + { + //expected + } + } - [Test] - public void Can_roll_back_transaction() - { - var tx = new TransactionScope(); - using (var s = sessions.OpenSession()) - { - new ForceEscalationToDistributedTx(true);//will rollback tx - s.Save(new Person - { - CreatedAt = DateTime.Today - }); + [Test] + public void CanDeleteItemInDtc() + { + object id; + using (var tx = new TransactionScope()) + { + using (ISession s = sessions.OpenSession()) + { + id = s.Save(new Person {CreatedAt = DateTime.Today}); - tx.Complete(); - } - try - { - tx.Dispose(); - Assert.Fail("Expected tx abort"); - } - catch (TransactionAbortedException) - { - //expected - } - } + new ForceEscalationToDistributedTx(); - [Test] - public void CanDeleteItemInDtc() - { - object id; - using (var tx = new TransactionScope()) - using (var s = sessions.OpenSession()) - { - id = s.Save(new Person - { - CreatedAt = DateTime.Today - }); + tx.Complete(); + } + } - new ForceEscalationToDistributedTx(); - - tx.Complete(); - } + using (var tx = new TransactionScope()) + { + using (ISession s = sessions.OpenSession()) + { + new ForceEscalationToDistributedTx(); - using (var tx = new TransactionScope()) - using (var s = sessions.OpenSession()) - { - new ForceEscalationToDistributedTx(); - - s.Delete(s.Get<Person>(id)); + s.Delete(s.Get<Person>(id)); - tx.Complete(); - } + tx.Complete(); + } + } + } - } + public class ForceEscalationToDistributedTx : IEnlistmentNotification + { + private readonly bool shouldRollBack; + private readonly int thread; - public class ForceEscalationToDistributedTx : IEnlistmentNotification - { - private readonly bool shouldRollBack; - private readonly int thread; + public ForceEscalationToDistributedTx(bool shouldRollBack) + { + this.shouldRollBack = shouldRollBack; + thread = Thread.CurrentThread.ManagedThreadId; + System.Transactions.Transaction.Current.EnlistDurable(Guid.NewGuid(), this, EnlistmentOptions.None); + } - public ForceEscalationToDistributedTx(bool shouldRollBack) - { - this.shouldRollBack = shouldRollBack; - thread = Thread.CurrentThread.ManagedThreadId; - System.Transactions.Transaction.Current.EnlistDurable(Guid.NewGuid(), this, EnlistmentOptions.None); - } + public ForceEscalationToDistributedTx() : this(false) {} - public ForceEscalationToDistributedTx():this(false) - { - - } + public void Prepare(PreparingEnlistment preparingEnlistment) + { + Assert.AreNotEqual(thread, Thread.CurrentThread.ManagedThreadId); + if (shouldRollBack) + { + preparingEnlistment.ForceRollback(); + } + else + { + preparingEnlistment.Prepared(); + } + } - public void Prepare(PreparingEnlistment preparingEnlistment) - { - Assert.AreNotEqual(thread, Thread.CurrentThread.ManagedThreadId); - if (shouldRollBack) - preparingEnlistment.ForceRollback(); - else - preparingEnlistment.Prepared(); - } + public void Commit(Enlistment enlistment) + { + enlistment.Done(); + } - public void Commit(Enlistment enlistment) - { - enlistment.Done(); - } + public void Rollback(Enlistment enlistment) + { + enlistment.Done(); + } - public void Rollback(Enlistment enlistment) - { - enlistment.Done(); - } - - public void InDoubt(Enlistment enlistment) - { - enlistment.Done(); - } - } - } -} + public void InDoubt(Enlistment enlistment) + { + enlistment.Done(); + } + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |