public void CurrentTransaction_returns_null_when_scope_is_rolledback() { var uowFactory = MockRepository.GenerateStub<IUnitOfWorkFactory>(); var locator = MockRepository.GenerateStub<IServiceLocator>(); uowFactory.Stub(x => x.Create()) .Do((Func<IUnitOfWork>)(() => MockRepository.GenerateStub<IUnitOfWork>())); locator.Stub(x => x.GetInstance<IUnitOfWorkFactory>()).Return(uowFactory); ServiceLocator.SetLocatorProvider(() => locator); using (var txManager = new TransactionManager()) { var scope = MockRepository.GenerateStub<IUnitOfWorkScope>(); txManager.EnlistScope(scope, TransactionMode.Default); Assert.That(txManager.CurrentUnitOfWork, Is.Not.Null); Assert.That(txManager.CurrentTransaction, Is.Not.Null); scope.Raise(x => x.ScopeRollingback += null, scope); Assert.That(txManager.CurrentTransaction, Is.Null); Assert.That(txManager.CurrentUnitOfWork, Is.Null); } }
public void new_transaction_is_not_started_when_second_scope_is_enlisted() { var uowFactory = MockRepository.GenerateStub<IUnitOfWorkFactory>(); var locator = MockRepository.GenerateStub<IServiceLocator>(); uowFactory.Stub(x => x.Create()) .Do((Func<IUnitOfWork>)(() => MockRepository.GenerateStub<IUnitOfWork>())); locator.Stub(x => x.GetInstance<IUnitOfWorkFactory>()).Return(uowFactory); ServiceLocator.SetLocatorProvider(() => locator); using (var txManager = new TransactionManager()) { txManager.EnlistScope(MockRepository.GenerateStub<IUnitOfWorkScope>(), TransactionMode.Default); var currentUOW = txManager.CurrentUnitOfWork; var currentTx = txManager.CurrentTransaction; txManager.EnlistScope(MockRepository.GenerateStub<IUnitOfWorkScope>(), TransactionMode.Default); Assert.That(currentUOW, Is.SameAs(txManager.CurrentUnitOfWork)); Assert.That(currentTx, Is.SameAs(txManager.CurrentTransaction)); } }