Esempio n. 1
0
        public void Do_Should_override_oldest_operation_When_max_capacity()
        {
            IUnDoManager manager = new UnDoManager(2);

            IUnDo operation1 = Substitute.For <IUnDo>();
            IUnDo operation2 = Substitute.For <IUnDo>();
            IUnDo operation3 = Substitute.For <IUnDo>();

            operation1.Description.Returns("un");
            operation2.Description.Returns("dos");
            operation3.Description.Returns("tres");

            manager.Do(operation1);
            manager.Do(operation2);
            manager.Do(operation3);

            Check.That(manager.UndoDescriptions).ContainsExactly("tres", "dos");

            manager.Undo();
            manager.Undo();

            Check.That(manager.RedoDescriptions).ContainsExactly("dos", "tres");

            manager.Redo();
            manager.Redo();

            Check.That(manager.UndoDescriptions).ContainsExactly("tres", "dos");
        }
Esempio n. 2
0
        public void Move_Should_move_item_as_UnDo_operation_When_UnDoList()
        {
            IUnDoManager manager = new UnDoManager();

            IList <int> items = new List <int> {
                1, 2
            }.AsUnDo(manager);

            items.Move(0, 1);

            Check.That(items).ContainsExactly(2, 1);

            manager.Undo();

            Check.That(items).ContainsExactly(1, 2);

            items = new ObservableCollection <int> {
                1, 2
            }.AsUnDo(manager);

            items.Move(0, 1);

            Check.That(items).ContainsExactly(2, 1);

            manager.Undo();

            Check.That(items).ContainsExactly(1, 2);
        }
Esempio n. 3
0
        public void DoRemove_ICollection_Should_keep_index_When_source_is_IList()
        {
            IUnDoManager      manager = new UnDoManager();
            ICollection <int> source  = new List <int> {
                0, 1
            };

            manager.DoRemove(source, 0);

            manager.Undo();

            Check.That(source).ContainsExactly(0, 1);
        }
Esempio n. 4
0
        public void UnDoSet_ExceptWith_Should_work()
        {
            IUnDoManager manager = new UnDoManager();
            ISet <int>   unDoSet = new HashSet <int> {
                1, 2, 3
            }.AsUnDo(manager);

            unDoSet.ExceptWith(new[] { 2 });

            Check.That(unDoSet.OrderBy(i => i)).ContainsExactly(1, 3);

            manager.Undo();

            Check.That(unDoSet.OrderBy(i => i)).ContainsExactly(1, 2, 3);
        }
Esempio n. 5
0
        public void DoAdd_ICollection_Should_keep_index_When_source_is_IList()
        {
            IUnDoManager      manager = new UnDoManager();
            ICollection <int> source  = new List <int> {
                0, 1
            };

            manager.DoAdd(source, 2);

            source.Add(3);

            manager.Undo();

            Check.That(source).ContainsExactly(0, 1, 3);

            manager.Redo();

            Check.That(source).ContainsExactly(0, 1, 2, 3);
        }
Esempio n. 6
0
        public void Do_Should_operation_When_max_capacity_is_one()
        {
            IUnDoManager manager = new UnDoManager(1);

            IUnDo operation1 = Substitute.For <IUnDo>();
            IUnDo operation2 = Substitute.For <IUnDo>();

            operation1.Description.Returns("kikoo");
            operation2.Description.Returns("lol");

            manager.Do(operation1);
            manager.Do(operation2);

            Check.That(manager.UndoDescriptions).ContainsExactly("lol");
            Check.That(manager.RedoDescriptions).IsEmpty();

            manager.Undo();

            Check.That(manager.UndoDescriptions).IsEmpty();
            Check.That(manager.RedoDescriptions).ContainsExactly("lol");
        }