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