Exemplo n.º 1
0
 void undo_Click(object sender, RoutedEventArgs e)
 {
     // Cancel the changes made by this control
     // by rolling _transaction back.
     _transaction.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(transaction_PropertyChanged);
     _transaction.Rollback();
     // Create a new transaction.
     CreateTransaction();
 }
Exemplo n.º 2
0
 public void SubTransactionCanContinueToBeUsedAfterRollback()
 {
     _subTransaction.Rollback();
     Assert.That(_subTransaction.IsDiscarded, Is.False);
     using (_subTransaction.EnterDiscardingScope())
     {
         Order order = Order.NewObject();
         Assert.That(order, Is.Not.Null);
     }
 }
Exemplo n.º 3
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));
            }
        }
Exemplo n.º 4
0
        public void TransactionMethodsCanBeOverridden()
        {
            using (MixinConfiguration.BuildFromActive().ForClass(typeof(ClientTransaction)).Clear().AddMixins(typeof(InvertingClientTransactionMixin)).EnterScope())
            {
                ClientTransaction invertedTransaction = ClientTransaction.CreateRootTransaction();

                bool committed  = false;
                bool rolledBack = false;
                invertedTransaction.Committed  += delegate { committed = true; };
                invertedTransaction.RolledBack += delegate { rolledBack = true; };

                Assert.That(rolledBack, Is.False);
                Assert.That(committed, Is.False);

                invertedTransaction.Commit();

                Assert.That(rolledBack, Is.True);
                Assert.That(committed, Is.False);

                rolledBack = false;
                invertedTransaction.Rollback();

                Assert.That(rolledBack, Is.False);
                Assert.That(committed, Is.True);
            }
        }
 void CancelAllChanges(object sender, RoutedEventArgs e)
 {
     // Cancel all changes made in this application by rolling back the global transaction.
     if (_transaction.State == TransactionState.Open)
     {
         _transaction.Rollback();
         _transactionScope.Dispose();
     }
     // Open a new transaction.
     _transaction      = _cache.CreateTransaction();
     _transactionScope = _transaction.Scope();
 }
Exemplo n.º 6
0
        public void GetState_Invalidated_AfterRollback()
        {
            _transaction.ExecuteInScope(() => _existingOrder.OrderNumber++);

            var stateBeforeChange = _cachingListener.GetState(_existingOrder.ID);

            _transaction.Rollback();
            var stateAfterChange = _cachingListener.GetState(_existingOrder.ID);

            Assert.That(stateBeforeChange, Is.EqualTo(StateType.Changed));
            Assert.That(stateAfterChange, Is.EqualTo(StateType.Unchanged));
        }
        private void buttonClose_Click(object sender, EventArgs e)
        {
            if (_transaction.HasChanges)
            {
                // Ask the user whether they will save or cancel the changes made by this control.
                switch (MessageBox.Show("Do you want to save changes?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
                {
                case DialogResult.Yes:
                    _transaction.Commit();
                    break;

                case DialogResult.No:
                    _transaction.Rollback();
                    break;

                case DialogResult.Cancel:
                    return;
                }
            }
            // Raise the CloseRequested event, so MainForm removes the tab page containing this control.
            CloseRequested(this, EventArgs.Empty);
        }
Exemplo n.º 8
0
 /// <summary> Rolls the transaction back. </summary>
 public virtual void Rollback()
 {
     _wrappedInstance.Rollback();
 }