Exemple #1
0
        public void Main_Disposes_Others_On_Error()
        {
            var us1 = new MonocastSubject <int>();
            var us2 = new MonocastSubject <int>();

            us1.Emit(10);
            us2.Emit(100);

            var source = new PublishSubject <int>();

            var to = source.WithLatestFrom((a, bs) =>
            {
                foreach (var i in bs)
                {
                    a += i;
                }
                return(a);
            }, us1, us2).Test();

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

            to.AssertEmpty();

            source.EmitError(new InvalidOperationException(), 1, 2, 3, 4, 5);

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

            to.AssertFailure(typeof(InvalidOperationException), 111, 112, 113, 114, 115);
        }
Exemple #2
0
        public void Main_Disposes_Others_On_Completion()
        {
            var us1 = new MonocastSubject <int>();
            var us2 = new MonocastSubject <int>();

            us1.Emit(10);
            us2.Emit(100);

            var source = new PublishSubject <int>();

            var to = source.WithLatestFrom((a, bs) =>
            {
                foreach (var i in bs)
                {
                    a += i;
                }
                return(a);
            }, us1, us2).Test();

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

            to.AssertEmpty();

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

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

            to.AssertResult(111, 112, 113, 114, 115);
        }
        public void Mapper_Crashes()
        {
            var us1 = new MonocastSubject <int>();
            var us2 = new MonocastSubject <int>();

            var to = ObservableSource.Zip(a =>
            {
                int s = 0;
                foreach (var v in a)
                {
                    s += v;
                }

                if (s == 33)
                {
                    throw new InvalidOperationException();
                }
                return(s);
            },
                                          us1,
                                          us2
                                          ).Test();

            us1.Emit(1, 2, 3);

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

            us2.Emit(10, 20, 30, 40);

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

            to.AssertFailure(typeof(InvalidOperationException), 11, 22);
        }
        public void Error_Delayed()
        {
            var us1 = new MonocastSubject <int>();
            var us2 = new MonocastSubject <int>();

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

            us1.EmitError(new InvalidOperationException(), 1, 2, 3);

            Assert.True(us2.HasObserver(), "us2: No observers!");

            us2.Emit(10, 20, 30, 40);

            Assert.False(us2.HasObserver(), "us2: Observers present!");

            to.AssertFailure(typeof(InvalidOperationException), 11, 22, 33);
        }
        public void Basic_Observer_Dispose()
        {
            var to  = new TestObserver <int>();
            var cdl = new CountdownEvent(2);
            var us  = new MonocastSubject <int>();

            Task.Factory.StartNew(() =>
            {
                while (to.ItemCount != 5)
                {
                    ;
                }
                to.Dispose();
                cdl.Signal();
            });

            Task.Factory.StartNew(() =>
            {
                us.Emit(1, 2, 3, 4, 5);
                cdl.Signal();
            });

            us.BlockingSubscribe(to);

            to.AssertValuesOnly(1, 2, 3, 4, 5);

            Assert.True(cdl.Wait(3000));

            Assert.False(us.HasObserver());
        }
        public void Basic_While_Dispose()
        {
            var to  = new TestObserver <int>();
            var sad = new SingleAssignmentDisposable();
            var cdl = new CountdownEvent(2);
            var us  = new MonocastSubject <int>();

            Task.Factory.StartNew(() =>
            {
                while (to.ItemCount != 5)
                {
                    ;
                }
                sad.Dispose();
                cdl.Signal();
            });

            Task.Factory.StartNew(() =>
            {
                us.Emit(1, 2, 3, 4, 5);
                cdl.Signal();
            });

            us.BlockingSubscribeWhile(v => {
                to.OnNext(v);
                return(true);
            }, to.OnError, to.OnCompleted, d => sad.Disposable = d);

            to.AssertValuesOnly(1, 2, 3, 4, 5);

            Assert.True(cdl.Wait(3000));

            Assert.False(us.HasObserver());
        }