public void Timeout_Fallback_Empty() { var ts = new TestScheduler(); var us = new MaybeSubject <int>(); var count = 0; var fb = MaybeSource.FromAction <int>(() => count++); var to = us .Timeout(TimeSpan.FromSeconds(1), ts, fb) .Test(); to.AssertEmpty(); ts.AdvanceTimeBy(100); Assert.True(us.HasObserver()); ts.AdvanceTimeBy(900); Assert.False(us.HasObserver()); to.AssertResult(); Assert.AreEqual(1, count); }
public void Enumerable_Error_Empty_Second() { var count = 0; var src = MaybeSource.FromAction <int>(() => { ++count; }); var err = MaybeSource.FromAction <int>(() => { ++count; throw new InvalidOperationException(); }); new List <IMaybeSource <int> >() { src, err } .Zip(Sum) .Test() .AssertResult(); Assert.AreEqual(1, count); }
public void Action_Empty_Ignored() { var count = 0; MaybeSource.FromAction <int>(() => count++) .BlockingSubscribe(); Assert.AreEqual(1, count); }
public void Empty() { var count = 0; MaybeSource.FromAction <int>(() => ++ count) .RetryWhen(v => v) .Test() .AssertResult(); Assert.AreEqual(1, count); }
public void Disposed_Upfront() { var count = 0; var c = MaybeSource.FromAction <int>(() => count++); c.Test(true) .AssertSubscribed() .AssertEmpty(); Assert.AreEqual(0, count); }
public void Error_Fallback_Empty() { var count = 0; var fb = MaybeSource.FromAction <int>(() => count++); MaybeSource.Error <int>(new InvalidOperationException()) .OnErrorResumeNext(fb) .Test() .AssertResult(); Assert.AreEqual(1, count); }
public void Handler_Success() { var count = 0; var fb = MaybeSource.FromAction <int>(() => count++); MaybeSource.Just(1) .OnErrorResumeNext(e => fb) .Test() .AssertResult(1); Assert.AreEqual(0, count); }
public void Error_Fallback() { var count = 0; var fb = MaybeSource.FromAction <int>(() => count++); MaybeSource.Error <int>(new InvalidOperationException()) .Timeout(TimeSpan.FromMinutes(1), NewThreadScheduler.Default, fb) .Test() .AssertFailure(typeof(InvalidOperationException)); Assert.AreEqual(0, count); }
public void Empty_Fallback() { var count = 0; var fb = MaybeSource.FromAction <int>(() => count++); MaybeSource.Empty <int>() .Timeout(TimeSpan.FromMinutes(1), NewThreadScheduler.Default, fb) .Test() .AssertResult(); Assert.AreEqual(0, count); }
public void Empty() { var count = 0; var fb = MaybeSource.FromAction <int>(() => count++); MaybeSource.Empty <int>() .OnErrorResumeNext(fb) .Test() .AssertResult(); Assert.AreEqual(0, count); }
public void Maybe_Inner_Empty() { var count = 0; SingleSource.Just(1) .FlatMap(v => MaybeSource.FromAction <string>(() => { count++; })) .Test() .AssertResult(); Assert.AreEqual(1, count); }
public void Maybe_Error() { var count = 0; SingleSource.Error <int>(new InvalidOperationException()) .FlatMap(v => MaybeSource.FromAction <string>(() => { count++; })) .Test() .AssertFailure(typeof(InvalidOperationException)); Assert.AreEqual(0, count); }
public void Handler_Empty_Crash() { var count = 0; var src = MaybeSource.FromAction <int>(() => ++ count); var obs = src.Repeat(v => throw new InvalidOperationException()); obs .Test() .AssertFailure(typeof(InvalidOperationException)); Assert.AreEqual(1, count); }
public void Times_Error_Limit_Fail() { var count = 0; MaybeSource.FromAction <int>(() => { if (++count < 5) { throw new InvalidOperationException(); } }) .Retry(3) .Test() .AssertFailure(typeof(InvalidOperationException)); }
public void Times_Error_Limit() { var count = 0; MaybeSource.FromAction <int>(() => { if (++count < 5) { throw new InvalidOperationException(); } }) .Retry(5) .Test() .AssertResult(); }
public void Handler_Error() { var count = 0; MaybeSource.FromAction <int>(() => { if (++count < 5) { throw new InvalidOperationException(); } }) .Retry((e, i) => true) .Test() .AssertResult(); }
public void Error() { var count = 0; MaybeSource.FromAction <int>(() => { if (++count < 5) { throw new InvalidOperationException(); } }) .RetryWhen(v => v) .Test() .AssertResult(); }
public void DisposeUpfront() { var name = ""; MaybeSource.FromAction <int>(() => { name = Thread.CurrentThread.Name; throw new InvalidOperationException(); }) .SubscribeOn(NewThreadScheduler.Default) .Test(true) .AssertEmpty(); Assert.AreEqual("", name); }
public void Error() { var count = 0; MaybeSource.FromAction <int>(() => { count++; throw new InvalidOperationException(); }) .RepeatWhen(v => v) .Test() .AssertFailure(typeof(InvalidOperationException)); Assert.AreEqual(1, count); }
public void Basic() { var name = -1; MaybeSource.FromAction <int>(() => { name = Thread.CurrentThread.ManagedThreadId; }) .SubscribeOn(NewThreadScheduler.Default) .Test() .AwaitDone(TimeSpan.FromSeconds(5)) .AssertResult(); Assert.AreNotEqual(-1, name); Assert.AreNotEqual(Thread.CurrentThread.ManagedThreadId, name); }
public void Disposed_During() { var count = 0; var to = new TestObserver <object>(); var c = MaybeSource.FromAction <object>(() => { count++; to.Dispose(); }); c.SubscribeWith(to) .AssertSubscribed() .AssertEmpty(); Assert.AreEqual(1, count); }
public void Basic() { var count = 0; var c = MaybeSource.FromAction <int>(() => count++); for (int i = 0; i < 100; i++) { Assert.AreEqual(i, count); c.Test() .AssertSubscribed() .AssertResult(); Assert.AreEqual(i + 1, count); } }
public void Empty() { var count = 0; MaybeSource.FromAction <int>(() => { if (++count >= 5) { throw new InvalidOperationException(); } }) .RepeatWhen(v => v) .Test() .AssertFailure(typeof(InvalidOperationException)); Assert.AreEqual(5, count); }
public void Array_Second_Wins_Empty() { var count = 0; var m = MaybeSource.FromAction <int>(() => ++ count); new[] { MaybeSource.Never <int>(), m } .AmbAll() .Test() .AssertResult(); Assert.AreEqual(1, count); }
public void Enumerable_Second_Wins_Empty() { var count = 0; var m = MaybeSource.FromAction <int>(() => ++ count); new List <IMaybeSource <int> >() { MaybeSource.Never <int>(), m } .Amb() .Test() .AssertResult(); Assert.AreEqual(1, count); }
public void Error() { var name = -1; MaybeSource.FromAction <int>(() => { name = Thread.CurrentThread.ManagedThreadId; throw new InvalidOperationException(); }) .SubscribeOn(NewThreadScheduler.Default) .Test() .AwaitDone(TimeSpan.FromSeconds(5)) .AssertFailure(typeof(InvalidOperationException)); Assert.AreNotEqual(-1, name); Assert.AreNotEqual(Thread.CurrentThread.ManagedThreadId, name); }
public void Limited_Retry() { var count = 0; MaybeSource.FromAction <int>(() => { ++count; throw new InvalidOperationException(); }) .RetryWhen(v => { var idx = 0; return(v.TakeWhile(w => ++ idx < 5)); }) .Test() .AssertResult(); Assert.AreEqual(5, count); }
public void Times_Limit_Error() { var count = 0; var src = MaybeSource.FromAction <int>(() => { if (++count == 5) { throw new InvalidOperationException(); } }); var obs = src.Repeat(5); obs .Test() .AssertFailure(typeof(InvalidOperationException)); Assert.AreEqual(5, count); }
public void Times_Limit_Empty() { var count = 0; var src = MaybeSource.FromAction <int>(() => { if (++count == 6) { throw new InvalidOperationException(); } }); var obs = src.Repeat(4); obs .Test() .AssertResult(); Assert.AreEqual(5, count); }
public void Handler_Wrong_Error() { var count = 0; MaybeSource.FromAction <int>(() => { if (++count < 5) { throw new InvalidOperationException(); } else { throw new ArgumentOutOfRangeException(); } }) .Retry((e, i) => e is InvalidOperationException) .Test() .AssertFailure(typeof(ArgumentOutOfRangeException)); }