Exemplo n.º 1
0
        public void AddWithHistory_Adds_Items_As_Last()
        {
            var history = new StackHistory();
            var target  = new ObservableCollection <Item>();
            var item0   = new Item("item0");
            var item1   = new Item("item1");
            var item2   = new Item("item2");

            target.AddWithHistory(item0, history);
            target.AddWithHistory(item1, history);
            target.AddWithHistory(item2, history);
            Assert.Equal(3, target.Count);
            Assert.Equal(item0, target[0]);
            Assert.Equal(item1, target[1]);
            Assert.Equal(item2, target[2]);

            history.Undo();
            Assert.Equal(2, target.Count);
            Assert.Equal(item0, target[0]);
            Assert.Equal(item1, target[1]);

            history.Undo();
            Assert.Single(target);
            Assert.Equal(item0, target[0]);

            history.Undo();
            Assert.Empty(target);

            history.Redo();
            Assert.Single(target);
            Assert.Equal(item0, target[0]);

            history.Redo();
            Assert.Equal(2, target.Count);
            Assert.Equal(item0, target[0]);
            Assert.Equal(item1, target[1]);

            history.Redo();
            Assert.Equal(3, target.Count);
            Assert.Equal(item0, target[0]);
            Assert.Equal(item1, target[1]);
            Assert.Equal(item2, target[2]);
        }
Exemplo n.º 2
0
        public void InsertWithHistory_Inserts_Items_List_Middle()
        {
            var history = new StackHistory();
            var target  = new ObservableCollection <Item>();
            var item0   = new Item("item0");
            var item1   = new Item("item1");
            var item2   = new Item("item2");

            target.InsertWithHistory(0, item0, history);
            target.InsertWithHistory(1, item1, history);
            target.InsertWithHistory(1, item2, history);
            Assert.Equal(3, target.Count);
            Assert.Equal(item0, target[0]);
            Assert.Equal(item2, target[1]);
            Assert.Equal(item1, target[2]);

            history.Undo();
            Assert.Equal(2, target.Count);
            Assert.Equal(item0, target[0]);
            Assert.Equal(item1, target[1]);

            history.Undo();
            Assert.Single(target);
            Assert.Equal(item0, target[0]);

            history.Undo();
            Assert.Empty(target);

            history.Redo();
            Assert.Single(target);
            Assert.Equal(item0, target[0]);

            history.Redo();
            Assert.Equal(2, target.Count);
            Assert.Equal(item0, target[0]);
            Assert.Equal(item1, target[1]);

            history.Redo();
            Assert.Equal(3, target.Count);
            Assert.Equal(item0, target[0]);
            Assert.Equal(item2, target[1]);
            Assert.Equal(item1, target[2]);
        }
        public void Invoking_Redo_Should_Not_Throw_When_Redos_Are_Empty()
        {
            var target = new StackHistory();

            using (var helper = new HistoryHelper(target))
            {
                var result = target.Redo();
                Assert.False(result);
                Assert.Equal(new bool[] { }, helper.CanUndos.ToArray());
                Assert.Equal(new bool[] { }, helper.CanRedos.ToArray());
                Assert.Equal(new bool[] { }, helper.CanClears.ToArray());
            }
        }
        public void Undo_Sets_IsPaused_True_While_Invoking_Undo_Redo_State()
        {
            var target = new StackHistory();

            target.Snapshot(
                undo: () => Assert.True(target.IsPaused),
                redo: () => Assert.True(target.IsPaused));

            Assert.False(target.IsPaused);
            target.Undo();
            Assert.False(target.IsPaused);

            Assert.False(target.IsPaused);
            target.Redo();
            Assert.False(target.IsPaused);
        }
Exemplo n.º 5
0
        public void InsertWithHistory_Inserts_Item_Empty_List()
        {
            var history = new StackHistory();
            var target  = new ObservableCollection <Item>();
            var item0   = new Item("item0");

            target.InsertWithHistory(0, item0, history);
            Assert.Equal(1, target.Count);
            Assert.Equal(item0, target[0]);

            history.Undo();
            Assert.Equal(0, target.Count);

            history.Redo();
            Assert.Equal(1, target.Count);
            Assert.Equal(item0, target[0]);
        }
Exemplo n.º 6
0
        public void AddWithHistory_Adds_Item_Empty_List()
        {
            var history = new StackHistory();
            var target  = new ObservableCollection <Item>();
            var item0   = new Item("item0");

            target.AddWithHistory(item0, history);
            Assert.Single(target);
            Assert.Equal(item0, target[0]);

            history.Undo();
            Assert.Empty(target);

            history.Redo();
            Assert.Single(target);
            Assert.Equal(item0, target[0]);
        }
Exemplo n.º 7
0
        public void RemoveWithHistory_Removes_Index_Empty_List()
        {
            var history = new StackHistory();
            var target  = new ObservableCollection <Item>();
            var item0   = new Item("item0");

            target.Add(item0);
            Assert.Equal(1, target.Count);
            Assert.Equal(item0, target[0]);

            target.RemoveWithHistory(0, history);
            Assert.Equal(0, target.Count);

            history.Undo();
            Assert.Equal(1, target.Count);
            Assert.Equal(item0, target[0]);

            history.Redo();
            Assert.Equal(0, target.Count);
        }
Exemplo n.º 8
0
        public void ReplaceWithHistory_Replaces_Item_Empty_List()
        {
            var history = new StackHistory();
            var target  = new ObservableCollection <Item>();
            var item0   = new Item("item0");
            var item1   = new Item("item1");

            target.Add(item0);
            Assert.Single(target);
            Assert.Equal(item0, target[0]);

            target.ReplaceWithHistory(0, item1, history);
            Assert.Single(target);
            Assert.Equal(item1, target[0]);

            history.Undo();
            Assert.Single(target);
            Assert.Equal(item0, target[0]);

            history.Redo();
            Assert.Single(target);
            Assert.Equal(item1, target[0]);
        }
Exemplo n.º 9
0
        public void ClearWithHistory_Removes_All_Items_Multiple_Item()
        {
            var history = new StackHistory();
            var target  = new ObservableCollection <Item>();
            var item0   = new Item("item0");
            var item1   = new Item("item1");
            var item2   = new Item("item2");

            target.Add(item0);
            target.Add(item1);
            target.Add(item2);
            Assert.Equal(3, target.Count);
            Assert.Equal(item0, target[0]);
            Assert.Equal(item1, target[1]);
            Assert.Equal(item2, target[2]);
            Assert.Equal(0, history.Undos.Count);
            Assert.Equal(0, history.Redos.Count);

            target.ClearWithHistory(history);
            Assert.Equal(0, target.Count);
            Assert.Equal(1, history.Undos.Count);
            Assert.Equal(0, history.Redos.Count);

            history.Undo();
            Assert.Equal(3, target.Count);
            Assert.Equal(item0, target[0]);
            Assert.Equal(item1, target[1]);
            Assert.Equal(item2, target[2]);
            Assert.Equal(0, history.Undos.Count);
            Assert.Equal(1, history.Redos.Count);

            history.Redo();
            Assert.Equal(0, target.Count);
            Assert.Equal(1, history.Undos.Count);
            Assert.Equal(0, history.Redos.Count);
        }
        public LineShapeViewModel(LineShape line, IHistory history)
        {
            Disposable = new CompositeDisposable();

            var lineHistoryScope = new StackHistory().AddTo(this.Disposable);

            this.Name = line.ToReactivePropertyAsSynchronized(l => l.Name)
                        .SetValidateNotifyError(name => string.IsNullOrWhiteSpace(name) ? "Name can not be null or whitespace." : null)
                        .AddTo(this.Disposable);

            var startInitialValue = new PointShapeViewModel(line.Start, lineHistoryScope).AddTo(this.Disposable);

            this.Start = new ReactiveProperty <PointShapeViewModel>(startInitialValue)
                         .SetValidateNotifyError(start => start == null ? "Point can not be null." : null)
                         .AddTo(this.Disposable);

            var endInitialValue = new PointShapeViewModel(line.End, lineHistoryScope).AddTo(this.Disposable);

            this.End = new ReactiveProperty <PointShapeViewModel>(endInitialValue)
                       .SetValidateNotifyError(end => end == null ? "Point can not be null." : null)
                       .AddTo(this.Disposable);

            this.Name.ObserveWithHistory(name => line.Name = name, line.Name, lineHistoryScope).AddTo(this.Disposable);

            this.DeleteCommand = new ReactiveCommand();
            this.DeleteCommand.Subscribe((x) => Delete(line, history)).AddTo(this.Disposable);

            UndoCommand = new ReactiveCommand(lineHistoryScope.CanUndo, false);
            UndoCommand.Subscribe(_ => lineHistoryScope.Undo()).AddTo(this.Disposable);

            RedoCommand = new ReactiveCommand(lineHistoryScope.CanRedo, false);
            RedoCommand.Subscribe(_ => lineHistoryScope.Redo()).AddTo(this.Disposable);

            ClearCommand = new ReactiveCommand(lineHistoryScope.CanClear, false);
            ClearCommand.Subscribe(_ => lineHistoryScope.Clear()).AddTo(this.Disposable);
        }