Created
October 8, 2012 22:34
-
-
Save haacked/3855403 to your computer and use it in GitHub Desktop.
ContinueAfter Unit Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TheContinueAfterMethod | |
{ | |
[Fact] | |
public void RunsNextItemAfterCompletion() | |
{ | |
var stringSequence = new[] { "one", "two", "three" }.ToObservable(); | |
var observed = new List<String>(); | |
Observable.Return(123).ContinueAfter(() => stringSequence) | |
.Subscribe(observed.Add); | |
observed[0].ShouldEqual("one"); | |
observed[1].ShouldEqual("two"); | |
observed[2].ShouldEqual("three"); | |
} | |
[Fact] | |
public void RunsNextItemOnlyOnceAfterCompletion() | |
{ | |
var stringSequence = new[] { "uno", "dos", "tres" }.ToObservable(); | |
var initialSequence = new[] { 1, 2, 3, 4 }.ToObservable(); | |
int callCount = 0; | |
var observed = new List<String>(); | |
initialSequence.ContinueAfter(() => | |
{ | |
callCount++; | |
return stringSequence; | |
}) | |
.Subscribe(observed.Add); | |
callCount.ShouldEqual(1); | |
observed[0].ShouldEqual("uno"); | |
observed[1].ShouldEqual("dos"); | |
observed[2].ShouldEqual("tres"); | |
} | |
[Fact] | |
public void RunsNextItemAfterObservableCompletesWithEmptySequence() | |
{ | |
var stringSequence = new[] { "하나", "둘", "셋" }.ToObservable(); | |
var observed = new List<String>(); | |
Observable.Empty<int>() | |
.ContinueAfter(() => stringSequence) | |
.Subscribe(observed.Add); | |
observed[0].ShouldEqual("하나"); | |
observed[1].ShouldEqual("둘"); | |
observed[2].ShouldEqual("셋"); | |
} | |
[Fact] | |
public void ForwardsExceptionsFromOriginalObservable() | |
{ | |
var stringSequence = new[] { "하나", "둘", "셋" }.ToObservable(); | |
var observed = new List<String>(); | |
Exception caught = null; | |
Observable.Throw<int>(new Exception("Will we catch this?")) | |
.ContinueAfter(() => stringSequence) | |
.Subscribe(observed.Add, e => caught = e); | |
observed.Count.ShouldEqual(0); | |
caught.Message.ShouldEqual("Will we catch this?"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment