public void ConnectableObservable_Connected()
        {
            var scheduler = new TestScheduler();

            var xs = scheduler.CreateHotObservable <int>(
                OnNext(210, 1),
                OnNext(220, 2),
                OnNext(230, 3),
                OnNext(240, 4),
                OnCompleted <int>(250)
                );

            var subject = new MySubject();

            var conn       = new ConnectableObservable <int>(xs, subject);
            var disconnect = conn.Connect();

            var res = scheduler.Start(() => conn);

            res.Messages.AssertEqual(
                OnNext(210, 1),
                OnNext(220, 2),
                OnNext(230, 3),
                OnNext(240, 4),
                OnCompleted <int>(250)
                );
        }
Beispiel #2
0
        public void RefCount_ConnectsOnFirst()
        {
            var scheduler = new TestScheduler();

            var xs = scheduler.CreateHotObservable(
                OnNext(210, 1),
                OnNext(220, 2),
                OnNext(230, 3),
                OnNext(240, 4),
                OnCompleted <int>(250)
                );

            var subject = new MySubject();

            var conn = new ConnectableObservable <int>(xs, subject);

            var res = scheduler.Start(() =>
                                      conn.RefCount()
                                      );

            res.Messages.AssertEqual(
                OnNext(210, 1),
                OnNext(220, 2),
                OnNext(230, 3),
                OnNext(240, 4),
                OnCompleted <int>(250)
                );

            Assert.True(subject.Disposed);
        }
Beispiel #3
0
        public void LazyRefCount_NotConnected()
        {
            var scheduler    = new TestScheduler();
            var disconnected = false;
            var count        = 0;
            var xs           = Observable.Defer(() =>
            {
                count++;
                return(Observable.Create <int>(obs =>
                {
                    return () => { disconnected = true; };
                }));
            });

            var subject = new MySubject();

            var conn = new ConnectableObservable <int>(xs, subject);
            var refd = conn.RefCount(TimeSpan.FromTicks(20), scheduler);

            var dis1 = refd.Subscribe();

            Assert.Equal(1, count);
            Assert.Equal(1, subject.SubscribeCount);
            Assert.False(disconnected);

            var dis2 = refd.Subscribe();

            Assert.Equal(1, count);
            Assert.Equal(2, subject.SubscribeCount);
            Assert.False(disconnected);

            dis1.Dispose();
            Assert.False(disconnected);
            dis2.Dispose();
            Assert.False(disconnected);

            scheduler.AdvanceBy(19);
            Assert.False(disconnected);

            scheduler.AdvanceBy(1);
            Assert.True(disconnected);
            disconnected = false;

            var dis3 = refd.Subscribe();

            Assert.Equal(2, count);
            Assert.Equal(3, subject.SubscribeCount);
            Assert.False(disconnected);

            dis3.Dispose();
            scheduler.AdvanceBy(20);
            Assert.True(disconnected);
        }
        public void ConnectableObservable_Creation()
        {
            var y = 0;

            var s2  = new Subject <int>();
            var co2 = new ConnectableObservable <int>(Observable.Return <int>(1), s2);

            co2.Subscribe(x => y = x);
            Assert.AreNotEqual(1, y);

            co2.Connect();
            Assert.AreEqual(1, y);
        }
Beispiel #5
0
        public void RefCount_NotConnected()
        {
            var disconnected = false;
            var count        = 0;
            var xs           = Observable.Defer(() =>
            {
                count++;
                return(Observable.Create <int>(obs =>
                {
                    return () => { disconnected = true; };
                }));
            });

            var subject = new MySubject();

            var conn = new ConnectableObservable <int>(xs, subject);
            var refd = conn.RefCount();

            var dis1 = refd.Subscribe();

            Assert.Equal(1, count);
            Assert.Equal(1, subject.SubscribeCount);
            Assert.False(disconnected);

            var dis2 = refd.Subscribe();

            Assert.Equal(1, count);
            Assert.Equal(2, subject.SubscribeCount);
            Assert.False(disconnected);

            dis1.Dispose();
            Assert.False(disconnected);
            dis2.Dispose();
            Assert.True(disconnected);
            disconnected = false;

            var dis3 = refd.Subscribe();

            Assert.Equal(2, count);
            Assert.Equal(3, subject.SubscribeCount);
            Assert.False(disconnected);

            dis3.Dispose();
            Assert.True(disconnected);
        }