Ejemplo n.º 1
0
        public void IteratorFailsMoveNextOnceIterationIsComplete()
        {
            var iter = new TaskEnumerator <int>(JustOne(), 1);

            Assert.IsFalse(iter.Disposed);
            Scheduler.WaitFor(iter.Fetch());

            using (var e = iter.CurrentItems) {
                Assert.IsTrue(e.MoveNext());
                Assert.AreEqual(1, e.Current);
                Assert.IsFalse(e.MoveNext());
            }

            Assert.IsFalse(iter.Disposed);
            Scheduler.WaitFor(iter.Fetch());
            Assert.IsTrue(iter.Disposed);

            iter.Dispose();
        }
Ejemplo n.º 2
0
        IEnumerator <object> IterationTask(TaskEnumerator <int> iterator, List <int> output)
        {
            while (!iterator.Disposed)
            {
                yield return(iterator.Fetch());

                foreach (var item in iterator)
                {
                    output.Add(item);
                }
            }
        }
Ejemplo n.º 3
0
        public void TestTypeCoercion()
        {
            var iter = new TaskEnumerator <int>(TwoTypes(), 1);

            Assert.IsFalse(iter.Disposed);
            Scheduler.WaitFor(iter.Fetch());

            using (var e = iter.CurrentItems) {
                Assert.IsTrue(e.MoveNext());
                Assert.AreEqual(1, e.Current);
            }

            Assert.IsFalse(iter.Disposed);

            try {
                Scheduler.WaitFor(iter.Fetch());
                Assert.Fail("Fetch did not throw an InvalidCastException");
            } catch (FutureException fe) {
                Assert.IsInstanceOf <InvalidCastException>(fe.InnerException);
            }

            iter.Dispose();
        }
Ejemplo n.º 4
0
        public void TestIterateSequence()
        {
            using (var iter = new TaskEnumerator <int>(CountToThree(), 1)) {
                for (int i = 1; i <= 3; i++)
                {
                    Assert.IsFalse(iter.Disposed);
                    Scheduler.WaitFor(iter.Fetch());

                    using (var e = iter.CurrentItems) {
                        Assert.IsTrue(e.MoveNext());
                        Assert.AreEqual(i, e.Current);
                        Assert.IsFalse(e.MoveNext());
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void IteratorRaisesIfCurrentIsAccessedBeforeInitialMoveNext()
        {
            var iter = new TaskEnumerator <int>(JustOne(), 1);

            Assert.IsFalse(iter.Disposed);
            Scheduler.WaitFor(iter.Fetch());

            try {
                using (var e = iter.CurrentItems) {
                    var _ = e.Current;
                    Assert.Fail("e.Current did not throw an InvalidOperationException");
                }
            } catch (InvalidOperationException) {
            }

            iter.Dispose();
        }