System.Collections.Tests.SortedListTests.GetEnumerator_IEnumerator_Invalid C# (CSharp) Méthode

GetEnumerator_IEnumerator_Invalid() private méthode

private GetEnumerator_IEnumerator_Invalid ( ) : void
Résultat void
        public static void GetEnumerator_IEnumerator_Invalid()
        {
            SortedList sortList = Helpers.CreateIntSortedList(100);

            // If the underlying collection is modified, MoveNext, Reset, Entry, Key and Value throw, but Current doesn't
            IEnumerator enumerator = ((IEnumerable)sortList).GetEnumerator();
            enumerator.MoveNext();
            sortList.Add(101, 101);

            Assert.Throws<InvalidOperationException>(() => enumerator.MoveNext());
            Assert.Throws<InvalidOperationException>(() => enumerator.Reset());

            // Current throws if index < 0
            enumerator = sortList.GetEnumerator();
            Assert.Throws<InvalidOperationException>(() => enumerator.Current);

            // Current throw after resetting
            enumerator = sortList.GetEnumerator();
            enumerator.MoveNext();

            enumerator.Reset();
            Assert.Throws<InvalidOperationException>(() => enumerator.Current);

            // Current throw if the current index is >= count
            enumerator = sortList.GetEnumerator();
            while (enumerator.MoveNext()) ;
            Assert.False(enumerator.MoveNext());
            Assert.Throws<InvalidOperationException>(() => enumerator.Current);
        }
SortedListTests