Ejemplo n.º 1
0
 public void CurrentUnitOfWork_returns_null_with_no_enlisted_scope()
 {
     using (var txManager = new TransactionManager())
     {
         Assert.That(txManager.CurrentUnitOfWork, Is.Null);
     }
 }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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));
            }
        }