public void No_Combinations_Complete_After_All()
        {
            var us1 = new MonocastSubject <int>();
            var us2 = new MonocastSubject <int>();

            var to = ObservableSource.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 Error_Delayed()
        {
            var us1 = new MonocastSubject <int>();
            var us2 = new MonocastSubject <int>();

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

            to.AssertEmpty();

            us1.OnNext(1);
            us1.OnError(new InvalidOperationException());

            Assert.True(us2.HasObserver());

            us2.EmitAll(10, 20, 30, 40, 50);

            to.AssertFailure(typeof(InvalidOperationException), 11, 21, 31, 41, 51);
        }
Exemple #3
0
        public void Switch_Outer_Completes_First()
        {
            var source = new PublishSubject <IObservableSource <int> >();

            var to = source.Switch().Test();

            to.AssertEmpty();

            var us1 = new MonocastSubject <int>();

            source.OnNext(us1);

            Assert.True(us1.HasObserver());

            var us2 = new MonocastSubject <int>();

            source.OnNext(us2);

            Assert.True(us2.HasObserver());
            Assert.False(us1.HasObserver());

            source.OnCompleted();

            Assert.True(us2.HasObserver());

            to.AssertEmpty();

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

            to.AssertResult(1, 2, 3, 4, 5);
        }
        public void Basic()
        {
            var up = new MonocastSubject <int>();

            var to = new TestObserver <int>();

            up.Subscribe(ObservableSource.ToSerialized(to));

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

            to.AssertResult(1, 2, 3, 4, 5);
        }
        public void Async_Regular_Basic()
        {
            for (int i = 0; i < 4; i++)
            {
                var ms = new MonocastSubject <int>();
                ms.EmitAll(1, 2, 3, 4, 5);

                ms
                .ObserveOn(reactive_extensions.ImmediateScheduler.INSTANCE, delayError: i / 2 == 0, fair: i % 2 == 0)
                .Test()
                .WithTag($"delayError={i / 2}, fair={i % 2}")
                .AssertResult(1, 2, 3, 4, 5);
            }
        }
        public void Async_Regular_Async()
        {
            for (int i = 0; i < 4; i++)
            {
                var name = -1;

                var ms = new MonocastSubject <int>();
                ms.EmitAll(1, 2, 3, 4, 5);

                ms
                .ObserveOn(ThreadPoolScheduler.Instance, delayError: i / 2 == 0, fair: i % 2 == 0)
                .DoOnNext(v => name = Thread.CurrentThread.ManagedThreadId)
                .Test()
                .WithTag($"delayError={i / 2}, fair={i % 2}")
                .AwaitDone(TimeSpan.FromSeconds(5))
                .AssertResult(1, 2, 3, 4, 5);

                Assert.AreNotEqual(-1, name);
                Assert.AreNotEqual(Thread.CurrentThread.ManagedThreadId, name);
            }
        }