Beispiel #1
0
        internal 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());
            }
        }
Beispiel #2
0
        public void FirstSequenceIsNotAccessedBeforeUse()
        {
            var first  = new ThrowingEnumerable();
            var second = new int[] { 5 };

            var query = first.Concat(second);

            using (var iterator = query.GetEnumerator())
            {
                Assert.Throws <InvalidOperationException>(() => iterator.MoveNext());
            }
        }
Beispiel #3
0
        public void FirstSequenceNotUsedUntilQueryIterated()
        {
            var first = new ThrowingEnumerable();

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

            using (var iterator = query.GetEnumerator())
            {
                // No exception thrown until here.
                Assert.Throws <InvalidOperationException>(() => iterator.MoveNext());
            }
        }
Beispiel #4
0
        public void AlternateExceptionExpectation()
        {
            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);

                iterator.MoveNext();
            }
        }
Beispiel #5
0
        public void SecondSequenceNotUsedUniltFirstIsExhausted()
        {
            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());
            }
        }
Beispiel #6
0
        public void SecondSequenceIsNotAccessedBeforeUse()
        {
            var first  = new int[] { 5 };
            var second = new ThrowingEnumerable();

            var query = first.Concat(second);

            using (var iterator = query.GetEnumerator())
            {
                // MoveNext will succeed as there is an element in first.
                Assert.IsTrue(iterator.MoveNext());
                Assert.AreEqual(5, iterator.Current);

                // This will fail as the second sequence doesn't support MoveNext().
                Assert.Throws <InvalidOperationException>(() => iterator.MoveNext());
            }
        }
 public void ExecutionIsDeferred()
 {
     ThrowingEnumerable.AssertDeferred(src => src.Select(x => x * 2));
 }
 public void WithIndexExecutionIsDeferred()
 {
     ThrowingEnumerable.AssertDeferred(src => src.Select((s, index) => s + index));
 }
Beispiel #9
0
 public void Have_deffered_execution_when_index_provided()
 {
     ThrowingEnumerable.AssertDeferred(src => src.Where((x, index) => x > 0));
 }
Beispiel #10
0
 public void Have_deffered_execution()
 {
     ThrowingEnumerable.AssertDeferred(src => src.Where(x => x > 0));
 }
Beispiel #11
0
 public void ExecutionIsDeferred()
 {
     ThrowingEnumerable.AssertDeferred <int>(src => src.Where(x => x > 0));
 }
Beispiel #12
0
 public void WithIndexExecutionIsDeferred()
 {
     ThrowingEnumerable.AssertDeferred(src => src.Where((x, index) => x > 0));
 }