示例#1
0
        public void SubscribeToEnumerable_Error()
        {
            var scheduler = new TestScheduler();

            var results = scheduler.CreateObserver <int>();
            var d       = default(IDisposable);
            var xs      = default(MockEnumerable <int>);
            var ex      = new Exception();

            scheduler.ScheduleAbsolute(Created, () => xs   = new MockEnumerable <int>(scheduler, Enumerable_Error(ex)));
            scheduler.ScheduleAbsolute(Subscribed, () => d = xs.Subscribe(results, scheduler));
            scheduler.ScheduleAbsolute(Disposed, () => d.Dispose());

            scheduler.Start();

            results.Messages.AssertEqual(
                OnNext(201, 1),
                OnNext(202, 2),
                OnNext(203, 3),
                OnError <int>(204, ex)
                );

            xs.Subscriptions.AssertEqual(
                Subscribe(200, 204)
                );
        }
示例#2
0
        public void Concat_EnumerableThrows()
        {
            var scheduler = new TestScheduler();

            var o = scheduler.CreateHotObservable(
                OnNext(150, 1),
                OnNext(210, 2),
                OnNext(220, 3),
                OnCompleted <int>(225)
                );

            var ex  = new Exception();
            var xss = new MockEnumerable <IObservable <int> >(scheduler, GetObservablesForConcatThrow(o, ex));

            var res = scheduler.Start(() =>
                                      xss.Concat()
                                      );

            res.Messages.AssertEqual(
                OnNext(210, 2),
                OnNext(220, 3),
                OnError <int>(225, ex)
                );

            o.Subscriptions.AssertEqual(
                Subscribe(200, 225)
                );

            xss.Subscriptions.AssertEqual(
                Subscribe(200, 225)
                );
        }
示例#3
0
        public void SubscribeToEnumerable_Infinite()
        {
            var scheduler = new TestScheduler();

            var results = scheduler.CreateObserver <int>();
            var d       = default(IDisposable);
            var xs      = default(MockEnumerable <int>);

            scheduler.ScheduleAbsolute(Created, () => xs   = new MockEnumerable <int>(scheduler, Enumerable_Infinite()));
            scheduler.ScheduleAbsolute(Subscribed, () => d = xs.Subscribe(results, scheduler));
            scheduler.ScheduleAbsolute(210, () => d.Dispose());

            scheduler.Start();

            results.Messages.AssertEqual(
                OnNext(201, 1),
                OnNext(202, 1),
                OnNext(203, 1),
                OnNext(204, 1),
                OnNext(205, 1),
                OnNext(206, 1),
                OnNext(207, 1),
                OnNext(208, 1),
                OnNext(209, 1)
                );

            xs.Subscriptions.AssertEqual(
                Subscribe(200, 210)
                );
        }
示例#4
0
        public void ShouldReturnTotalCountWhenEnumerationIsNonEmpty()
        {
            MockEnumerable source = new MockEnumerable(3);
            var            list   = new LazyList <int>(source);

            Assert.AreEqual(3, list.Count, "Should return size of enumeration.");
            Assert.AreEqual(3, source.TotalElementsReturned, "Should have fetched all elements.");

            Assert.AreEqual(3, list.Count, "Should return the same count the second time also.");
            Assert.AreEqual(3, source.TotalElementsReturned, "Should not have fetched any additional elements.");
        }
示例#5
0
        public void ShouldRetrieveIndexedElementIncrementally()
        {
            MockEnumerable source = new MockEnumerable(3);
            var            list   = new LazyList <int>(source);

            Assert.AreEqual(1, list[1]);
            Assert.AreEqual(2, source.TotalElementsReturned, "Should have read exactly the necessary number of elements.");

            Assert.AreEqual(0, list[0]);
            Assert.AreEqual(2, source.TotalElementsReturned, "Should have read exactly the necessary number of elements.");

            Assert.AreEqual(2, list[2]);
            Assert.AreEqual(3, source.TotalElementsReturned, "Should have read exactly the necessary number of elements.");
        }
示例#6
0
        public void CopyToShouldCopyAllElements()
        {
            MockEnumerable source = new MockEnumerable(3);
            var            list   = new LazyList <int>(source);

            var copy = new int[4];

            list.CopyTo(copy, 1);

            Assert.AreEqual(0, copy[1]);
            Assert.AreEqual(1, copy[2]);
            Assert.AreEqual(2, copy[3]);
            Assert.AreEqual(3, source.TotalElementsReturned, "Should have read exactly the necessary number of elements.");
        }
示例#7
0
        public void Concat_Enumerable_Dispose()
        {
            var scheduler = new TestScheduler();

            var o1 = scheduler.CreateHotObservable(
                OnNext(150, 1),
                OnNext(210, 2),
                OnNext(220, 3),
                OnCompleted <int>(230)
                );

            var o2 = scheduler.CreateHotObservable(
                OnNext(150, 1),
                OnNext(200, 2),
                OnNext(210, 3),
                OnNext(240, 4),
                OnNext(270, 5),
                OnNext(320, 6),
                OnNext(330, 7),
                OnCompleted <int>(340)
                );

            var xss = new MockEnumerable <ITestableObservable <int> >(scheduler, new[] { o1, o2 });

            var res = scheduler.Start(() =>
                                      xss.Select(xs => (IObservable <int>)xs).Concat(),
                                      300
                                      );

            res.Messages.AssertEqual(
                OnNext(210, 2),
                OnNext(220, 3),
                OnNext(240, 4),
                OnNext(270, 5)
                );

            o1.Subscriptions.AssertEqual(
                Subscribe(200, 230)
                );

            o2.Subscriptions.AssertEqual(
                Subscribe(230, 300)
                );

            xss.Subscriptions.AssertEqual(
                Subscribe(200, 300)
                );
        }
示例#8
0
        public void ShouldThrowIndexOutOfRangeExceptionWhenIndexIsTooBig()
        {
            MockEnumerable source = new MockEnumerable(3);
            var            list   = new LazyList <int>(source);

            try
            {
                int value = list[3];
                Assert.Fail("Expected IndexOutOfRangeException.");
            }
            catch (IndexOutOfRangeException)
            {
            }

            Assert.AreEqual(3, source.TotalElementsReturned, "Should have fetched all elements since index was beyond end of collection.");
        }
示例#9
0
        public void ShouldThrowIndexOutOfRangeExceptionWhenIndexIsTooSmall()
        {
            MockEnumerable source = new MockEnumerable(3);
            var            list   = new LazyList <int>(source);

            try
            {
                int value = list[-1];
                Assert.Fail("Expected IndexOutOfRangeException.");
            }
            catch (IndexOutOfRangeException)
            {
            }

            Assert.AreEqual(0, source.TotalElementsReturned, "Should not have fetched any elements because the index was negative.");
        }
示例#10
0
        public void ShouldEnumerateAllElementsIncrementally()
        {
            MockEnumerable source = new MockEnumerable(2);
            var            list   = new LazyList <int>(source);

            IEnumerator <int> enumerator = list.GetEnumerator();

            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual(0, enumerator.Current);
            Assert.AreEqual(1, source.TotalElementsReturned, "Should have read exactly the necessary number of elements.");

            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual(1, enumerator.Current);
            Assert.AreEqual(2, source.TotalElementsReturned, "Should have read exactly the necessary number of elements.");

            Assert.IsFalse(enumerator.MoveNext());
            Assert.AreEqual(2, source.TotalElementsReturned, "Should have read exactly the necessary number of elements.");
        }
示例#11
0
        public void EnumerableToObservable_Dispose()
        {
            var scheduler = new TestScheduler();

            var e = new MockEnumerable <int>(scheduler,
                                             new[] { 3, 1, 2, 4 }
                                             );

            var results = scheduler.Start(() =>
                                          e.ToObservable(scheduler),
                                          203
                                          );

            results.Messages.AssertEqual(
                OnNext(201, 3),
                OnNext(202, 1)
                );

            e.Subscriptions.AssertEqual(
                Subscribe(200, 203)
                );
        }
示例#12
0
        public void EnumerableToObservable_Error()
        {
            var scheduler = new TestScheduler();

            var ex = new Exception();

            var e = new MockEnumerable <int>(scheduler,
                                             EnumerableToObservable_Error_Core(ex)
                                             );

            var results = scheduler.Start(() =>
                                          e.ToObservable(scheduler)
                                          );

            results.Messages.AssertEqual(
                OnNext(201, 1),
                OnNext(202, 2),
                OnError <int>(203, ex)
                );

            e.Subscriptions.AssertEqual(
                Subscribe(200, 203)
                );
        }
示例#13
0
        public void Concat_EnumerableTiming()
        {
            var scheduler = new TestScheduler();

            var o1 = scheduler.CreateHotObservable(
                OnNext(150, 1),
                OnNext(210, 2), // !
                OnNext(220, 3), // !
                OnCompleted <int>(230)
                );

            var o2 = scheduler.CreateColdObservable(
                OnNext(50, 4),  // !
                OnNext(60, 5),  // !
                OnNext(70, 6),  // !
                OnCompleted <int>(80)
                );

            var o3 = scheduler.CreateHotObservable(
                OnNext(150, 1),
                OnNext(200, 2),
                OnNext(210, 3),
                OnNext(220, 4),
                OnNext(230, 5),
                OnNext(270, 6),
                OnNext(320, 7), // !
                OnNext(330, 8), // !
                OnCompleted <int>(340)
                );

            var xss = new MockEnumerable <ITestableObservable <int> >(scheduler, new[] { o1, o2, o3, o2 });

            var res = scheduler.Start(() =>
                                      xss.Select(xs => (IObservable <int>)xs).Concat()
                                      );

            res.Messages.AssertEqual(
                OnNext(210, 2),
                OnNext(220, 3),
                OnNext(280, 4),
                OnNext(290, 5),
                OnNext(300, 6),
                OnNext(320, 7),
                OnNext(330, 8),
                OnNext(390, 4),
                OnNext(400, 5),
                OnNext(410, 6),
                OnCompleted <int>(420)
                );

            o1.Subscriptions.AssertEqual(
                Subscribe(200, 230)
                );

            o2.Subscriptions.AssertEqual(
                Subscribe(230, 310),
                Subscribe(340, 420)
                );

            o3.Subscriptions.AssertEqual(
                Subscribe(310, 340)
                );

            xss.Subscriptions.AssertEqual(
                Subscribe(200, 420)
                );
        }