Esempio n. 1
0
        public void asd()
        {
            var scheduler = new TestScheduler();

            var observer = new MockObserver<int>(scheduler);

            Observable.Range(0, 3, Scheduler.Immediate)
                .Expand(i => (i < 300) ? Observable.Return(i + 100) : Observable.Empty<int>())
                .Subscribe(observer);

            observer.AssertEqual(
                OnNext(0, 0),
                OnNext(0, 1),
                OnNext(0, 2),
                OnNext(0, 100),
                OnNext(0, 101),
                OnNext(0, 102),
                OnNext(0, 200),
                OnNext(0, 201),
                OnNext(0, 202),
                OnNext(0, 300),
                OnNext(0, 301),
                OnNext(0, 302),
                OnCompleted(0)
            );
        }
Esempio n. 2
0
        public void asd()
        {
            var scheduler = new TestScheduler();

            var observer = new MockObserver <int>(scheduler);

            Observable.Range(0, 3, Scheduler.Immediate)
            .Expand(i => (i < 300) ? Observable.Return(i + 100) : Observable.Empty <int>())
            .Subscribe(observer);

            observer.AssertEqual(
                OnNext(0, 0),
                OnNext(0, 1),
                OnNext(0, 2),
                OnNext(0, 100),
                OnNext(0, 101),
                OnNext(0, 102),
                OnNext(0, 200),
                OnNext(0, 201),
                OnNext(0, 202),
                OnNext(0, 300),
                OnNext(0, 301),
                OnNext(0, 302),
                OnCompleted(0)
                );
        }
Esempio n. 3
0
        public void all_streams_are_merged_if_no_concurrent_value_is_supplied()
        {
            var observer = new MockObserver <int>(scheduler);

            Observable.Merge((IObservable <IObservable <int> >)sources.ToObservable())
            .Subscribe(observer);

            scheduler.Run();

            observer.AssertEqual(
                OnNext(5, 0),
                OnNext(10, 10),
                OnNext(15, 20),
                OnNext(25, 1),
                OnNext(30, 11),
                OnNext(35, 21),
                OnNext(45, 2),
                OnNext(50, 12),
                OnNext(55, 22),
                OnNext(65, 3),
                OnNext(70, 13),
                OnNext(75, 23),
                OnNext(85, 4), // sourceA completes, sourceC subscribes
                OnNext(90, 14),
                OnNext(95, 24),
                OnCompleted(95)
                );
        }
Esempio n. 4
0
        public void all_streams_are_merged_if_no_concurrent_value_is_supplied()
        {
            var observer = new MockObserver<int>(scheduler);

            Observable.Merge((IObservable<IObservable<int>>)sources.ToObservable())
                .Subscribe(observer);

            scheduler.Run();

            observer.AssertEqual(
                OnNext(5, 0),
                OnNext(10, 10),
                OnNext(15, 20),
                OnNext(25, 1),
                OnNext(30, 11),
                OnNext(35, 21),
                OnNext(45, 2),
                OnNext(50, 12),
                OnNext(55, 22),
                OnNext(65, 3),
                OnNext(70, 13),
                OnNext(75, 23),
                OnNext(85, 4), // sourceA completes, sourceC subscribes
                OnNext(90, 14),
                OnNext(95, 24),
                OnCompleted(95)
                );
        }
Esempio n. 5
0
        public void Finite()
        {
            var scheduler = new TestScheduler();

            var xs = scheduler.CreateHotObservable(
                OnNext(70, 1),
                OnNext(110, 2),
                OnNext(220, 3),
                OnNext(270, 4),
                OnNext(340, 5),
                OnNext(410, 6),
                OnNext(520, 7),
                OnCompleted <int>(630),
                OnNext(640, 9),
                OnCompleted <int>(650),
                OnError <int>(660, new MockException(1))
                );

            var subject      = default(Subject <int>);
            var subscription = default(IDisposable);

            var results1      = new MockObserver <int>(scheduler);
            var subscription1 = default(IDisposable);

            var results2      = new MockObserver <int>(scheduler);
            var subscription2 = default(IDisposable);

            var results3      = new MockObserver <int>(scheduler);
            var subscription3 = default(IDisposable);

            scheduler.Schedule(() => subject      = new Subject <int>(), 100);
            scheduler.Schedule(() => subscription = xs.Subscribe(subject), 200);
            scheduler.Schedule(() => subscription.Dispose(), 1000);

            scheduler.Schedule(() => subscription1 = subject.Subscribe(results1), 300);
            scheduler.Schedule(() => subscription2 = subject.Subscribe(results2), 400);
            scheduler.Schedule(() => subscription3 = subject.Subscribe(results3), 900);

            scheduler.Schedule(() => subscription1.Dispose(), 600);
            scheduler.Schedule(() => subscription2.Dispose(), 700);
            scheduler.Schedule(() => subscription1.Dispose(), 800);
            scheduler.Schedule(() => subscription3.Dispose(), 950);

            scheduler.Run();

            results1.AssertEqual(
                OnNext(340, 5),
                OnNext(410, 6),
                OnNext(520, 7)
                );

            results2.AssertEqual(
                OnNext(410, 6),
                OnNext(520, 7),
                OnCompleted <int>(630)
                );

            results3.AssertEqual(
                );
        }
Esempio n. 6
0
        public void Infinite()
        {
            var scheduler = new TestScheduler();

            var xs = scheduler.CreateHotObservable(
                OnNext(70, 1),
                OnNext(110, 2),
                OnNext(220, 3),
                OnNext(270, 4),
                OnNext(340, 5),
                OnNext(410, 6),
                OnNext(520, 7),
                OnNext(630, 8),
                OnNext(710, 9),
                OnNext(870, 10),
                OnNext(940, 11),
                OnNext(1020, 12)
                );

            var subject      = default(AsyncSubject <int>);
            var subscription = default(IDisposable);

            var results1      = new MockObserver <int>(scheduler);
            var subscription1 = default(IDisposable);

            var results2      = new MockObserver <int>(scheduler);
            var subscription2 = default(IDisposable);

            var results3      = new MockObserver <int>(scheduler);
            var subscription3 = default(IDisposable);

            scheduler.Schedule(() => subject      = new AsyncSubject <int>(scheduler), 100);
            scheduler.Schedule(() => subscription = xs.Subscribe(subject), 200);
            scheduler.Schedule(() => subscription.Dispose(), 1000);

            scheduler.Schedule(() => subscription1 = subject.Subscribe(results1), 300);
            scheduler.Schedule(() => subscription2 = subject.Subscribe(results2), 400);
            scheduler.Schedule(() => subscription3 = subject.Subscribe(results3), 900);

            scheduler.Schedule(() => subscription1.Dispose(), 600);
            scheduler.Schedule(() => subscription2.Dispose(), 700);
            scheduler.Schedule(() => subscription1.Dispose(), 800);
            scheduler.Schedule(() => subscription3.Dispose(), 950);

            scheduler.Run();

            results1.AssertEqual(
                );

            results2.AssertEqual(
                );

            results3.AssertEqual(
                );
        }
Esempio n. 7
0
        public void Canceled()
        {
            var scheduler = new TestScheduler();

            var xs = scheduler.CreateHotObservable(
                OnCompleted <int>(630),
                OnNext(640, 9),
                OnCompleted <int>(650),
                OnError <int>(660, new MockException(1))
                );

            var subject      = default(BehaviorSubject <int>);
            var subscription = default(IDisposable);

            var results1      = new MockObserver <int>(scheduler);
            var subscription1 = default(IDisposable);

            var results2      = new MockObserver <int>(scheduler);
            var subscription2 = default(IDisposable);

            var results3      = new MockObserver <int>(scheduler);
            var subscription3 = default(IDisposable);

            scheduler.Schedule(() => subject      = new BehaviorSubject <int>(100, scheduler), 100);
            scheduler.Schedule(() => subscription = xs.Subscribe(subject), 200);
            scheduler.Schedule(() => subscription.Dispose(), 1000);

            scheduler.Schedule(() => subscription1 = subject.Subscribe(results1), 300);
            scheduler.Schedule(() => subscription2 = subject.Subscribe(results2), 400);
            scheduler.Schedule(() => subscription3 = subject.Subscribe(results3), 900);

            scheduler.Schedule(() => subscription1.Dispose(), 600);
            scheduler.Schedule(() => subscription2.Dispose(), 700);
            scheduler.Schedule(() => subscription1.Dispose(), 800);
            scheduler.Schedule(() => subscription3.Dispose(), 950);

            scheduler.Run();

            results1.AssertEqual(
                OnNext(301, 100)
                );

            results2.AssertEqual(
                OnNext(401, 100),
                OnCompleted <int>(630)
                );

            results3.AssertEqual(
                OnCompleted <int>(901)
                );
        }
Esempio n. 8
0
        public void Bug_1381()
        {
            var scheduler = new TestScheduler();

            var xs = scheduler.CreateHotObservable(
                OnNext(90, 1),
                OnNext(110, 2),
                OnNext(250, 3),
                OnNext(270, 4),
                OnNext(280, 5),
                OnNext(301, 6),
                OnNext(302, 7),
                OnNext(400, 8),
                OnNext(401, 9),
                OnNext(510, 10)
                );

            var results      = new MockObserver <int>(scheduler);
            var ys           = default(IConnectableObservable <int>);
            var connection   = default(IDisposable);
            var subscription = default(IDisposable);

            scheduler.Schedule(() => ys           = xs.Replay(scheduler), 100);
            scheduler.Schedule(() => connection   = ys.Connect(), 200);
            scheduler.Schedule(() => subscription = ys.Subscribe(results), 300);
            scheduler.Schedule(() => subscription.Dispose(), 500);
            scheduler.Schedule(() => connection.Dispose(), 600);

            scheduler.Run();

            results.AssertEqual(
                OnNext(301, 3),
                OnNext(302, 4),
                OnNext(303, 5),
                OnNext(304, 6),
                OnNext(305, 7),
                OnNext(400, 8),
                OnNext(401, 9)
                );

            xs.Subscriptions.AssertEqual(
                Subscribe(200, 600)
                );
        }
Esempio n. 9
0
        public void latest_value_is_sampled_at_next_sample_time_after_completion()
        {
            var subject = new Subject <int>();

            var scheduler = new TestScheduler();

            var observer = new MockObserver <int>(scheduler);

            scheduler.CreateColdObservable(
                new Recorded <Notification <int> >(5, new Notification <int> .OnNext(0)),
                new Recorded <Notification <int> >(6, new Notification <int> .OnCompleted())
                )
            .Sample(new TimeSpan(15), scheduler)
            .Subscribe(observer);

            scheduler.Run();

            observer.AssertEqual(
                new Recorded <Notification <int> >(15, new Notification <int> .OnNext(0)),
                new Recorded <Notification <int> >(15, new Notification <int> .OnCompleted())
                );
        }
Esempio n. 10
0
        public void recursively_expands_values_and_merges()
        {
            var scheduler = new TestScheduler();

            var observer = new MockObserver <int>(scheduler);

            scheduler.CreateColdObservable(
                OnNext(5, 0),
                OnNext(10, 1),
                OnNext(15, 2),
                OnCompleted(15)
                )
            .Expand(i => (i < 300)
                ? scheduler.CreateColdObservable(
                        OnNext(5, i + 100),
                        OnCompleted(5))
                : Observable.Empty <int>()
                    )
            .Subscribe(observer);

            scheduler.Run();

            observer.AssertEqual(
                OnNext(5, 0),
                OnNext(10, 1),
                OnNext(10, 100),
                OnNext(15, 2),
                OnNext(15, 101),
                OnNext(15, 200),
                OnNext(20, 102),
                OnNext(20, 201),
                OnNext(20, 300),
                OnNext(25, 202),
                OnNext(25, 301),
                OnNext(30, 302),
                OnCompleted(30)
                );
        }
Esempio n. 11
0
        public void recursively_expands_values_and_merges()
        {
            var scheduler = new TestScheduler();

            var observer = new MockObserver<int>(scheduler);

            scheduler.CreateColdObservable(
                OnNext(5, 0),
                OnNext(10, 1),
                OnNext(15, 2),
                OnCompleted(15)
            )
            .Expand(i => (i < 300)
                ? scheduler.CreateColdObservable(
                    OnNext(5, i + 100),
                    OnCompleted(5))
                : Observable.Empty<int>()
            )
            .Subscribe(observer);

            scheduler.Run();

            observer.AssertEqual(
                OnNext(5, 0),
                OnNext(10, 1),
                OnNext(10, 100),
                OnNext(15, 2),
                OnNext(15, 101),
                OnNext(15, 200),
                OnNext(20, 102),
                OnNext(20, 201),
                OnNext(20, 300),
                OnNext(25, 202),
                OnNext(25, 301),
                OnNext(30, 302),
                OnCompleted(30)
            );
        }
Esempio n. 12
0
        public void concurrent_messages_are_merged()
        {
            var observer = new MockObserver<int>(scheduler);

            Observable.Merge(sources.ToObservable(), 2)
                .Subscribe(observer);

            scheduler.Run();

            observer.AssertEqual(
                OnNext(5, 0),
                OnNext(10, 10),
                OnNext(25, 1),
                OnNext(30, 11),
                OnNext(45, 2),
                OnNext(50, 12),
                OnNext(65, 3),
                OnNext(70, 13),
                OnNext(85, 4), // sourceA completes, sourceC subscribes
                OnNext(90, 14),
                OnNext(95, 24),
                OnCompleted(95)
                );
        }
Esempio n. 13
0
        public void concurrent_messages_are_merged()
        {
            var observer = new MockObserver <int>(scheduler);

            Observable.Merge(sources.ToObservable(), 2)
            .Subscribe(observer);

            scheduler.Run();

            observer.AssertEqual(
                OnNext(5, 0),
                OnNext(10, 10),
                OnNext(25, 1),
                OnNext(30, 11),
                OnNext(45, 2),
                OnNext(50, 12),
                OnNext(65, 3),
                OnNext(70, 13),
                OnNext(85, 4), // sourceA completes, sourceC subscribes
                OnNext(90, 14),
                OnNext(95, 24),
                OnCompleted(95)
                );
        }
Esempio n. 14
0
        public void latest_value_is_sampled_at_next_sample_time_after_completion()
        {
            var subject = new Subject<int>();

            var scheduler = new TestScheduler();

            var observer = new MockObserver<int>(scheduler);

            scheduler.CreateColdObservable(
                new Recorded<Notification<int>>(5, new Notification<int>.OnNext(0)),
                new Recorded<Notification<int>>(6, new Notification<int>.OnCompleted())
                )
                .Sample(new TimeSpan(15), scheduler)
                .Subscribe(observer);

            scheduler.Run();

            observer.AssertEqual(
                new Recorded<Notification<int>>(15, new Notification<int>.OnNext(0)),
                new Recorded<Notification<int>>(15, new Notification<int>.OnCompleted())
                );
        }
Esempio n. 15
0
        public void Infinite()
        {
            var scheduler = new TestScheduler();

            var xs = scheduler.CreateHotObservable(
                OnNext(70, 1),
                OnNext(110, 2),
                OnNext(220, 3),
                OnNext(270, 4),
                OnNext(340, 5),
                OnNext(410, 6),
                OnNext(520, 7),
                OnNext(630, 8),
                OnNext(710, 9),
                OnNext(870, 10),
                OnNext(940, 11),
                OnNext(1020, 12)
                );

            var subject = default(ReplaySubject<int>);
            var subscription = default(IDisposable);

            var results1 = new MockObserver<int>(scheduler);
            var subscription1 = default(IDisposable);

            var results2 = new MockObserver<int>(scheduler);
            var subscription2 = default(IDisposable);

            var results3 = new MockObserver<int>(scheduler);
            var subscription3 = default(IDisposable);

            scheduler.Schedule(() => subject = new ReplaySubject<int>(3, TimeSpan.FromTicks(100), scheduler), 100);
            scheduler.Schedule(() => subscription = xs.Subscribe(subject), 200);
            scheduler.Schedule(() => subscription.Dispose(), 1000);

            scheduler.Schedule(() => subscription1 = subject.Subscribe(results1), 300);
            scheduler.Schedule(() => subscription2 = subject.Subscribe(results2), 400);
            scheduler.Schedule(() => subscription3 = subject.Subscribe(results3), 900);

            scheduler.Schedule(() => subscription1.Dispose(), 600);
            scheduler.Schedule(() => subscription2.Dispose(), 700);
            scheduler.Schedule(() => subscription1.Dispose(), 800);
            scheduler.Schedule(() => subscription3.Dispose(), 950);

            scheduler.Run();

            results1.AssertEqual(
                OnNext(301, 3),
                OnNext(302, 4),
                OnNext(340, 5),
                OnNext(410, 6),
                OnNext(520, 7)
                );

            results2.AssertEqual(
                OnNext(401, 5),
                OnNext(410, 6),
                OnNext(520, 7),
                OnNext(630, 8)
                );

            results3.AssertEqual(
                OnNext(901, 10),
                OnNext(940, 11)
                );
        }
Esempio n. 16
0
        public void Canceled()
        {
            var scheduler = new TestScheduler();

            var xs = scheduler.CreateHotObservable(
                OnCompleted<int>(630),
                OnNext(640, 9),
                OnCompleted<int>(650),
                OnError<int>(660, new MockException(1))
                );

            var subject = default(ReplaySubject<int>);
            var subscription = default(IDisposable);

            var results1 = new MockObserver<int>(scheduler);
            var subscription1 = default(IDisposable);

            var results2 = new MockObserver<int>(scheduler);
            var subscription2 = default(IDisposable);

            var results3 = new MockObserver<int>(scheduler);
            var subscription3 = default(IDisposable);

            scheduler.Schedule(() => subject = new ReplaySubject<int>(3, TimeSpan.FromTicks(100), scheduler), 100);
            scheduler.Schedule(() => subscription = xs.Subscribe(subject), 200);
            scheduler.Schedule(() => subscription.Dispose(), 1000);

            scheduler.Schedule(() => subscription1 = subject.Subscribe(results1), 300);
            scheduler.Schedule(() => subscription2 = subject.Subscribe(results2), 400);
            scheduler.Schedule(() => subscription3 = subject.Subscribe(results3), 900);

            scheduler.Schedule(() => subscription1.Dispose(), 600);
            scheduler.Schedule(() => subscription2.Dispose(), 700);
            scheduler.Schedule(() => subscription1.Dispose(), 800);
            scheduler.Schedule(() => subscription3.Dispose(), 950);

            scheduler.Run();

            results1.AssertEqual(
                );

            results2.AssertEqual(
                OnCompleted<int>(630)
                );

            results3.AssertEqual(
                );
        }
Esempio n. 17
0
        public void Finite()
        {
            var scheduler = new TestScheduler();

            var xs = scheduler.CreateHotObservable(
                OnNext(70, 1),
                OnNext(110, 2),
                OnNext(220, 3),
                OnNext(270, 4),
                OnNext(340, 5),
                OnNext(410, 6),
                OnNext(520, 7),
                OnCompleted<int>(630),
                OnNext(640, 9),
                OnCompleted<int>(650),
                OnError<int>(660, new MockException(1))
                );

            var subject = default(Subject<int>);
            var subscription = default(IDisposable);

            var results1 = new MockObserver<int>(scheduler);
            var subscription1 = default(IDisposable);

            var results2 = new MockObserver<int>(scheduler);
            var subscription2 = default(IDisposable);

            var results3 = new MockObserver<int>(scheduler);
            var subscription3 = default(IDisposable);

            scheduler.Schedule(() => subject = new Subject<int>(), 100);
            scheduler.Schedule(() => subscription = xs.Subscribe(subject), 200);
            scheduler.Schedule(() => subscription.Dispose(), 1000);

            scheduler.Schedule(() => subscription1 = subject.Subscribe(results1), 300);
            scheduler.Schedule(() => subscription2 = subject.Subscribe(results2), 400);
            scheduler.Schedule(() => subscription3 = subject.Subscribe(results3), 900);

            scheduler.Schedule(() => subscription1.Dispose(), 600);
            scheduler.Schedule(() => subscription2.Dispose(), 700);
            scheduler.Schedule(() => subscription1.Dispose(), 800);
            scheduler.Schedule(() => subscription3.Dispose(), 950);

            scheduler.Run();

            results1.AssertEqual(
                OnNext(340, 5),
                OnNext(410, 6),
                OnNext(520, 7)
                );

            results2.AssertEqual(
                OnNext(410, 6),
                OnNext(520, 7),
                OnCompleted<int>(630)
                );

            results3.AssertEqual(
                );
        }
Esempio n. 18
0
        public void Bug_1381()
        {
            var scheduler = new TestScheduler();

            var xs = scheduler.CreateHotObservable(
                OnNext( 90, 1),
                OnNext(110, 2),
                OnNext(250, 3),
                OnNext(270, 4),
                OnNext(280, 5),
                OnNext(301, 6),
                OnNext(302, 7),
                OnNext(400, 8),
                OnNext(401, 9),
                OnNext(510, 10)
                );

            var results = new MockObserver<int>(scheduler);
            var ys = default(IConnectableObservable<int>);
            var connection = default(IDisposable);
            var subscription = default(IDisposable);

            scheduler.Schedule(() => ys = xs.Replay(scheduler), 100);
            scheduler.Schedule(() => connection = ys.Connect(), 200);
            scheduler.Schedule(() => subscription = ys.Subscribe(results), 300);
            scheduler.Schedule(() => subscription.Dispose(), 500);
            scheduler.Schedule(() => connection.Dispose(), 600);

            scheduler.Run();

            results.AssertEqual(
                OnNext(301, 3),
                OnNext(302, 4),
                OnNext(303, 5),
                OnNext(304, 6),
                OnNext(305, 7),
                OnNext(400, 8),
                OnNext(401, 9)
                );

            xs.Subscriptions.AssertEqual(
                Subscribe(200, 600)
                );
        }