Example #1
0
        public void Complete()
        {
            var us = new UnicastSubject <int>();

            var n0 = Thread.CurrentThread.ManagedThreadId;

            var cdl = new CountdownEvent(1);

            var n1 = default(int);

            var to = us.DoOnDispose(() =>
            {
                n1 = Thread.CurrentThread.ManagedThreadId;
                cdl.Signal();
            })
                     .UnsubscribeOn(NewThreadScheduler.Default)
                     .Test();

            us.OnNext(1);

            us.OnCompleted();

            to.AssertResult(1);

            Assert.True(cdl.Wait(TimeSpan.FromSeconds(5)));

            Assert.AreNotEqual(n0, n1);
        }
        public void No_Combinations_Complete_After_All()
        {
            var us1 = new UnicastSubject <int>();
            var us2 = new UnicastSubject <int>();

            var to = ReactiveExtensions.CombineLatest(a =>
            {
                int v = 0;
                foreach (var e in a)
                {
                    v += e;
                }
                return(v);
            }, us1, us2).Test();

            to.AssertEmpty();

            us1.OnCompleted();

            Assert.True(us2.HasObserver(), "Other source disposed?");

            us2.EmitAll(1, 2, 3, 4, 5);

            to.AssertResult();
        }
        public void Race_While()
        {
            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                var us = new UnicastSubject <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 Race()
        {
            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                var us = new UnicastSubject <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();
            }
        }
Example #5
0
        public void Switch()
        {
            var s = new UnicastSubject <ICompletableSource>();

            var cs1 = new CompletableSubject();
            var cs2 = new CompletableSubject();
            var cs3 = new CompletableSubject();

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

            to.AssertEmpty();

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

            s.OnNext(cs1);

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

            cs1.OnCompleted();

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

            s.OnNext(cs2);

            Assert.True(cs2.HasObserver());
            Assert.False(cs3.HasObserver());

            s.OnNext(cs3);

            Assert.False(cs2.HasObserver());
            Assert.True(cs3.HasObserver());

            to.AssertEmpty();

            s.OnCompleted();

            to.AssertEmpty();

            cs3.OnCompleted();

            to.AssertResult();
        }
        public void Basic()
        {
            var us1 = new UnicastSubject <int>();
            var us2 = new UnicastSubject <int>();

            var to = ReactiveExtensions.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);
        }
Example #7
0
        public void Observable_Basic_Other()
        {
            var cs1 = new SingleSubject <int>();
            var cs2 = new UnicastSubject <int>();

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

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

            cs2.OnCompleted();

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

            to.AssertFailure(typeof(IndexOutOfRangeException));
        }
        public void Observable_Basic_Other()
        {
            var cs1 = new CompletableSubject();
            var cs2 = new UnicastSubject <int>();

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

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

            cs2.OnCompleted();

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

            to.AssertResult();
        }
Example #9
0
        public void Race_DelayErrors()
        {
            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                var us1 = new UnicastSubject <int>();
                var us2 = new UnicastSubject <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_DelayErrors()
        {
            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                var us1 = new UnicastSubject <int>();
                var us2 = new UnicastSubject <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_Delayed()
        {
            var count = 0;

            var us = new UnicastSubject <int>();

            var to = us
                     .ConcatMap(v => {
                if (v == 2)
                {
                    return(CompletableSource.Error(new InvalidOperationException()));
                }
                return(CompletableSource.FromAction(() => count++));
            }, true)
                     .Test();

            to.AssertEmpty()
            .AssertSubscribed();

            us.OnNext(0);
            us.OnNext(1);
            us.OnNext(2);

            Assert.AreEqual(2, count);

            to.AssertEmpty();

            us.OnNext(3);

            Assert.AreEqual(3, count);
            us.OnCompleted();

            to.AssertFailure(typeof(InvalidOperationException));

            Assert.AreEqual(3, count);
        }
Example #12
0
 public void Dispose()
 {
     publishSubject?.OnCompleted();
 }