Exemple #1
0
        public void CommitAndRollbackOnScope()
        {
            ClientTransaction transaction = ClientTransaction.CreateRootTransaction();
            var eventCounter = new TransactionEventCounter(transaction);

            using (ClientTransactionScope scope = transaction.EnterNonDiscardingScope())
            {
                Assert.That(eventCounter.Commits, Is.EqualTo(0));
                Assert.That(eventCounter.Rollbacks, Is.EqualTo(0));

                scope.Commit();

                Assert.That(eventCounter.Commits, Is.EqualTo(1));
                Assert.That(eventCounter.Rollbacks, Is.EqualTo(0));

                scope.Rollback();

                Assert.That(eventCounter.Commits, Is.EqualTo(1));
                Assert.That(eventCounter.Rollbacks, Is.EqualTo(1));

                transaction.Commit();

                Assert.That(eventCounter.Commits, Is.EqualTo(2));
                Assert.That(eventCounter.Rollbacks, Is.EqualTo(1));

                transaction.Rollback();

                Assert.That(eventCounter.Commits, Is.EqualTo(2));
                Assert.That(eventCounter.Rollbacks, Is.EqualTo(2));
            }
        }
Exemple #2
0
        public void NoAutoRollbackWhenNoneBehavior()
        {
            var mock         = new TestableClientTransaction();
            var eventCounter = new TransactionEventCounter(mock);

            using (mock.EnterScope(AutoRollbackBehavior.None))
            {
                Order order = new DomainObjectIDs(MappingConfiguration.Current).Order1.GetObject <Order> ();
                order.OrderNumber = 0xbadf00d;
                order.OrderTicket = OrderTicket.NewObject();
                order.OrderItems.Add(OrderItem.NewObject());
            }

            Assert.That(eventCounter.Rollbacks, Is.EqualTo(0));

            using (mock.EnterScope(AutoRollbackBehavior.None))
            {
            }

            Assert.That(eventCounter.Rollbacks, Is.EqualTo(0));

            using (ClientTransactionScope scope = mock.EnterScope(AutoRollbackBehavior.None))
            {
                Order order = new DomainObjectIDs(MappingConfiguration.Current).Order1.GetObject <Order> ();
                order.OrderNumber = 0xbadf00d;

                scope.ScopedTransaction.Rollback();
            }

            Assert.That(eventCounter.Rollbacks, Is.EqualTo(1));
        }