public void Offline_Error_Fused() { var ms = new MonocastSubject <int>(); var ex = new IndexOutOfRangeException(); ms.OnNext(1); ms.OnNext(2); ms.OnNext(3); ms.OnError(ex); Assert.False(ms.HasObservers); Assert.True(ms.HasException()); Assert.False(ms.HasCompleted()); Assert.AreEqual(ex, ms.GetException()); var to = ms.Test(fusionMode: FusionSupport.Any); Assert.False(ms.HasObservers); to.AssertFuseable() .AssertFusionMode(FusionSupport.Async); to.AssertFailure(typeof(IndexOutOfRangeException), 1, 2, 3); ms.Test().AssertFailure(typeof(InvalidOperationException)); }
public void Async_Regular_Error_Delayed() { for (int i = 0; i < 2; i++) { var ts = new TestScheduler(); var subj = new MonocastSubject <int>(); var to = subj.ObserveOn(ts, true, fair: i == 0) .Test() .WithTag($"fair={i == 0}"); Assert.True(subj.HasObservers); to.AssertEmpty(); subj.OnNext(1); subj.OnNext(2); subj.OnError(new InvalidOperationException()); to.AssertEmpty(); ts.AdvanceTimeBy(1); to.AssertFailure(typeof(InvalidOperationException), 1, 2); } }
public void Offline_Basic_Fused() { var ms = new MonocastSubject <int>(); ms.OnNext(1); ms.OnNext(2); ms.OnNext(3); ms.OnCompleted(); Assert.False(ms.HasObservers); Assert.False(ms.HasException()); Assert.True(ms.HasCompleted()); Assert.Null(ms.GetException()); var to = ms.Test(fusionMode: FusionSupport.Any); to.AssertFuseable() .AssertFusionMode(FusionSupport.Async); Assert.False(ms.HasObservers); to.AssertResult(1, 2, 3); ms.Test().AssertFailure(typeof(InvalidOperationException)); }
public void Mapper_Crash() { var us1 = new MonocastSubject <int>(); var us2 = new MonocastSubject <int>(); var to = ObservableSource.CombineLatest(a => { int v = 0; foreach (var e in a) { v += e; } if (v == 22) { throw new InvalidOperationException(); } return(v); }, us1, us2).Test(); to.AssertEmpty(); us1.OnNext(1); us2.OnNext(10); us1.OnNext(2); us2.OnNext(20); Assert.False(us1.HasObserver()); Assert.False(us2.HasObserver()); to.AssertFailure(typeof(InvalidOperationException), 11, 12); }
public void Disposed() { var us = new MonocastSubject <int>(); var to = new TestObserverLocal(); bool[] disposed = { false }; var d = us.ConcatMap(v => new OnDispose <int>(Enumerable.Range(v * 100, 5), disposed)) .SubscribeWith(to); Assert.True(us.HasObserver()); to.AssertEmpty(); us.OnNext(1); to.AssertValuesOnly(100, 101, 102, 103, 104); Assert.True(us.HasObserver()); us.OnNext(2); Assert.False(us.HasObserver()); Assert.True(disposed[0]); to.AssertResult(100, 101, 102, 103, 104, 200, 201); }
public void Error_Delayed() { var us1 = new MonocastSubject <int>(); var us2 = new MonocastSubject <int>(); var to = ObservableSource.CombineLatest(a => { int v = 0; foreach (var e in a) { v += e; } return(v); }, true, us1, us2).Test(); to.AssertEmpty(); us1.OnNext(1); us1.OnError(new InvalidOperationException()); Assert.True(us2.HasObserver()); us2.EmitAll(10, 20, 30, 40, 50); to.AssertFailure(typeof(InvalidOperationException), 11, 21, 31, 41, 51); }
public void Fused_Failure_Message() { var ms = new MonocastSubject <int>(); var to = ms.Test(fusionMode: FusionSupport.Any); to.AssertEmpty() .AssertFuseable() .AssertFusionMode(FusionSupport.Async); ms.OnNext(1); try { to.AssertEmpty(); Assert.Fail("Should have thrown"); } catch (AssertionException) { throw; } catch (Exception ex) { var msg = ex.Message; Assert.True(msg.Contains("fuseable!")); Assert.True(msg.Contains("fusion-requested")); Assert.True(msg.Contains("fusion-established")); } }
public void Race() { for (int i = 0; i < TestHelper.RACE_LOOPS; i++) { var us = new MonocastSubject <int>(); var to = new TestObserver <int>(); TestHelper.Race(() => { for (int j = 0; j < 1000; j++) { us.OnNext(j); } us.OnCompleted(); }, () => { foreach (var v in us.BlockingEnumerable()) { to.OnNext(v); } to.OnCompleted(); }); to.AssertValueCount(1000) .AssertNoError() .AssertCompleted(); } }
public void Race_While() { for (int i = 0; i < TestHelper.RACE_LOOPS; i++) { var us = new MonocastSubject <int>(); var to = new TestObserver <int>(); TestHelper.Race(() => { for (int j = 0; j < 1000; j++) { us.OnNext(j); } us.OnCompleted(); }, () => { us.BlockingSubscribeWhile(v => { to.OnNext(v); return(true); }, to.OnError, to.OnCompleted); }); to.AssertValueCount(1000) .AssertNoError() .AssertCompleted(); } }
public void Online_Error() { var ms = new MonocastSubject <int>(); Assert.False(ms.HasObservers); Assert.False(ms.HasException()); Assert.False(ms.HasCompleted()); Assert.Null(ms.GetException()); var to = ms.Test(); ms.Test().AssertFailure(typeof(InvalidOperationException)); Assert.True(ms.HasObservers); Assert.False(ms.HasException()); Assert.False(ms.HasCompleted()); Assert.Null(ms.GetException()); to.AssertEmpty(); ms.OnNext(1); to.AssertValuesOnly(1); ms.OnNext(2); to.AssertValuesOnly(1, 2); ms.OnNext(3); to.AssertValuesOnly(1, 2, 3); var ex = new IndexOutOfRangeException(); ms.OnError(ex); to.AssertFailure(typeof(IndexOutOfRangeException), 1, 2, 3); Assert.False(ms.HasObservers); Assert.True(ms.HasException()); Assert.False(ms.HasCompleted()); Assert.AreEqual(ex, ms.GetException()); ms.Test().AssertFailure(typeof(InvalidOperationException)); }
public void Basic() { var us1 = new MonocastSubject <int>(); var us2 = new MonocastSubject <int>(); var to = ObservableSource.CombineLatest(a => { int v = 0; foreach (var e in a) { v += e; } return(v); }, us1, us2).Test(); to.AssertEmpty(); us1.OnNext(1); to.AssertEmpty(); us1.OnNext(2); to.AssertEmpty(); us2.OnNext(10); to.AssertValuesOnly(12); us2.OnNext(20); to.AssertValuesOnly(12, 22); us2.OnCompleted(); to.AssertValuesOnly(12, 22); us1.OnNext(3); to.AssertValuesOnly(12, 22, 23); us1.OnCompleted(); to.AssertResult(12, 22, 23); }
public void Online_Basic() { var ms = new MonocastSubject <int>(); Assert.False(ms.HasObservers); Assert.False(ms.HasException()); Assert.False(ms.HasCompleted()); Assert.Null(ms.GetException()); var to = ms.Test(); ms.Test().AssertFailure(typeof(InvalidOperationException)); Assert.True(ms.HasObservers); Assert.False(ms.HasException()); Assert.False(ms.HasCompleted()); Assert.Null(ms.GetException()); to.AssertEmpty(); ms.OnNext(1); to.AssertValuesOnly(1); ms.OnNext(2); to.AssertValuesOnly(1, 2); ms.OnNext(3); to.AssertValuesOnly(1, 2, 3); ms.OnCompleted(); to.AssertResult(1, 2, 3); Assert.False(ms.HasObservers); Assert.False(ms.HasException()); Assert.True(ms.HasCompleted()); Assert.Null(ms.GetException()); ms.Test().AssertFailure(typeof(InvalidOperationException)); }
public void Race_DelayErrors() { for (int i = 0; i < TestHelper.RACE_LOOPS; i++) { var us1 = new MonocastSubject <int>(); var us2 = new MonocastSubject <int>(); var to = new[] { us1, us2 }.CombineLatest(a => { int v = 0; foreach (var e in a) { v += e; } return(v); }, true).Test(); us1.OnNext(0); us2.OnNext(1000); TestHelper.Race(() => { for (int j = 1; j < 1000; j++) { us1.OnNext(j); } us1.OnCompleted(); }, () => { for (int j = 1001; j < 2000; j++) { us2.OnNext(j); } us2.OnCompleted(); }); to.AssertValueCount(1999) .AssertNoError() .AssertCompleted(); } }
public void Error_Second_Source() { var us1 = new MonocastSubject <int>(); var us2 = new MonocastSubject <int>(); var to = ObservableSource.Zip(a => { int s = 0; foreach (var v in a) { s += v; } return(s); }, us1, us2 ).Test(); us1.OnNext(1); to.AssertEmpty(); us1.OnNext(2); to.AssertEmpty(); us2.OnNext(10); to.AssertValuesOnly(11); us2.OnError(new InvalidOperationException()); Assert.False(us1.HasObserver()); to.AssertFailure(typeof(InvalidOperationException), 11); }
public void Async_Fusion_TryPoll_Crash() { var ms = new MonocastSubject <int>(); var to = ms.Map <int, int>(v => throw new InvalidOperationException()).Test(fusionMode: FusionSupport.Any); to.AssertEmpty() .AssertFuseable() .AssertFusionMode(FusionSupport.Async); ms.OnNext(1); to.AssertFailure(typeof(InvalidOperationException)); Assert.False(ms.HasObservers); }
public void Fused_Async_TryPoll_Crash() { var ms = new MonocastSubject <int>(); var to = ms .Map <int, int>(v => throw new InvalidOperationException()) .ConcatMap(v => { return(ObservableSource.Just(9 + v)); }) .Test(); ms.OnNext(1); Assert.False(ms.HasObservers); to .AssertFailure(typeof(InvalidOperationException)); }
public void Race_DelayErrors() { for (int i = 0; i < TestHelper.RACE_LOOPS; i++) { var us1 = new MonocastSubject <int>(); var us2 = new MonocastSubject <int>(); var to = new[] { us1, us2 }.Zip(a => { int v = 0; foreach (var e in a) { v += e; } return(v); }, true).Test(); TestHelper.Race(() => { for (int j = 0; j < 1000; j++) { us1.OnNext(j); } us1.OnCompleted(); }, () => { for (int j = 1000; j < 2000; j++) { us2.OnNext(j); } us2.OnCompleted(); }); to.AssertValueCount(1000) .AssertNoError() .AssertCompleted(); var list = to.Items; for (int j = 0; j < 1000; j++) { Assert.AreEqual(j + (1000 + j), list[j]); } } }
public void Race_With_Error() { var exc = new InvalidOperationException(); for (int i = 0; i < TestHelper.RACE_LOOPS; i++) { var us = new MonocastSubject <int>(); var to = new TestObserver <int>(); TestHelper.Race(() => { for (int j = 0; j < 1000; j++) { us.OnNext(j); } us.OnError(exc); }, () => { try { foreach (var v in us.BlockingEnumerable()) { to.OnNext(v); } } catch (Exception ex) { to.OnError(ex); } }); to.AssertValueCount(1000) .AssertError(typeof(InvalidOperationException)) .AssertNotCompleted(); } }