예제 #1
0
        public void Case_ArgumentChecking()
        {
            ReactiveAssert.Throws <ArgumentNullException>(() => Observable.Case(null, new Dictionary <int, IObservable <int> >(), DummyObservable <int> .Instance));
            ReactiveAssert.Throws <ArgumentNullException>(() => Observable.Case(DummyFunc <int> .Instance, null, DummyObservable <int> .Instance));
            ReactiveAssert.Throws <ArgumentNullException>(() => Observable.Case(DummyFunc <int> .Instance, new Dictionary <int, IObservable <int> >(), default(IObservable <int>)));

            ReactiveAssert.Throws <ArgumentNullException>(() => Observable.Case(null, new Dictionary <int, IObservable <int> >(), DummyScheduler.Instance));
            ReactiveAssert.Throws <ArgumentNullException>(() => Observable.Case <int, int>(DummyFunc <int> .Instance, null, DummyScheduler.Instance));
            ReactiveAssert.Throws <ArgumentNullException>(() => Observable.Case(DummyFunc <int> .Instance, new Dictionary <int, IObservable <int> >(), default(IScheduler)));

            ReactiveAssert.Throws <ArgumentNullException>(() => Observable.Case(null, new Dictionary <int, IObservable <int> >()));
            ReactiveAssert.Throws <ArgumentNullException>(() => Observable.Case <int, int>(DummyFunc <int> .Instance, null));
        }
예제 #2
0
        public void Case_Two()
        {
            var scheduler = new TestScheduler();

            var xs = scheduler.CreateHotObservable(
                OnNext(210, 1),
                OnNext(240, 2),
                OnNext(270, 3),
                OnCompleted <int>(300)
                );

            var ys = scheduler.CreateHotObservable(
                OnNext(220, 11),
                OnNext(250, 12),
                OnNext(280, 13),
                OnCompleted <int>(310)
                );

            var zs = scheduler.CreateHotObservable(
                OnNext(230, 21),
                OnNext(240, 22),
                OnNext(290, 23),
                OnCompleted <int>(320)
                );

            var map = new Dictionary <int, IObservable <int> >
            {
                { 1, xs },
                { 2, ys }
            };

            var results = scheduler.Start(() => Observable.Case(() => 2, map, zs));

            results.Messages.AssertEqual(
                OnNext(220, 11),
                OnNext(250, 12),
                OnNext(280, 13),
                OnCompleted <int>(310)
                );

            xs.Subscriptions.AssertEqual(
                );

            ys.Subscriptions.AssertEqual(
                Subscribe(200, 310)
                );

            zs.Subscriptions.AssertEqual(
                );
        }
예제 #3
0
        public void empty_is_returned_if_lookup_key_is_invalid()
        {
            Dictionary <string, IObservable <int> > dictionary = new Dictionary <string, IObservable <int> >()
            {
                { "keyA", Observable.Return(1) },
                { "keyB", Observable.Return(2) },
                { "keyC", Observable.Return(3) }
            };

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

            Observable.Case(() => "keyD", dictionary)
            .Subscribe(stats);

            Assert.IsFalse(stats.NextCalled);
            Assert.IsTrue(stats.CompletedCalled);
        }
예제 #4
0
        public void lookup_value_is_subscribed_to()
        {
            Dictionary <string, IObservable <int> > dictionary = new Dictionary <string, IObservable <int> >()
            {
                { "keyA", Observable.Return(1) },
                { "keyB", Observable.Return(2) },
                { "keyC", Observable.Return(3) }
            };

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

            Observable.Case(() => "keyB", dictionary)
            .Subscribe(stats);

            Assert.AreEqual(1, stats.NextCount);
            Assert.AreEqual(2, stats.NextValues[0]);
            Assert.IsTrue(stats.CompletedCalled);
        }
예제 #5
0
        public void error_is_raised_if_selector_throws_exception()
        {
            Dictionary <string, IObservable <int> > dictionary = new Dictionary <string, IObservable <int> >()
            {
                { "keyA", Observable.Return(1) },
                { "keyB", Observable.Return(2) },
                { "keyC", Observable.Return(3) }
            };

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

            Exception exception = new ArgumentException();

            Observable.Case(() => { throw exception; }, dictionary)
            .Subscribe(stats);

            Assert.IsTrue(stats.ErrorCalled);
            Assert.AreEqual(exception, stats.Error);
        }
예제 #6
0
        public void Case_Error()
        {
            var scheduler = new TestScheduler();

            var ex = new Exception();

            var xs = scheduler.CreateHotObservable(
                OnNext(210, 1),
                OnNext(240, 2),
                OnNext(270, 3),
                OnError <int>(300, ex)
                );

            var ys = scheduler.CreateHotObservable(
                OnNext(220, 11),
                OnNext(250, 12),
                OnNext(280, 13),
                OnCompleted <int>(310)
                );

            var map = new Dictionary <int, IObservable <int> >
            {
                { 1, xs },
                { 2, ys }
            };

            var results = scheduler.Start(() => Observable.Case(() => 1, map, scheduler));

            results.Messages.AssertEqual(
                OnNext(210, 1),
                OnNext(240, 2),
                OnNext(270, 3),
                OnError <int>(300, ex)
                );

            xs.Subscriptions.AssertEqual(
                Subscribe(200, 300)
                );

            ys.Subscriptions.AssertEqual(
                );
        }
예제 #7
0
        public void CaseWithDefault_Three()
        {
            var scheduler = new TestScheduler();

            var xs = scheduler.CreateHotObservable(
                OnNext(210, 1),
                OnNext(240, 2),
                OnNext(270, 3),
                OnCompleted <int>(300)
                );

            var ys = scheduler.CreateHotObservable(
                OnNext(220, 11),
                OnNext(250, 12),
                OnNext(280, 13),
                OnCompleted <int>(310)
                );

            var map = new Dictionary <int, IObservable <int> >
            {
                { 1, xs },
                { 2, ys }
            };

            var results = scheduler.Start(() => Observable.Case(() => 3, map, scheduler));

            results.Messages.AssertEqual(
                OnCompleted <int>(201)
                );

            xs.Subscriptions.AssertEqual(
                );

            ys.Subscriptions.AssertEqual(
                );
        }
예제 #8
0
 public void CaseWithDefault_CheckDefault()
 {
     Observable.Case(() => 1, new Dictionary <int, IObservable <int> >(), DefaultScheduler.Instance)
     .AssertEqual(Observable.Case(() => 1, new Dictionary <int, IObservable <int> >()));
 }