diff --git a/tests/ReactiveHistory.UnitTests/StackHistoryExtensionsTests.cs b/tests/ReactiveHistory.UnitTests/StackHistoryExtensionsTests.cs index 118583d..a3adc5c 100644 --- a/tests/ReactiveHistory.UnitTests/StackHistoryExtensionsTests.cs +++ b/tests/ReactiveHistory.UnitTests/StackHistoryExtensionsTests.cs @@ -93,6 +93,144 @@ namespace ReactiveHistory.UnitTests Assert.Equal(item0, target[0]); } + [Fact] + [Trait("ReactiveHistory", "StackHistoryExtensions")] + public void InsertWithHistory_Inserts_Items_List_Head() + { + var history = new StackHistory(); + var target = new ObservableCollection(); + var item0 = new Item("item0"); + var item1 = new Item("item1"); + var item2 = new Item("item2"); + + target.InsertWithHistory(0, item0, history); + target.InsertWithHistory(0, item1, history); + target.InsertWithHistory(0, item2, history); + Assert.Equal(3, target.Count); + Assert.Equal(item2, target[0]); + Assert.Equal(item1, target[1]); + Assert.Equal(item0, target[2]); + + history.Undo(); + Assert.Equal(2, target.Count); + Assert.Equal(item1, target[0]); + Assert.Equal(item0, target[1]); + + history.Undo(); + 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]); + + history.Redo(); + Assert.Equal(2, target.Count); + Assert.Equal(item1, target[0]); + Assert.Equal(item0, target[1]); + + history.Redo(); + Assert.Equal(3, target.Count); + Assert.Equal(item2, target[0]); + Assert.Equal(item1, target[1]); + Assert.Equal(item0, target[2]); + } + + [Fact] + [Trait("ReactiveHistory", "StackHistoryExtensions")] + public void InsertWithHistory_Inserts_Items_List_Tail() + { + var history = new StackHistory(); + var target = new ObservableCollection(); + 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(2, 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.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]); + + 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]); + } + + [Fact] + [Trait("ReactiveHistory", "StackHistoryExtensions")] + public void InsertWithHistory_Inserts_Items_List_Middle() + { + var history = new StackHistory(); + var target = new ObservableCollection(); + 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.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]); + + 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]); + } + [Fact] [Trait("ReactiveHistory", "StackHistoryExtensions")] public void ReplaceWithHistory_Replaces_Item_Empty_List()