public void ExecutinIsDeferred() { var outer = new ThrowingEnumerable(); var inner = new ThrowingEnumerable(); outer.Join(inner, x => x, y => y, (x, y) => x + y); }
public void ExecutionIsDeferrred() { var outer = new ThrowingEnumerable(); var inner = new ThrowingEnumerable(); outer.GroupJoin(inner, x => x, y => y, (x, y) => x + y.Count()); }
public void NoSequenceUsedBeforeIteration() { var first = new ThrowingEnumerable(); var second = new ThrowingEnumerable(); var query = first.Intersect(second); using (var iterator = query.GetEnumerator()) { } }
/// <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()); } }
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()); } }
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()); } }
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()) { } }
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()); } }
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()); } }
public void WithIndexExecutionIsDeferred() { ThrowingEnumerable.AssertDeferred(src => src.Where((x, index) => x > 0)); }
public void ExecutionIsDeferred() { ThrowingEnumerable.AssertDeferred(src => src.Where(x => x > 0)); }
public void ExecutionIsDeferred() { ThrowingEnumerable.AssertDeferred(src => src.Select(x => x * 2)); }
public void SourceSequenceIsReadEagerly() { var source = new ThrowingEnumerable(); Assert.Throws <InvalidOperationException>(() => source.ToLookup(x => x)); }