Exemplo n.º 1
0
 public void EnlistScope_throws_ArgumentNullException_when_scope_parameter_is_null()
 {
     using (var transaction = new TransactionScope())
     {
         var uowTx = new UnitOfWorkTransaction(MockRepository.GenerateStub <IUnitOfWork>(), transaction);
         Assert.Throws <ArgumentNullException>(() => uowTx.EnlistScope(null));
     }
 }
Exemplo n.º 2
0
        public void disposing_transaction_raises_TransactionDisposing_event()
        {
            var disposed = false;

            using (var tx = new UnitOfWorkTransaction(MockRepository.GenerateStub <IUnitOfWork>(), new TransactionScope()))
            {
                tx.TransactionDisposing += (x) => disposed = true;
            }
            Assert.That(disposed);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles a Dispose signal from a transaction.
        /// </summary>
        /// <param name="transaction"></param>
        void OnTransactionDisposing(UnitOfWorkTransaction transaction)
        {
            _logger.Info(x => x("UnitOfWorkTransaction {0} signalled a disposed. Unregistering transaction from TransactionManager {1}",
                                transaction.TransactionId, _transactionManagerId));

            transaction.TransactionDisposing -= OnTransactionDisposing;
            var node = _transactions.Find(transaction);

            if (node != null)
            {
                _transactions.Remove(node);
            }
        }
Exemplo n.º 4
0
        public void when_scope_is_comitting_unit_of_work_and_transaction_is_comitted()
        {
            using (var tx = new TransactionScope())
            {
                Assert.That(Transaction.Current, Is.Not.Null);
                Assert.That(Transaction.Current.TransactionInformation.Status, Is.EqualTo(TransactionStatus.Active));

                var uow      = MockRepository.GenerateMock <IUnitOfWork>();
                var uowScope = MockRepository.GenerateStub <IUnitOfWorkScope>();
                var uowTx    = new UnitOfWorkTransaction(uow, tx);
                uowTx.EnlistScope(uowScope);
                uowScope.Raise(x => x.ScopeComitting += null, uowScope);

                uow.AssertWasCalled(x => x.Flush());
                Assert.That(Transaction.Current, Is.Null);
            }
        }
Exemplo n.º 5
0
        public void when_scope_is_rolledback_unit_of_work_and_transaction_is_disposed_even_when_other_scopes_are_attached()
        {
            using (var tx = new TransactionScope())
            {
                Assert.That(Transaction.Current, Is.Not.Null);
                Assert.That(Transaction.Current.TransactionInformation.Status, Is.EqualTo(TransactionStatus.Active));

                var uow       = MockRepository.GenerateMock <IUnitOfWork>();
                var uowScope1 = MockRepository.GenerateStub <IUnitOfWorkScope>();
                var uowScope2 = MockRepository.GenerateStub <IUnitOfWorkScope>();
                var uowTx     = new UnitOfWorkTransaction(uow, tx);
                uowTx.EnlistScope(uowScope1);
                uowTx.EnlistScope(uowScope2);
                uowScope1.Raise(x => x.ScopeRollingback += null, uowScope2);

                uow.AssertWasNotCalled(x => x.Flush());
                uow.AssertWasCalled(x => x.Dispose());
                Assert.That(Transaction.Current, Is.Null);
            }
        }