This commit is contained in:
Wiesław Šoltés 2016-08-31 23:36:48 +02:00
Родитель 70db5beea9
Коммит 129775f20f
1 изменённых файлов: 50 добавлений и 45 удалений

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

@ -14,12 +14,13 @@ namespace ReactiveHistory.UnitTests
public void ObserveWithHistory_Skips_First_Value()
{
var target = new StackHistory();
var subject = new Subject<int>();
var disposable = subject.AsObservable().ObserveWithHistory(x => { }, 0, target);
subject.OnNext(1);
Assert.Equal(0, target.Undos.Count);
using (var subject = new Subject<int>())
using (subject.AsObservable().ObserveWithHistory(x => { }, 0, target))
{
subject.OnNext(1);
Assert.Equal(0, target.Undos.Count);
}
}
[Fact]
@ -27,14 +28,16 @@ namespace ReactiveHistory.UnitTests
public void ObserveWithHistory_Creates_History_Snapshot()
{
var target = new StackHistory();
var subject = new Subject<int>();
var disposable = subject.AsObservable().ObserveWithHistory(x => { }, 0, target);
subject.OnNext(1);
subject.OnNext(2);
subject.OnNext(3);
using (var subject = new Subject<int>())
using (subject.AsObservable().ObserveWithHistory(x => { }, 0, target))
{
subject.OnNext(1);
subject.OnNext(2);
subject.OnNext(3);
Assert.Equal(2, target.Undos.Count);
Assert.Equal(2, target.Undos.Count);
}
}
[Fact]
@ -42,19 +45,23 @@ namespace ReactiveHistory.UnitTests
public void ObserveWithHistory_Does_Not_Create_History_Snapshot_When_IsPaused_True()
{
var target = new StackHistory();
var subject = new Subject<int>();
var disposable = subject.AsObservable().ObserveWithHistory(x => { }, 0, target);
subject.OnNext(1);
subject.OnNext(2);
target.IsPaused = true;
subject.OnNext(3);
subject.OnNext(4);
target.IsPaused = false;
subject.OnNext(5);
subject.OnNext(6);
using (var subject = new Subject<int>())
using (subject.AsObservable().ObserveWithHistory(x => { }, 0, target))
{
subject.OnNext(1);
subject.OnNext(2);
Assert.Equal(3, target.Undos.Count);
target.IsPaused = true;
subject.OnNext(3);
subject.OnNext(4);
target.IsPaused = false;
subject.OnNext(5);
subject.OnNext(6);
Assert.Equal(3, target.Undos.Count);
}
}
[Fact]
@ -62,35 +69,33 @@ namespace ReactiveHistory.UnitTests
public void ObserveWithHistory_Sets_CurrentValue()
{
var history = new StackHistory();
var subject = new Subject<int>();
var target = new List<int>();
var initialValue = 10;
var disposable = subject.AsObservable().ObserveWithHistory(
x =>
using (var subject = new Subject<int>())
{
var target = new List<int>();
var initialValue = 10;
using (subject.AsObservable().ObserveWithHistory(x => target.Add(x), currentValue: initialValue, history: history))
{
target.Add(x);
},
currentValue: initialValue,
history: history);
subject.OnNext(initialValue); // empty -> 10 (the initial state of variable)
subject.OnNext(2); // empty -> 10 -> 2
subject.OnNext(3); // empty -> 10 -> 2 -> 3
subject.OnNext(initialValue); // empty -> 10 (the initial state of variable)
subject.OnNext(2); // empty -> 10 -> 2
subject.OnNext(3); // empty -> 10 -> 2 -> 3
history.Undo(); // 3 -> 2
history.Undo(); // 2 -> 10 (finally restores initial state)
history.Undo(); // 3 -> 2
history.Undo(); // 2 -> 10 (finally restores initial state)
Assert.Equal(0, history.Undos.Count);
Assert.Equal(2, history.Redos.Count);
Assert.Equal(new int[] { 2, 10 }, target);
Assert.Equal(0, history.Undos.Count);
Assert.Equal(2, history.Redos.Count);
Assert.Equal(new int[] { 2, 10 }, target);
history.Redo(); // 10 -> 2
history.Redo(); // 2 -> 3
history.Redo(); // 10 -> 2
history.Redo(); // 2 -> 3
Assert.Equal(2, history.Undos.Count);
Assert.Equal(0, history.Redos.Count);
Assert.Equal(new int[] { 2, 10, 2, 3 }, target);
Assert.Equal(2, history.Undos.Count);
Assert.Equal(0, history.Redos.Count);
Assert.Equal(new int[] { 2, 10, 2, 3 }, target);
}
}
}
}
}