Beispiel #1
0
        public void Main_Disposes_Others_On_Completion()
        {
            var us1 = new UnicastSubject <int>();
            var us2 = new UnicastSubject <int>();

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

            var source = new Subject <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 Disposed()
        {
            var us = new UnicastSubject <int>();

            var to = new TestObserverLocal();

            bool[] disposed = { false };

            var d = us.ConcatMap(v => new OnDispose <int>(Enumerable.Range(v * 100, 5), disposed))
                    .Subscribe(to);

            to.OnSubscribe(d);

            Assert.True(us.HasObserver());

            to.AssertEmpty();

            us.OnNext(1);

            to.AssertValuesOnly(100, 101, 102, 103, 104);

            Assert.True(us.HasObserver());

            us.OnNext(2);

            Assert.False(us.HasObserver());

            Assert.True(disposed[0]);

            to.AssertResult(100, 101, 102, 103, 104, 200, 201);
        }
Beispiel #3
0
        public void Mapper_Crashes()
        {
            var us1 = new UnicastSubject <int>();
            var us2 = new UnicastSubject <int>();

            var to = ReactiveExtensions.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 Switch_Outer_Completes_First()
        {
            var source = new Subject <IObservable <int> >();

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

            to.AssertEmpty();

            var us1 = new UnicastSubject <int>();

            source.OnNext(us1);

            Assert.True(us1.HasObserver());

            var us2 = new UnicastSubject <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);
        }
Beispiel #5
0
        public void Main_Disposes_Others_On_Error()
        {
            var us1 = new UnicastSubject <int>();
            var us2 = new UnicastSubject <int>();

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

            var source = new Subject <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);
        }
Beispiel #6
0
        public void Error_Delayed()
        {
            var us1 = new UnicastSubject <int>();
            var us2 = new UnicastSubject <int>();

            var to = ReactiveExtensions.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 Dispose()
        {
            var us = new UnicastSubject <int>();

            var en = us.BlockingEnumerable().GetEnumerator();

            Assert.True(us.HasObserver());

            en.Dispose();

            Assert.False(us.HasObserver());

            Assert.False(en.MoveNext());
        }
        public void Observable_Dispose_Next()
        {
            var us = new UnicastSubject <int>();

            var to = CompletableSource.Empty()
                     .AndThen(us)
                     .Test();

            Assert.True(us.HasObserver());

            to.Dispose();

            Assert.False(us.HasObserver());
        }
Beispiel #9
0
        public void Dispose()
        {
            var us = new UnicastSubject <int>();

            var to = us
                     .IgnoreAllElements()
                     .Test();

            Assert.True(us.HasObserver());

            to.Dispose();

            Assert.False(us.HasObserver());
        }
Beispiel #10
0
        public void Basic_Dispose()
        {
            var count = 0;

            var up = new UnicastSubject <int>();

            var ts = up.DoFinally(() => count++).Test();

            Assert.True(up.HasObserver());

            ts.Dispose();

            Assert.False(up.HasObserver());

            Assert.AreEqual(1, count);
        }
        public void Error_Delayed()
        {
            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);
            }, 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);
        }
        public void Basic_Observer_Dispose()
        {
            var to  = new TestObserver <int>();
            var sad = new SingleAssignmentDisposable();
            var cdl = new CountdownEvent(1);
            var us  = new UnicastSubject <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.BlockingSubscribe(to, d => sad.Disposable = d);

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

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

            Assert.False(us.HasObserver());
        }
        public void Basic_WithDelayError()
        {
            var us = new UnicastSubject <int>();

            var ts = us.ObserveOn(ImmediateScheduler.INSTANCE, true).Test();

            Assert.True(us.HasObserver());

            ts.AssertEmpty();

            us.EmitAll(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

            Assert.False(us.HasObserver());

            ts.AssertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        }
        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 Mapper_Crash()
        {
            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;
                }
                if (v == 22)
                {
                    throw new InvalidOperationException();
                }
                return(v);
            }, us1, us2).Test();

            to.AssertEmpty();

            us1.OnNext(1);
            us2.OnNext(10);

            us1.OnNext(2);
            us2.OnNext(20);

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

            to.AssertFailure(typeof(InvalidOperationException), 11, 12);
        }
        public void Error()
        {
            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++));
            })
                     .Test();

            to.AssertEmpty()
            .AssertSubscribed();

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

            to.AssertFailure(typeof(InvalidOperationException));

            Assert.False(us.HasObserver());

            Assert.AreEqual(2, count);
        }
Beispiel #17
0
        public void Main_Disposed_Handler_Completes()
        {
            var us = new UnicastSubject <int>();

            us.RepeatWhen(v => Observable.Empty <int>())
            .Test()
            .AssertResult();

            Assert.False(us.HasObserver());
        }
        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();
        }
Beispiel #19
0
        public void Main_Disposed_Handler_Errors()
        {
            var us = new UnicastSubject <int>();

            us.RepeatWhen(v => Observable.Throw <int>(new InvalidOperationException()))
            .Test()
            .AssertFailure(typeof(InvalidOperationException));

            Assert.False(us.HasObserver());
        }
Beispiel #20
0
        public void Observable_Dispose()
        {
            var cs1 = new SingleSubject <int>();
            var cs2 = new UnicastSubject <int>();

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

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

            to.Dispose();

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

            to.AssertEmpty();
        }
Beispiel #21
0
        public void Observable_Error_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.OnError(new InvalidOperationException());

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

            to.AssertFailure(typeof(InvalidOperationException));
        }
Beispiel #22
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));
        }
Beispiel #23
0
        public void Observable_Success()
        {
            var cs1 = new SingleSubject <int>();
            var cs2 = new UnicastSubject <int>();

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

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

            cs1.OnSuccess(1);

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

            to.AssertResult(1);
        }
        public void Handler_Disposed()
        {
            var us = new UnicastSubject <int>();

            CompletableSource.Empty()
            .RetryWhen(v => us)
            .Test()
            .AssertResult();

            Assert.False(us.HasObserver());
        }
        public void Observable_Error()
        {
            var us = new UnicastSubject <int>();

            CompletableSource.Error(new InvalidOperationException())
            .AndThen(us)
            .Test()
            .AssertFailure(typeof(InvalidOperationException));

            Assert.False(us.HasObserver());
        }
Beispiel #26
0
        public void Handler_Completes_Immediately()
        {
            var us = new UnicastSubject <int>();

            us
            .RetryWhen(v => Observable.Empty <int>())
            .Test()
            .AssertResult();

            Assert.False(us.HasObserver());
        }
Beispiel #27
0
        public void Handler_Disposed()
        {
            var us = new UnicastSubject <int>();

            Observable.Range(1, 5)
            .RetryWhen(v => us)
            .Test()
            .AssertResult(1, 2, 3, 4, 5);

            Assert.False(us.HasObserver());
        }
Beispiel #28
0
        public void Basic()
        {
            var count = 0;

            var up = new UnicastSubject <int>();

            var d = up.DoOnDispose(() => count++).Subscribe();

            Assert.True(up.HasObserver());
            Assert.AreEqual(0, count);

            d.Dispose();

            Assert.AreEqual(1, count);

            d.Dispose();

            Assert.AreEqual(1, count);

            Assert.False(up.HasObserver());
        }
        public void Dispose()
        {
            var d = default(IDisposable);

            var us = new UnicastSubject <int>();

            var o = us.Cache(capacityHint: 16, cancel: v => d = v);

            Assert.IsNull(d);
            Assert.False(us.HasObserver());

            var to = o.Test();

            Assert.IsNotNull(d);
            Assert.True(us.HasObserver());

            d.Dispose();

            Assert.False(us.HasObserver());

            to.AssertFailure(typeof(OperationCanceledException));
        }
        public void Handler_Crash()
        {
            var up = new UnicastSubject <int>();

            var ts = up
                     .DoAfterNext(v => { throw new InvalidOperationException(); })
                     .Test();

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

            ts.AssertFailure(typeof(InvalidOperationException), 1);

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