コード例 #1
0
        public void ExecutinIsDeferred()
        {
            var outer = new ThrowingEnumerable();
            var inner = new ThrowingEnumerable();

            outer.Join(inner, x => x, y => y, (x, y) => x + y);
        }
コード例 #2
0
        public void ExecutionIsDeferrred()
        {
            var outer = new ThrowingEnumerable();
            var inner = new ThrowingEnumerable();

            outer.GroupJoin(inner, x => x, y => y, (x, y) => x + y.Count());
        }
コード例 #3
0
        public void NoSequenceUsedBeforeIteration()
        {
            var first  = new ThrowingEnumerable();
            var second = new ThrowingEnumerable();
            var query  = first.Intersect(second);

            using (var iterator = query.GetEnumerator())
            { }
        }
コード例 #4
0
        /// <summary>
        /// Check that the given function uses deferred execution.
        /// A "spiked" source is given to the function: the function
        /// call itself shouldn't throw an exception. However, using
        /// the result (by calling GetEnumerator() then MoveNext() on it) *should*
        /// throw InvalidOperationException.
        /// </summary>
        public static void AssertDeferred <T>(
            Func <IEnumerable <int>, IEnumerable <T> > deferredFunction)
        {
            ThrowingEnumerable source = new ThrowingEnumerable();
            var result = deferredFunction(source);

            using (var iterator = result.GetEnumerator())
            {
                Assert.Throws <InvalidOperationException>(() => iterator.MoveNext());
            }
        }
コード例 #5
0
        public void FisrtSequenceIsNotAccessedBeforeFirstUse()
        {
            IEnumerable <int> first  = new ThrowingEnumerable();
            IEnumerable <int> second = new int[] { 1 };
            var query = first.Concat(second);

            using (var iterator = query.GetEnumerator())
            {
                //Now is used first
                Assert.Throws <InvalidOperationException>(() => iterator.MoveNext());
            }
        }
コード例 #6
0
        public void FirstSequenceIsNotUsedUntilQueryIsIterated()
        {
            var first = new ThrowingEnumerable();

            int[] second = { 2 };
            var   query  = first.Union(second);

            using (var iterator = query.GetEnumerator())
            {
                Assert.Throws <InvalidOperationException>(() => iterator.MoveNext());
            }
        }
コード例 #7
0
        public void NoSequencesUsedBeforeIteration()
        {
            var first  = new ThrowingEnumerable();
            var second = new ThrowingEnumerable();
            // No exceptions!
            var query = first.Union(second);

            // Still no exceptions... we're not calling MoveNext.
            using (var iterator = query.GetEnumerator())
            {
            }
        }
コード例 #8
0
        public void SecondSequenceIsNotAccessedBeforeFirstUse()
        {
            IEnumerable <int> first  = new int[] { 1 };
            IEnumerable <int> second = new ThrowingEnumerable();

            var query = first.Concat(second);

            using (var iterator = query.GetEnumerator())
            {
                Assert.IsTrue(iterator.MoveNext());
                Assert.AreEqual(1, iterator.Current);
                //now is used second
                Assert.Throws <InvalidOperationException>(() => iterator.MoveNext());
            }
        }
コード例 #9
0
        public void SecondSequenceIsNotUSedUntilFirstIsExhausted()
        {
            int[] first  = { 3, 5, 3 };
            var   second = new ThrowingEnumerable();

            using (var iterator = first.Union(second).GetEnumerator())
            {
                Assert.IsTrue(iterator.MoveNext());
                Assert.AreEqual(3, iterator.Current);
                Assert.IsTrue(iterator.MoveNext());
                Assert.AreEqual(5, iterator.Current);

                Assert.Throws <InvalidOperationException>(() => iterator.MoveNext());
            }
        }
コード例 #10
0
 public void WithIndexExecutionIsDeferred()
 {
     ThrowingEnumerable.AssertDeferred(src => src.Where((x, index) => x > 0));
 }
コード例 #11
0
 public void ExecutionIsDeferred()
 {
     ThrowingEnumerable.AssertDeferred(src => src.Where(x => x > 0));
 }
コード例 #12
0
 public void ExecutionIsDeferred()
 {
     ThrowingEnumerable.AssertDeferred(src => src.Select(x => x * 2));
 }
コード例 #13
0
        public void SourceSequenceIsReadEagerly()
        {
            var source = new ThrowingEnumerable();

            Assert.Throws <InvalidOperationException>(() => source.ToLookup(x => x));
        }