Beispiel #1
0
        public void scheduler_is_not_used_when_count_great_than_zero()
        {
            var scheduler = new ManualScheduler();

            var subject = new StatsSubject <int>();

            var stats = new StatsObserver <int>();

            subject.Take(3, scheduler).Subscribe(stats);

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

            Assert.AreEqual(0, scheduler.QueueSize);
        }
Beispiel #2
0
        public void scheduler_is_not_used_when_count_great_than_zero()
        {
            var scheduler = new ManualScheduler();

            var subject = new StatsSubject<int>();

            var stats = new StatsObserver<int>();

            subject.Take(3, scheduler).Subscribe(stats);

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

            Assert.AreEqual(0, scheduler.QueueSize);
        }
Beispiel #3
0
        public void last_value_is_still_used_after_complete()
        {
            StatsSubject <int> subjectA = new StatsSubject <int>();
            StatsSubject <int> subjectB = new StatsSubject <int>();

            var stats = new StatsObserver <string>();

            subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString()))
            .Subscribe(stats);

            subjectA.OnNext(1);
            subjectA.OnCompleted();

            subjectB.OnNext(2);
            subjectB.OnNext(3);

            Assert.AreEqual(2, stats.NextCount);
            Assert.AreEqual("1,2", stats.NextValues[0]);
            Assert.AreEqual("1,3", stats.NextValues[1]);
            Assert.IsFalse(stats.CompletedCalled);
        }
Beispiel #4
0
        public void reuses_values()
        {
            StatsSubject <int> subjectA = new StatsSubject <int>();
            StatsSubject <int> subjectB = new StatsSubject <int>();

            var stats = new StatsObserver <string>();

            subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString()))
            .Subscribe(stats);

            subjectA.OnNext(1);
            subjectB.OnNext(2);
            subjectA.OnNext(3);
            subjectB.OnNext(4);

            Assert.AreEqual(3, stats.NextCount);
            Assert.AreEqual("1,2", stats.NextValues[0]);
            Assert.AreEqual("3,2", stats.NextValues[1]);
            Assert.AreEqual("3,4", stats.NextValues[2]);
            Assert.IsFalse(stats.CompletedCalled);
        }
Beispiel #5
0
        public void operations_are_passed_on_once_connected()
        {
            StatsObserver <int> stats = new StatsObserver <int>();

            StatsSubject <int> source  = new StatsSubject <int>();
            StatsSubject <int> subject = new StatsSubject <int>();

            ConnectableObservable <int> connectable = new ConnectableObservable <int>(source, subject);

            var sub = connectable.Subscribe(stats);

            source.OnNext(0);

            connectable.Connect();

            source.OnNext(1);

            Assert.IsTrue(stats.NextCalled);
            Assert.AreEqual(1, stats.NextValues[0]);
            Assert.IsFalse(stats.CompletedCalled);
            Assert.IsFalse(stats.ErrorCalled);
        }
Beispiel #6
0
        public void operation_order_is_honoured_prior_to_connection()
        {
            StatsObserver <int> stats = new StatsObserver <int>();

            StatsSubject <int> source  = new StatsSubject <int>();
            StatsSubject <int> subject = new StatsSubject <int>();

            ConnectableObservable <int> connectable = new ConnectableObservable <int>(source, subject);

            var sub = connectable.Subscribe(stats);

            source.OnNext(0);
            source.OnCompleted();

            connectable.Connect();

            source.OnNext(1);

            Assert.IsFalse(stats.NextCalled);
            Assert.IsFalse(stats.CompletedCalled);
            Assert.IsFalse(stats.ErrorCalled);
        }
Beispiel #7
0
        public void emits_combinations_of_the_latest_values()
        {
            StatsSubject <int> subjectA = new StatsSubject <int>();
            StatsSubject <int> subjectB = new StatsSubject <int>();

            var stats = new StatsObserver <string>();

            subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString()))
            .Subscribe(stats);

            subjectA.OnNext(1);
            subjectB.OnNext(2);

            Assert.AreEqual(1, stats.NextCount);
            Assert.AreEqual("1,2", stats.NextValues[0]);
            Assert.IsFalse(stats.CompletedCalled);
        }
        public void emits_combinations_of_the_latest_values()
        {
            StatsSubject<int> subjectA = new StatsSubject<int>();
            StatsSubject<int> subjectB = new StatsSubject<int>();

            var stats = new StatsObserver<string>();

            subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString()))
                .Subscribe(stats);

            subjectA.OnNext(1);
            subjectB.OnNext(2);

            Assert.AreEqual(1, stats.NextCount);
            Assert.AreEqual("1,2", stats.NextValues[0]);
            Assert.IsFalse(stats.CompletedCalled);
        }
Beispiel #9
0
        public void values_are_received_by_all_subscriptions()
        {
            var subject = new StatsSubject <int>();

            var statsA = new StatsObserver <int>();
            var statsB = new StatsObserver <int>();

            var refCount = subject.Publish().RefCount();

            var subscriptionA = refCount.Subscribe(statsA);
            var subscriptionB = refCount.Subscribe(statsB);

            subject.OnNext(0);

            Assert.AreEqual(1, statsA.NextCount);
            Assert.AreEqual(1, statsB.NextCount);
        }
Beispiel #10
0
        public void values_send_before_completion_are_ignored()
        {
            StatsObserver <int> stats = new StatsObserver <int>();

            StatsSubject <int> source  = new StatsSubject <int>();
            StatsSubject <int> subject = new StatsSubject <int>();

            ConnectableObservable <int> connectable = new ConnectableObservable <int>(source, subject);

            var sub = connectable.Subscribe(stats);

            source.OnNext(0);
            source.OnCompleted();
            source.OnError(new Exception());

            Assert.IsFalse(stats.NextCalled);
            Assert.IsFalse(stats.CompletedCalled);
            Assert.IsFalse(stats.ErrorCalled);
        }
Beispiel #11
0
        public void complete_is_fired_when_both_sequences_complete()
        {
            StatsSubject <int> subjectA = new StatsSubject <int>();
            StatsSubject <int> subjectB = new StatsSubject <int>();

            var stats = new StatsObserver <string>();

            subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString()))
            .Subscribe(stats);

            subjectA.OnNext(1);
            subjectA.OnCompleted();

            subjectB.OnNext(2);
            subjectB.OnCompleted();

            Assert.AreEqual(1, stats.NextCount);
            Assert.AreEqual("1,2", stats.NextValues[0]);
            Assert.IsTrue(stats.CompletedCalled);
        }
        public void complete_is_fired_when_both_sequences_complete()
        {
            StatsSubject<int> subjectA = new StatsSubject<int>();
            StatsSubject<int> subjectB = new StatsSubject<int>();

            var stats = new StatsObserver<string>();

            subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString()))
                .Subscribe(stats);

            subjectA.OnNext(1);
            subjectA.OnCompleted();

            subjectB.OnNext(2);
            subjectB.OnCompleted();

            Assert.AreEqual(1, stats.NextCount);
            Assert.AreEqual("1,2", stats.NextValues[0]);
            Assert.IsTrue(stats.CompletedCalled);
        }
        public void operations_are_passed_on_once_connected()
        {
            StatsObserver<int> stats = new StatsObserver<int>();

            StatsSubject<int> source = new StatsSubject<int>();
            StatsSubject<int> subject = new StatsSubject<int>();

            ConnectableObservable<int> connectable = new ConnectableObservable<int>(source, subject);

            var sub = connectable.Subscribe(stats);

            source.OnNext(0);

            connectable.Connect();

            source.OnNext(1);

            Assert.IsTrue(stats.NextCalled);
            Assert.AreEqual(1, stats.NextValues[0]);
            Assert.IsFalse(stats.CompletedCalled);
            Assert.IsFalse(stats.ErrorCalled);
        }
        public void last_value_is_still_used_after_complete()
        {
            StatsSubject<int> subjectA = new StatsSubject<int>();
            StatsSubject<int> subjectB = new StatsSubject<int>();

            var stats = new StatsObserver<string>();

            subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString()))
                .Subscribe(stats);

            subjectA.OnNext(1);
            subjectA.OnCompleted();

            subjectB.OnNext(2);
            subjectB.OnNext(3);

            Assert.AreEqual(2, stats.NextCount);
            Assert.AreEqual("1,2", stats.NextValues[0]);
            Assert.AreEqual("1,3", stats.NextValues[1]);
            Assert.IsFalse(stats.CompletedCalled);
        }
        public void reuses_values()
        {
            StatsSubject<int> subjectA = new StatsSubject<int>();
            StatsSubject<int> subjectB = new StatsSubject<int>();

            var stats = new StatsObserver<string>();

            subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString()))
                .Subscribe(stats);

            subjectA.OnNext(1);
            subjectB.OnNext(2);
            subjectA.OnNext(3);
            subjectB.OnNext(4);

            Assert.AreEqual(3, stats.NextCount);
            Assert.AreEqual("1,2", stats.NextValues[0]);
            Assert.AreEqual("3,2", stats.NextValues[1]);
            Assert.AreEqual("3,4", stats.NextValues[2]);
            Assert.IsFalse(stats.CompletedCalled);
        }
        public void operation_order_is_honoured_prior_to_connection()
        {
            StatsObserver<int> stats = new StatsObserver<int>();

            StatsSubject<int> source = new StatsSubject<int>();
            StatsSubject<int> subject = new StatsSubject<int>();

            ConnectableObservable<int> connectable = new ConnectableObservable<int>(source, subject);

            var sub = connectable.Subscribe(stats);

            source.OnNext(0);
            source.OnCompleted();

            connectable.Connect();

            source.OnNext(1);

            Assert.IsFalse(stats.NextCalled);
            Assert.IsFalse(stats.CompletedCalled);
            Assert.IsFalse(stats.ErrorCalled);
        }
Beispiel #17
0
        public void values_are_not_received_by_unsubscribed_observers()
        {
            var subject = new StatsSubject<int>();

            var statsA = new StatsObserver<int>();
            var statsB = new StatsObserver<int>();

            var refCount = subject.Publish().RefCount();

            var subscriptionA = refCount.Subscribe(statsA);
            refCount.Subscribe(statsB).Dispose();

            subject.OnNext(0);

            Assert.AreEqual(1, statsA.NextCount);
            Assert.AreEqual(0, statsB.NextCount);
        }
        public void values_send_before_completion_are_ignored()
        {
            StatsObserver<int> stats = new StatsObserver<int>();

            StatsSubject<int> source = new StatsSubject<int>();
            StatsSubject<int> subject = new StatsSubject<int>();

            ConnectableObservable<int> connectable = new ConnectableObservable<int>(source, subject);

            var sub = connectable.Subscribe(stats);

            source.OnNext(0);
            source.OnCompleted();
            source.OnError(new Exception());

            Assert.IsFalse(stats.NextCalled);
            Assert.IsFalse(stats.CompletedCalled);
            Assert.IsFalse(stats.ErrorCalled);
        }
Beispiel #19
0
        public void values_are_emitted_during_open_windows()
        {
            left.OnNext(0);
            right.OnNext(0);
            right.OnNext(1);

            left.OnNext(1);
            right.OnNext(2);

            Assert.AreEqual(new string[]
            {
                "0,0", "0,1", "1,0", "1,1", "0,2", "1,2"
            }, stats.NextValues);
        }
Beispiel #20
0
        public void values_can_be_emitted_from_the_right_first()
        {
            right.OnNext(0);
            left.OnNext(0);

            left.OnNext(1);
            right.OnNext(1);

            Assert.AreEqual(new string[]
            {
                "0,0", "1,0", "0,1", "1,1"
            }, stats.NextValues);
        }