public
Created

ContinueAfter Unit Tests

  • Download Gist
continue-after-unit-tests.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
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?");
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.