System.Linq.Tests.SelectTests.MoveNextAfterDispose C# (CSharp) Method

MoveNextAfterDispose() private method

private MoveNextAfterDispose ( IEnumerable source ) : void
source IEnumerable
return void
        public void MoveNextAfterDispose(IEnumerable<int> source)
        {
            // Select is specialized for a bunch of different types, so we want
            // to make sure this holds true for all of them.
            var identityTransforms = new List<Func<IEnumerable<int>, IEnumerable<int>>>
            {
                e => e,
                e => ForceNotCollection(e),
                e => e.ToArray(),
                e => e.ToList(),
                e => new LinkedList<int>(e), // IList<T> that's not a List
                e => e.Select(i => i) // Multiple Select() chains are optimized
            };

            foreach (IEnumerable<int> equivalentSource in identityTransforms.Select(t => t(source)))
            {
                IEnumerable<int> result = equivalentSource.Select(i => i);
                using (IEnumerator<int> e = result.GetEnumerator())
                {
                    while (e.MoveNext()) ; // Loop until we reach the end of the iterator, @ which pt it gets disposed.
                    Assert.False(e.MoveNext()); // MoveNext should not throw an exception after Dispose.
                }
            }
        }
SelectTests