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

Select_SourceListGetsModifiedDuringIteration_ExceptionIsPropagated() private method

        public void Select_SourceListGetsModifiedDuringIteration_ExceptionIsPropagated()
        {
            List<int> source = new List<int>() { 1, 2, 3, 4, 5 };
            Func<int, int> selector = i => i + 1;

            var result = source.Select(selector);
            var enumerator = result.GetEnumerator();

            Assert.True(enumerator.MoveNext());
            Assert.Equal(2 /* 1 + 1 */, enumerator.Current);

            source.Add(6);
            Assert.Throws<InvalidOperationException>(() => enumerator.MoveNext());
        }
SelectTests