예제 #1
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());
            }
        }
예제 #2
0
 public void ExecutionIsDeferred()
 {
     ThrowingEnumerable.AssertDeferred(src => src.Where(x => x > 0));
 }
예제 #3
0
 public void ExecutionIsDeferred()
 {
     ThrowingEnumerable.AssertDeferred(src => src.Select(x => x * 2));
 }