public void GetConnection_ShouldGetDifferentConnectionOnDifferentThreads() { using (TransactionScope scope = new TransactionScope()) { DatabaseConnectionWrapper connection = TransactionScopeConnections.GetConnection(db); ThreadTests tests = new ThreadTests(); Thread thread = new Thread(tests.GetTransactionScopeConnection); thread.Start(); thread.Join(); Assert.AreNotSame(connection, tests.Connection); } }
public void GetConnection_ShouldGetSameConnectionWhenOtherThreadUsesSameTransaction() { using (TransactionScope scope = new TransactionScope()) { DatabaseConnectionWrapper connection = TransactionScopeConnections.GetConnection(db); ThreadTests tests = new ThreadTests(); Thread thread = new Thread(tests.GetConnection); thread.Start(Transaction.Current); thread.Join(); Assert.AreSame(connection, tests.Connection); Assert.AreEqual(ConnectionState.Open, tests.Connection.Connection.State); } }
public void Current_ShouldBeDifferentTransactionInOtherThread() { using (TransactionScope scope = new TransactionScope()) { ThreadTests tests = new ThreadTests(); Thread thread = new Thread(tests.GetTransactionScopeConnection); thread.Start(); thread.Join(); Assert.IsNotNull(tests.Current); Assert.IsNotNull(Transaction.Current); Assert.AreNotSame(tests.Current, Transaction.Current); } }