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);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 8
0
        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}");
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
        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);
        }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 21
0
        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}");
        }
Exemplo n.º 22
0
        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);
        }
Exemplo n.º 24
0
        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));
        }
Exemplo n.º 25
0
        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);
        }
Exemplo n.º 26
0
        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);
        }
Exemplo n.º 27
0
        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));
        }
Exemplo n.º 28
0
        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);
        }
Exemplo n.º 29
0
        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);
        }
Exemplo n.º 30
0
        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);
        }