public void Limit_Error_Stop() { for (int i = 1; i < 10; i++) { var count = 0; var src = MaybeSource.FromFunc(() => ++ count); var to = new [] { MaybeSource.Just(1), MaybeSource.Error <int>(new InvalidOperationException()), src }.ToObservable() .ConcatEager(maxConcurrency: i) .Test(); to .AssertNotCompleted() .AssertError(typeof(InvalidOperationException)); Assert.AreEqual(0, count); } }
public void Enumerable_Limit_Error_Stop() { for (int i = 1; i < 10; i++) { var count = 0; var src = MaybeSource.FromFunc(() => ++ count); var to = new List <IMaybeSource <int> >() { MaybeSource.Just(1), MaybeSource.Error <int>(new InvalidOperationException()), src } .ConcatEager(maxConcurrency: i) .Test(); if (i >= 2) { to.AssertFailure(typeof(InvalidOperationException)); } else { to.AssertFailure(typeof(InvalidOperationException), 1); } Assert.AreEqual(0, count); } }
public void Timeout_Fallback_Error() { var ts = new TestScheduler(); var us = new MaybeSubject <int>(); var count = 0; var fb = MaybeSource.FromFunc <int>(() => { ++count; throw new InvalidOperationException(); }); 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.AssertFailure(typeof(InvalidOperationException)); Assert.AreEqual(1, count); }
public void Timeout_Fallback_Success() { var ts = new TestScheduler(); var us = new MaybeSubject <int>(); var count = 0; var fb = MaybeSource.FromFunc <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(1); Assert.AreEqual(1, count); }
public void Action_Just_Ignored() { var count = 0; MaybeSource.FromFunc(() => ++ count) .BlockingSubscribe(); Assert.AreEqual(1, count); }
public void Dispose_Upfront() { var count = 0; MaybeSource.FromFunc(() => ++ count) .Test(true) .AssertEmpty(); Assert.AreEqual(0, count); }
public void Basic() { var count = 0; MaybeSource.FromFunc(() => ++ count) .RetryWhen(v => v) .Test() .AssertResult(1); Assert.AreEqual(1, count); }
public void Error_Fallback_Success() { var count = 0; var fb = MaybeSource.FromFunc(() => ++ count); MaybeSource.Error <int>(new InvalidOperationException()) .OnErrorResumeNext(fb) .Test() .AssertResult(1); Assert.AreEqual(1, count); }
public void Dispose_During_Error() { var to = new TestObserver <int>(); MaybeSource.FromFunc <int>(() => { to.Dispose(); throw new InvalidOperationException(); }) .SubscribeWith(to) .AssertEmpty(); Assert.True(to.IsDisposed()); }
public void Dispose_During() { var to = new TestObserver <int>(); MaybeSource.FromFunc(() => { to.Dispose(); return(1); }) .SubscribeWith(to) .AssertEmpty(); Assert.True(to.IsDisposed()); }
public void Maybe_Empty() { var count = 0; MaybeSource.Empty <int>() .FlatMap(v => MaybeSource.FromFunc(() => { count++; return(v + 1); })) .Test() .AssertResult(); Assert.AreEqual(0, count); }
public void Basic() { var count = 0; MaybeSource.FromFunc(() => ++ count) .RepeatWhen(v => v) .SubscribeOn(NewThreadScheduler.Default) .Take(5) .Test() .AwaitDone(TimeSpan.FromSeconds(5)) .AssertResult(1, 2, 3, 4, 5); Assert.True(count >= 5, $"{count}"); }
public void Times_Limit() { var count = 0; var src = MaybeSource.FromFunc(() => ++ count); var obs = src.Repeat(4); obs .Test() .AssertResult(1, 2, 3, 4, 5); Assert.AreEqual(5, count); }
public void Handler_False() { var count = 0; var src = MaybeSource.FromFunc(() => ++ count); var obs = src.Repeat(v => false); obs .Test() .AssertResult(1); Assert.AreEqual(1, count); }
public void Array_First_Wins_Error() { var count = 0; var m = MaybeSource.FromFunc <int>(() => ++ count); MaybeSource.Amb( MaybeSource.Error <int>(new InvalidOperationException()), m ) .Test() .AssertFailure(typeof(InvalidOperationException)); Assert.AreEqual(0, count); }
public void Limited_Repeat() { var count = 0; MaybeSource.FromFunc(() => ++ count) .RepeatWhen(v => { var idx = 0; return(v.TakeWhile(w => ++ idx < 5)); }) .Test() .AssertResult(1, 2, 3, 4, 5); Assert.AreEqual(5, count); }
public void Array_Max_Error_Delay() { var count = 0; var src = MaybeSource.FromFunc(() => ++ count); MaybeSource.ConcatEager(true, MaybeSource.Just(0), MaybeSource.Error <int>(new InvalidOperationException()), src ) .Test() .AssertFailure(typeof(InvalidOperationException), 0, 1); Assert.AreEqual(1, count); }
public void Array_Second_Wins_Success() { var count = 0; var m = MaybeSource.FromFunc <int>(() => ++ count); new[] { MaybeSource.Never <int>(), m } .AmbAll() .Test() .AssertResult(1); Assert.AreEqual(1, count); }
public void Array_First_Wins_Empty() { var count = 0; var m = MaybeSource.FromFunc <int>(() => ++ count); new[] { MaybeSource.Empty <int>(), m } .AmbAll() .Test() .AssertResult(); Assert.AreEqual(0, count); }
public void Enumerable_Second_Wins_Success() { var count = 0; var m = MaybeSource.FromFunc <int>(() => ++ count); new List <IMaybeSource <int> >() { MaybeSource.Never <int>(), m } .Amb() .Test() .AssertResult(1); Assert.AreEqual(1, count); }
public void Times_Basic() { var count = 0; var src = MaybeSource.FromFunc(() => ++ count); var obs = src.Repeat(); obs .SubscribeOn(NewThreadScheduler.Default) .Take(5) .Test() .AwaitDone(TimeSpan.FromSeconds(5)) .AssertResult(1, 2, 3, 4, 5); Assert.True(5 <= count, $"{count}"); }
public void Enumerable_First_Wins_Empty() { var count = 0; var m = MaybeSource.FromFunc <int>(() => ++ count); new List <IMaybeSource <int> >() { MaybeSource.Empty <int>(), m } .Amb() .Test() .AssertResult(); Assert.AreEqual(0, count); }
public void Success() { var name = -1; MaybeSource.FromFunc(() => { name = Thread.CurrentThread.ManagedThreadId; return(1); }) .SubscribeOn(NewThreadScheduler.Default) .Test() .AwaitDone(TimeSpan.FromSeconds(5)) .AssertResult(1); Assert.AreNotEqual(-1, name); Assert.AreNotEqual(Thread.CurrentThread.ManagedThreadId, name); }
public void Array_Null_Entry() { var count = 0; var src = MaybeSource.FromFunc(() => ++ count); new[] { src, src, null, src, src } .Zip(Sum) .Test() .AssertFailure(typeof(NullReferenceException)); }
public void Array_Max_Error_Stop() { var count = 0; var src = MaybeSource.FromFunc(() => ++ count); new[] { MaybeSource.Just(1), MaybeSource.Error <int>(new InvalidOperationException()), src } .ConcatEagerAll() .Test() .AssertFailure(typeof(InvalidOperationException), 1); Assert.AreEqual(0, count); }
public void Array_Second_Wins_Error() { var count = 0; var m = MaybeSource.FromFunc <int>(() => { count++; throw new InvalidOperationException(); }); MaybeSource.Amb( MaybeSource.Never <int>(), m ) .Test() .AssertFailure(typeof(InvalidOperationException)); Assert.AreEqual(1, count); }
public void Enumerable_Null_Entry() { var count = 0; var src = MaybeSource.FromFunc(() => ++ count); new List <IMaybeSource <int> >() { src, src, null, src, src } .Zip(Sum) .Test() .AssertFailure(typeof(NullReferenceException)); }
public void Array_Error_Middle() { var count = 0; var src = MaybeSource.FromFunc(() => ++ count); new[] { src, MaybeSource.Empty <int>(), src, MaybeSource.Error <int>(new InvalidOperationException()), src, src } .ConcatAll() .Test() .AssertFailure(typeof(InvalidOperationException), 1, 2); }
public void Enumerable_Error_Middle_Delay() { var count = 0; var src = MaybeSource.FromFunc(() => ++ count); new List <IMaybeSource <int> >() { src, MaybeSource.Empty <int>(), src, MaybeSource.Error <int>(new InvalidOperationException()), src, src } .Concat(true) .Test() .AssertFailure(typeof(InvalidOperationException), 1, 2, 3, 4); }
public void Array_Null_Entry() { var count = 0; var src = MaybeSource.FromFunc(() => ++ count); new[] { src, MaybeSource.Empty <int>(), src, null, src, src } .ConcatAll() .Test() .AssertFailure(typeof(NullReferenceException), 1, 2); }