Exemple #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));
     }
 }
Exemple #2
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);
            }
        }
Exemple #3
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);
            }
        }