Beispiel #1
0
        public void IUnDoTransactionDispose_Should_throw_When_not_the_latest_transaction()
        {
            IUnDoManager manager = new UnDoManager(1);

            IUnDoTransaction transaction1 = manager.BeginTransaction();
            IUnDoTransaction transaction2 = manager.BeginTransaction();

            Check.ThatCode(transaction1.Dispose).Throws <InvalidOperationException>();
        }
Beispiel #2
0
        public void IUnDoTransactionCommit_Should_throw_When_already_disposed()
        {
            IUnDoManager manager = new UnDoManager(1);

            IUnDoTransaction transaction = manager.BeginTransaction();

            transaction.Dispose();

            Check.ThatCode(transaction.Commit).Throws <ObjectDisposedException>();
        }
Beispiel #3
0
        public void IUnDoTransactionCommit_Should_throw_When_already_committed()
        {
            IUnDoManager manager = new UnDoManager(1);

            IUnDoTransaction transaction = manager.BeginTransaction();

            transaction.Commit();

            Check.ThatCode(transaction.Commit).Throws <InvalidOperationException>();
        }
Beispiel #4
0
        void ISet <T> .UnionWith(IEnumerable <T> other)
        {
            using IUnDoTransaction transaction = _manager.BeginTransaction(_descriptionFactory?.Invoke(new UnDoCollectionOperation(this, UnDoCollectionAction.ISetUnionWith, other)));

            foreach (T item in other)
            {
                _manager.DoAdd(_source, item);
            }

            transaction.Commit();
        }
Beispiel #5
0
        public void IUnDoTransactionDispose_Should_undo_When_not_committed()
        {
            IUnDoManager manager = new UnDoManager(1);

            bool unDone = false;

            using (IUnDoTransaction transaction = manager.BeginTransaction())
            {
                IUnDo undo = Substitute.For <IUnDo>();
                undo.When(u => u.Undo()).Do(_ => unDone = true);

                manager.Do(undo);
            }

            Check.That(unDone).IsTrue();
        }
Beispiel #6
0
        void ISet <T> .IntersectWith(IEnumerable <T> other)
        {
            if (_source.Count > 0)
            {
                List <T> items = other.Where(_source.Contains).ToList();

                using IUnDoTransaction transaction = _manager.BeginTransaction(_descriptionFactory?.Invoke(new UnDoCollectionOperation(this, UnDoCollectionAction.ISetIntersectWith, other)));

                _manager.DoClear(_source);
                foreach (T item in items)
                {
                    _manager.DoAdd(_source, item);
                }

                transaction.Commit();
            }
        }
Beispiel #7
0
        public void Move(int oldIndex, int newIndex)
        {
            if (_source is ObservableCollection <T> collection)
            {
                _manager.Do(
                    () => collection.Move(oldIndex, newIndex),
                    () => collection.Move(newIndex, oldIndex),
                    _descriptionFactory?.Invoke(new UnDoCollectionOperation(this, UnDoCollectionAction.IListMove, oldIndex, newIndex)));
            }
            else
            {
                using IUnDoTransaction transaction = _manager.BeginTransaction(_descriptionFactory?.Invoke(new UnDoCollectionOperation(this, UnDoCollectionAction.IListMove, oldIndex, newIndex)));

                T         item = _source[oldIndex];
                IList <T> list = this;
                list.RemoveAt(oldIndex);
                list.Insert(newIndex, item);

                transaction.Commit();
            }
        }
Beispiel #8
0
        public void BeginTransaction_Should_add_commands_as_one_operation_in_history_once_disposed(IUnDoManager manager)
        {
            IUnDo undo = Substitute.For <IUnDo>();

            undo.Description.Returns("dummy");
            int version = manager.Version;

            using (IUnDoTransaction t1 = manager.BeginTransaction("first"))
                using (IUnDoTransaction t2 = manager.BeginTransaction("second"))
                {
                    manager.Do(undo);
                    manager.Do(undo);

                    t2.Commit();
                    t1.Commit();
                }

            Check.That(manager.Version).IsStrictlyGreaterThan(version);
            Check.That(manager.UndoDescriptions).ContainsExactly("first");

            manager.Undo();

            Check.That(manager.Version).IsEqualTo(version);
        }
Beispiel #9
0
        public void Clear_Should_throw_When_a_transaction_is_going_on(IUnDoManager manager)
        {
            IUnDoTransaction transaction = manager.BeginTransaction();

            Check.ThatCode(manager.Clear).Throws <InvalidOperationException>();
        }