This commit is contained in:
Wiesław Šoltés 2016-09-01 22:58:40 +02:00
Родитель 917ecccaf7
Коммит 7e3c768cbc
1 изменённых файлов: 138 добавлений и 0 удалений

Просмотреть файл

@ -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<Item>();
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<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(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<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.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()