public void Enumerable_Limited_Subscription()
        {
            var ms1 = new MaybeSubject <int>();
            var ms2 = new MaybeSubject <int>();

            var to = new List <IMaybeSource <int> >()
            {
                ms1,
                ms2
            }
            .Merge(maxConcurrency: 1)
            .Test();

            Assert.True(ms1.HasObserver());
            Assert.False(ms2.HasObserver());

            ms1.OnSuccess(1);

            Assert.False(ms1.HasObserver());
            Assert.True(ms2.HasObserver());

            ms2.OnSuccess(2);

            to.AssertResult(1, 2);
        }
        public void Enumerable_Limited_Race_Success()
        {
            for (int k = 1; k < 4; k++)
            {
                for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
                {
                    var ms1 = new MaybeSubject <int>();
                    var ms2 = new MaybeSubject <int>();

                    var to = new List <IMaybeSource <int> >()
                    {
                        ms1,
                        ms2
                    }
                    .Merge(maxConcurrency: k)
                    .Test();

                    TestHelper.Race(() =>
                    {
                        ms1.OnSuccess(1);
                    }, () =>
                    {
                        ms2.OnSuccess(2);
                    });

                    to.AssertValueCount(2)
                    .AssertNoError()
                    .AssertCompleted();
                }
            }
        }
        public void Array_Limited_Race_Empty_Success()
        {
            for (int k = 1; k < 4; k++)
            {
                for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
                {
                    var ms1 = new MaybeSubject <int>();
                    var ms2 = new MaybeSubject <int>();

                    var to = new[]
                    {
                        ms1,
                        ms2
                    }
                    .MergeAll(maxConcurrency: k)
                    .Test();

                    TestHelper.Race(() =>
                    {
                        ms1.OnSuccess(1);
                    }, () =>
                    {
                        ms2.OnCompleted();
                    });

                    to.AssertResult(1);
                }
            }
        }
        public void Maybe_Dispose_Inner()
        {
            var ss = new MaybeSubject <int>();
            var cs = new CompletableSubject();

            var to = ss
                     .FlatMap(v => cs)
                     .Test();

            to.AssertSubscribed();

            Assert.True(ss.HasObserver());
            Assert.False(cs.HasObserver());

            ss.OnSuccess(1);

            Assert.True(cs.HasObserver());
            Assert.False(ss.HasObserver());

            to.AssertEmpty();

            cs.OnCompleted();

            to.AssertResult();
        }
        public void Limited_Eager_Race_Upstream_Success()
        {
            for (int k = 1; k < 10; k++)
            {
                for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
                {
                    var ms1 = new MaybeSubject <int>();
                    var ms2 = new MaybeSubject <int>();

                    var subj = new Subject <MaybeSubject <int> >();

                    var to = subj.FlatMap(v => v, maxConcurrency: k).Test();

                    subj.OnNext(ms1);

                    TestHelper.Race(() =>
                    {
                        ms1.OnSuccess(1);
                    }, () =>
                    {
                        subj.OnNext(ms2);
                        ms2.OnSuccess(2);
                    });

                    subj.OnCompleted();

                    to.AssertValueCount(2)
                    .AssertNoError()
                    .AssertCompleted();
                }
            }
        }
Exemplo n.º 6
0
        public void Enumerable_Limit_Max_Concurrency()
        {
            var ms1 = new MaybeSubject <int>();
            var ms2 = new MaybeSubject <int>();

            var to = MaybeSource.ConcatEager(
                new List <IMaybeSource <int> >()
            {
                ms1, ms2
            }
                , maxConcurrency: 1
                )
                     .Test();

            Assert.True(ms1.HasObserver());
            Assert.False(ms2.HasObserver());

            ms1.OnSuccess(1);

            Assert.False(ms1.HasObserver());
            Assert.True(ms2.HasObserver());

            ms2.OnSuccess(2);

            to.AssertResult(1, 2);
        }
        public void Limited_Eager_Main_Completes_Inner_Succeeds()
        {
            for (int k = 1; k < 10; k++)
            {
                var subj = new Subject <int>();
                var ms   = new MaybeSubject <int>();

                var to = subj.FlatMap(v => ms, maxConcurrency: k).Test();

                Assert.True(subj.HasObservers);
                Assert.False(ms.HasObserver());

                subj.OnNext(1);
                subj.OnCompleted();

                Assert.True(ms.HasObserver());

                ms.OnSuccess(1);

                Assert.False(subj.HasObservers);
                Assert.False(ms.HasObserver());

                to.AssertResult(1);
            }
        }
        public void Enumerable_Max_Race_Empty_Success()
        {
            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                var ms1 = new MaybeSubject <int>();
                var ms2 = new MaybeSubject <int>();

                var to = new List <IMaybeSource <int> >()
                {
                    ms1,
                    ms2
                }
                .Merge()
                .Test();

                TestHelper.Race(() =>
                {
                    ms1.OnSuccess(1);
                }, () =>
                {
                    ms2.OnCompleted();
                });

                to.AssertResult(1);
            }
        }
        public void Limited_Eager_Race_Success_Empty()
        {
            for (int k = 1; k < 10; k++)
            {
                for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
                {
                    var ms1 = new MaybeSubject <int>();
                    var ms2 = new MaybeSubject <int>();

                    var to = new[] {
                        ms1, ms2
                    }
                    .ToObservable()
                    .FlatMap(v => v, maxConcurrency: k)
                    .Test();

                    TestHelper.Race(() =>
                    {
                        ms1.OnSuccess(1);
                    }, () =>
                    {
                        ms2.OnCompleted();
                    });

                    to.AssertResult(1);
                }
            }
        }
        public void Max_Delayed_Race_Upstream_Success()
        {
            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                var ms1 = new MaybeSubject <int>();
                var ms2 = new MaybeSubject <int>();

                var subj = new Subject <MaybeSubject <int> >();

                var to = subj.FlatMap(v => v, true).Test();

                subj.OnNext(ms1);

                TestHelper.Race(() =>
                {
                    ms1.OnSuccess(1);
                }, () =>
                {
                    subj.OnNext(ms2);
                    ms2.OnSuccess(2);
                });

                subj.OnCompleted();

                to.AssertValueCount(2)
                .AssertNoError()
                .AssertCompleted();
            }
        }
        public void Max_Delayed_Race_Success_Error()
        {
            var ex = new InvalidOperationException();

            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                var ms1 = new MaybeSubject <int>();
                var ms2 = new MaybeSubject <int>();

                var to = new[] {
                    ms1, ms2
                }
                .ToObservable()
                .FlatMap(v => v, true)
                .Test();

                TestHelper.Race(() => {
                    ms1.OnSuccess(1);
                }, () => {
                    ms2.OnError(ex);
                });

                to.AssertFailure(typeof(InvalidOperationException), 1);
            }
        }
        public void Max_Delayed_Race_Success()
        {
            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                var ms1 = new MaybeSubject <int>();
                var ms2 = new MaybeSubject <int>();

                var to = new[] {
                    ms1, ms2
                }
                .ToObservable()
                .FlatMap(v => v, true)
                .Test();

                TestHelper.Race(() => {
                    ms1.OnSuccess(1);
                }, () => {
                    ms2.OnSuccess(2);
                });

                to.AssertValueCount(2)
                .AssertNoError()
                .AssertCompleted();
            }
        }
Exemplo n.º 13
0
        public void Array_Limited_Subscription()
        {
            var ms1 = new MaybeSubject <int>();
            var ms2 = new MaybeSubject <int>();

            var to = new[]
            {
                ms1,
                ms2
            }
            .MergeAll(maxConcurrency: 1)
            .Test();

            Assert.True(ms1.HasObserver());
            Assert.False(ms2.HasObserver());

            ms1.OnSuccess(1);

            Assert.False(ms1.HasObserver());
            Assert.True(ms2.HasObserver());

            ms2.OnSuccess(2);

            to.AssertResult(1, 2);
        }
Exemplo n.º 14
0
        public void Array_Max_Race_Success()
        {
            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                var ms1 = new MaybeSubject <int>();
                var ms2 = new MaybeSubject <int>();

                var to = new[]
                {
                    ms1,
                    ms2
                }
                .MergeAll()
                .Test();

                TestHelper.Race(() =>
                {
                    ms1.OnSuccess(1);
                }, () =>
                {
                    ms2.OnSuccess(2);
                });

                to.AssertValueCount(2)
                .AssertNoError()
                .AssertCompleted();
            }
        }
Exemplo n.º 15
0
        public void Crash_OnSuccess()
        {
            var cs = new MaybeSubject <int>();

            cs.SubscribeSafe(new FailingMaybeObserver(false, true, true, true));

            Assert.True(cs.HasObserver());

            cs.OnSuccess(1);
        }
        public void Disposed_Upfront()
        {
            var ms = new MaybeSubject <int>();

            var to = ms.Test();

            var to2 = ms.Test(true).AssertSubscribed().AssertEmpty();

            ms.OnSuccess(1);

            to.AssertResult(1);

            to2.AssertEmpty();
        }
Exemplo n.º 17
0
        public void Multiple()
        {
            var ms = new MaybeSubject <int>();

            var source = ms.Cache();

            var to1 = source.Test();
            var to2 = source.Test();
            var to3 = source.Test(true);

            ms.OnSuccess(1);

            to1.AssertResult(1);
            to2.AssertResult(1);
            to3.AssertEmpty();
        }
        public void Success_Dispose_Other()
        {
            var ms = new MaybeSubject <int>();

            var to1 = new TestObserver <int>();

            var count = 0;

            ms.Subscribe(v => { to1.Dispose(); }, e => { count = 1; }, () => { count = 2; });

            ms.Subscribe(to1);

            ms.OnSuccess(1);

            to1.AssertEmpty();

            Assert.AreEqual(0, count);
        }
        public void Success_Other()
        {
            var cs1 = new MaybeSubject <int>();
            var cs2 = new MaybeSubject <int>();

            var to = cs1
                     .TakeUntil(cs2)
                     .Test();

            Assert.True(cs1.HasObserver());
            Assert.True(cs2.HasObserver());

            cs2.OnSuccess(1);

            Assert.False(cs1.HasObserver());
            Assert.False(cs2.HasObserver());

            to.AssertResult();
        }
        public void Limited_Eager_Empty_First()
        {
            var ms1 = new MaybeSubject <int>();
            var ms2 = new MaybeSubject <int>();

            var to = new[] { ms1, ms2 }.ToObservable()
            .FlatMap(v => v, maxConcurrency: 1)
            .Test();

            Assert.True(ms1.HasObserver());
            Assert.False(ms2.HasObserver());

            ms1.OnCompleted();

            Assert.True(ms2.HasObserver());

            ms2.OnSuccess(2);

            to.AssertResult(2);
        }
        public void Limited_Delayed_Error_First()
        {
            var ms1 = new MaybeSubject <int>();
            var ms2 = new MaybeSubject <int>();

            var to = new[] { ms1, ms2 }.ToObservable()
            .FlatMap(v => v, true, maxConcurrency: 1)
            .Test();

            Assert.True(ms1.HasObserver());
            Assert.False(ms2.HasObserver());

            ms1.OnError(new InvalidOperationException());

            Assert.True(ms2.HasObserver());

            ms2.OnSuccess(2);

            to.AssertFailure(typeof(InvalidOperationException), 2);
        }
        public void Limited_Delayed_Success_First()
        {
            var ms1 = new MaybeSubject <int>();
            var ms2 = new MaybeSubject <int>();

            var to = new[] { ms1, ms2 }.ToObservable()
            .FlatMap(v => v, true, maxConcurrency: 1)
            .Test();

            Assert.True(ms1.HasObserver());
            Assert.False(ms2.HasObserver());

            ms1.OnSuccess(1);

            Assert.True(ms2.HasObserver());

            ms2.OnSuccess(2);

            to.AssertResult(1, 2);
        }
Exemplo n.º 23
0
        public void Array_Limit_Keep_Order()
        {
            var ms1 = new MaybeSubject <int>();
            var ms2 = new MaybeSubject <int>();

            var to = MaybeSource.ConcatEager(2,
                                             ms1, ms2
                                             )
                     .Test();

            Assert.True(ms1.HasObserver());
            Assert.True(ms2.HasObserver());

            ms2.OnSuccess(2);

            to.AssertEmpty();

            ms1.OnSuccess(1);

            to.AssertResult(1, 2);
        }
        public void Success()
        {
            var ms = new MaybeSubject <int>();

            Assert.False(ms.HasObservers);
            Assert.False(ms.HasCompleted());
            Assert.False(ms.HasException());
            Assert.IsNull(ms.GetException());
            Assert.False(ms.HasValue());
            Assert.False(ms.TryGetValue(out var _));

            var to = ms.Test();

            Assert.True(ms.HasObservers);
            Assert.False(ms.HasCompleted());
            Assert.False(ms.HasException());
            Assert.IsNull(ms.GetException());
            Assert.False(ms.HasValue());
            Assert.False(ms.TryGetValue(out var _));

            to.AssertSubscribed().AssertEmpty();

            ms.OnSuccess(1);

            Assert.False(ms.HasObservers);
            Assert.False(ms.HasCompleted());
            Assert.False(ms.HasException());
            Assert.IsNull(ms.GetException());
            Assert.True(ms.HasValue());
            var v = default(int);

            Assert.True(ms.TryGetValue(out v));
            Assert.AreEqual(1, v);

            to.AssertResult(1);

            ms.Test().AssertSubscribed().AssertResult(1);

            ms.Test(true).AssertSubscribed().AssertEmpty();
        }
        public void Max_Eager_Main_Completes_Inner_Succeeds()
        {
            var subj = new Subject <int>();
            var ms   = new MaybeSubject <int>();

            var to = subj.FlatMap(v => ms).Test();

            Assert.True(subj.HasObservers);
            Assert.False(ms.HasObserver());

            subj.OnNext(1);
            subj.OnCompleted();

            Assert.True(ms.HasObserver());

            ms.OnSuccess(1);

            Assert.False(subj.HasObservers);
            Assert.False(ms.HasObserver());

            to.AssertResult(1);
        }
Exemplo n.º 26
0
        public void Array_Limit_Max_Concurrency()
        {
            var ms1 = new MaybeSubject <int>();
            var ms2 = new MaybeSubject <int>();

            var to = MaybeSource.ConcatEager(1,
                                             ms1, ms2
                                             )
                     .Test();

            Assert.True(ms1.HasObserver());
            Assert.False(ms2.HasObserver());

            ms1.OnSuccess(1);

            Assert.False(ms1.HasObserver());
            Assert.True(ms2.HasObserver());

            ms2.OnSuccess(2);

            to.AssertResult(1, 2);
        }
        public void Limit_Keep_Order()
        {
            var ms1 = new MaybeSubject <int>();
            var ms2 = new MaybeSubject <int>();

            var to = MaybeSource.ConcatEager(
                new [] {
                ms1, ms2
            }.ToObservable(), maxConcurrency: 2
                )
                     .Test();

            Assert.True(ms1.HasObserver());
            Assert.True(ms2.HasObserver());

            ms2.OnSuccess(2);

            to.AssertEmpty();

            ms1.OnSuccess(1);

            to.AssertResult(1, 2);
        }
Exemplo n.º 28
0
        public void Eager_Switch_Normal()
        {
            var subj = new Subject <MaybeSubject <int> >();

            var ms1 = new MaybeSubject <int>();
            var ms2 = new MaybeSubject <int>();
            var ms3 = new MaybeSubject <int>();

            var to = subj.SwitchMap(v => v).Test();

            to.AssertEmpty();

            subj.OnNext(ms1);

            Assert.True(ms1.HasObserver());

            ms1.OnSuccess(1);

            to.AssertValuesOnly(1);

            subj.OnNext(ms2);

            Assert.True(ms2.HasObserver());

            subj.OnNext(ms3);

            Assert.False(ms2.HasObserver());
            Assert.True(ms3.HasObserver());

            subj.OnCompleted();

            Assert.True(ms3.HasObserver());

            ms3.OnSuccess(3);

            to.AssertResult(1, 3);
        }
Exemplo n.º 29
0
        public void Delayed_Switch_Main_Errors_Success()
        {
            var subj = new Subject <MaybeSubject <int> >();

            var ms1 = new MaybeSubject <int>();
            var ms2 = new MaybeSubject <int>();
            var ms3 = new MaybeSubject <int>();

            var to = subj.SwitchMap(v => v, true).Test();

            to.AssertEmpty();

            subj.OnNext(ms1);

            Assert.True(ms1.HasObserver());

            ms1.OnSuccess(1);

            to.AssertValuesOnly(1);

            subj.OnNext(ms2);

            Assert.True(ms2.HasObserver());

            subj.OnNext(ms3);

            Assert.False(ms2.HasObserver());
            Assert.True(ms3.HasObserver());

            subj.OnError(new InvalidOperationException());

            Assert.True(ms3.HasObserver());

            ms3.OnSuccess(3);

            to.AssertFailure(typeof(InvalidOperationException), 1, 3);
        }
Exemplo n.º 30
0
        public void Action_Success_Async()
        {
            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                var cs = new MaybeSubject <int>();

                var to = new TestObserver <int>();

                var cdl = new CountdownEvent(1);

                Task.Factory.StartNew(() =>
                {
                    while (!cs.HasObserver())
                    {
                        ;
                    }
                    cs.OnSuccess(1);
                });

                cs.BlockingSubscribe(to.OnSuccess, to.OnError, to.OnCompleted);

                to.AssertResult(1);
            }
        }