RunNext() public method

public RunNext ( ) : void
return void
Exemplo n.º 1
1
        public void interval_is_cancelled_on_completion()
        {
            var subject = new Subject<int>();

            var stats = new StatsObserver<int>();

            var scheduler = new ManualScheduler();

            subject
                .Sample(TimeSpan.FromSeconds(1), scheduler)
                .Subscribe(stats);

            subject.OnNext(0);
            subject.OnCompleted();
            scheduler.RunNext();

            Assert.AreEqual(0, scheduler.QueueSize);
        }
Exemplo n.º 2
0
        public void each_subscriber_is_scheduled_individually()
        {
            ManualScheduler scheduler = new ManualScheduler();

            AsyncSubject<int> subject = new AsyncSubject<int>(scheduler);

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

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);
            subject.OnCompleted();

            subject.Subscribe(statsA);
            subject.Subscribe(statsB);

            scheduler.RunNext();

            Assert.IsTrue(statsA.NextCalled);
            Assert.IsFalse(statsB.NextCalled);

            scheduler.RunNext();

            Assert.IsTrue(statsB.NextCalled);
        }
Exemplo n.º 3
0
        public void scheduler_used_to_subscribe_to_each_sequence()
        {
            var stats = new StatsObserver<int>();

            var scheduler = new ManualScheduler();

            var subjectA = new StatsSubject<int>();
            var subjectB = new StatsSubject<int>();
            var subjectC = new StatsSubject<int>();

            Observable.Merge(
                scheduler,
                subjectA,
                subjectB,
                subjectC
                )
                .Subscribe(stats);

            Assert.AreEqual(1, scheduler.QueueSize);
            scheduler.RunNext();

            Assert.IsTrue(subjectA.HasSubscriptions);
            Assert.IsFalse(subjectB.HasSubscriptions);

            Assert.AreEqual(1, scheduler.QueueSize);
            scheduler.RunNext();

            Assert.IsTrue(subjectB.HasSubscriptions);
            Assert.IsFalse(subjectC.HasSubscriptions);

            Assert.AreEqual(1, scheduler.QueueSize);
            scheduler.RunNext();

            Assert.IsTrue(subjectC.HasSubscriptions);

            Assert.AreEqual(1, scheduler.QueueSize);
            scheduler.RunNext();

            Assert.AreEqual(0, scheduler.QueueSize);
        }
Exemplo n.º 4
0
        public void completion_occurs_after_interval()
        {
            var scheduler = new ManualScheduler();
            var stats = new StatsObserver<int>();

            Observable.Empty<int>()
                .Sample(TimeSpan.FromSeconds(1), scheduler)
                .Subscribe(stats);

            Assert.IsFalse(stats.CompletedCalled);

            scheduler.RunNext();
            Assert.IsTrue(stats.CompletedCalled);
        }
Exemplo n.º 5
0
        public void next_and_complete_are_scheduled_separately()
        {
            ManualScheduler scheduler = new ManualScheduler();

            AsyncSubject<int> subject = new AsyncSubject<int>(scheduler);

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

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);
            subject.OnCompleted();

            subject.Subscribe(statsA);

            Assert.AreEqual(1, scheduler.QueueSize);
            scheduler.RunNext();
            Assert.IsTrue(statsA.NextCalled);
            Assert.IsFalse(statsA.CompletedCalled);

            Assert.AreEqual(1, scheduler.QueueSize);
            scheduler.RunNext();
            Assert.IsTrue(statsA.CompletedCalled);
        }
Exemplo n.º 6
0
        public void errors_are_sent_through_scheduler()
        {
            ManualScheduler scheduler = new ManualScheduler();

            ReplaySubject<int> subject = new ReplaySubject<int>(scheduler);

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.OnError(new Exception());

            subject.Subscribe(stats);

            Assert.IsFalse(stats.ErrorCalled);

            scheduler.RunNext();
            Assert.IsTrue(stats.ErrorCalled);
        }
Exemplo n.º 7
0
        public void default_value_is_sent_through_scheduler()
        {
            ManualScheduler scheduler = new ManualScheduler();

            BehaviorSubject<int> subject = new BehaviorSubject<int>(0, scheduler);

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.Subscribe(stats);

            Assert.IsFalse(stats.NextCalled);

            scheduler.RunNext();
            Assert.AreEqual(1, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0 }));
            Assert.IsFalse(stats.CompletedCalled);
        }
Exemplo n.º 8
0
        public void complete_is_sent_through_scheduler()
        {
            ManualScheduler scheduler = new ManualScheduler();

            BehaviorSubject<int> subject = new BehaviorSubject<int>(0, scheduler);

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.OnCompleted();

            subject.Subscribe(stats);

            Assert.IsFalse(stats.NextCalled);

            scheduler.RunNext();
            Assert.AreEqual(0, stats.NextCount);
            Assert.IsTrue(stats.CompletedCalled);
        }
Exemplo n.º 9
0
        public void scheduler_is_used_to_distribute_values()
        {
            ManualScheduler scheduler = new ManualScheduler();

            AsyncSubject<int> subject = new AsyncSubject<int>(scheduler);

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

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);
            subject.OnCompleted();

            subject.Subscribe(statsA);

            Assert.IsFalse(statsA.NextCalled);

            scheduler.RunNext();

            Assert.IsTrue(statsA.NextCalled);
        }
Exemplo n.º 10
0
        public void scheduler_is_not_used_to_sent_complete()
        {
            Subject<int> subject = new Subject<int>();

            var scheduler = new ManualScheduler();

            var stats = new StatsObserver<int>();

            var obs = subject.Prune(scheduler);
            var connection = obs.Connect();

            subject.OnNext(1);
            subject.OnCompleted();

            obs.Subscribe(stats);

            scheduler.RunNext(); // only run one

            Assert.IsTrue(stats.NextCalled);

            scheduler.RunNext(); // only run one

            Assert.IsTrue(stats.CompletedCalled); // complete is called anyway
        }
Exemplo n.º 11
0
        public void values_cannot_be_replayed_out_of_order()
        {
            ManualScheduler scheduler = new ManualScheduler();

            ReplaySubject<int> subject = new ReplaySubject<int>(scheduler);

            StatsObserver<int> stats = new StatsObserver<int>();

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

            subject.Subscribe(stats);

            Assert.IsFalse(stats.NextCalled);

            scheduler.RunNext();
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 1 }));

            subject.OnNext(3);

            scheduler.RunNext();
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 1, 2 }));

            scheduler.RunNext();
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 1, 2, 3 }));

            subject.OnCompleted();

            scheduler.RunNext();
            Assert.IsTrue(stats.CompletedCalled);
        }
Exemplo n.º 12
0
        public void replayed_values_are_sent_through_scheduler()
        {
            ManualScheduler scheduler = new ManualScheduler();

            ReplaySubject<int> subject = new ReplaySubject<int>(scheduler);

            StatsObserver<int> stats = new StatsObserver<int>();

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

            subject.Subscribe(stats);

            Assert.IsFalse(stats.NextCalled);

            scheduler.RunNext();
            Assert.AreEqual(1, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 1 }));
            Assert.IsFalse(stats.CompletedCalled);

            scheduler.RunNext();
            Assert.AreEqual(2, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 1, 2 }));
            Assert.IsFalse(stats.CompletedCalled);

            scheduler.RunNext();
            Assert.IsTrue(stats.CompletedCalled);
        }
Exemplo n.º 13
0
        public void uses_scheduler_to_schedule_samples()
        {
            var subject = new Subject<int>();

            var stats = new StatsObserver<int>();

            var scheduler = new ManualScheduler();

            subject
                .Sample(TimeSpan.FromSeconds(1), scheduler)
                .Subscribe(stats);

            Assert.AreEqual(1, scheduler.QueueSize);

            subject.OnNext(0);
            scheduler.RunNext();

            Assert.AreEqual(1, scheduler.QueueSize);
            Assert.AreEqual(1, stats.NextCount);
            Assert.AreEqual(0, stats.NextValues[0]);
        }
Exemplo n.º 14
0
        public void no_value_is_emitted_if_sampled_value_hasnt_changed()
        {
            var subject = new Subject<int>();

            var stats = new StatsObserver<int>();

            var scheduler = new ManualScheduler();

            subject
                .Sample(TimeSpan.FromSeconds(1), scheduler)
                .Subscribe(stats);

            stats.OnNext(0);

            scheduler.RunNext();
            scheduler.RunNext();

            Assert.AreEqual(1, stats.NextCount);
        }
Exemplo n.º 15
0
        public void last_value_is_taken_for_each_sample()
        {
            var subject = new Subject<int>();

            var stats = new StatsObserver<int>();

            var scheduler = new ManualScheduler();

            subject
                .Sample(TimeSpan.FromSeconds(1), scheduler)
                .Subscribe(stats);

            subject.OnNext(0);
            subject.OnNext(1);
            scheduler.RunNext();

            subject.OnNext(2);
            subject.OnNext(3);
            scheduler.RunNext();

            Assert.AreEqual(2, stats.NextCount);
            Assert.AreEqual(1, stats.NextValues[0]);
            Assert.AreEqual(3, stats.NextValues[1]);
        }