예제 #1
0
        public void ReadOnlyCollectionBuilder_GetEnumerator(int length)
        {
            var rocb = new ReadOnlyCollectionBuilder <int>();

            for (int i = 0; i < length; i++)
            {
                rocb.Add(i);
            }

            for (int j = 0; j < 2; j++)
            {
                IEnumerator <int> enumerator = rocb.GetEnumerator();

                // NB: Current property on generic enumerator doesn't throw; this is consistent with List<T>.

                for (int i = 0; i < length; i++)
                {
                    Assert.True(enumerator.MoveNext());
                    Assert.Equal(i, enumerator.Current);
                    Assert.Equal(i, ((IEnumerator)enumerator).Current);

                    enumerator.Dispose(); // NB: Similar to List<T>, calling Dispose does not have an effect here
                }

                Assert.False(enumerator.MoveNext());
                Assert.False(enumerator.MoveNext());

                // NB: Current property on generic enumerator doesn't throw; this is consistent with List<T>.

                enumerator.Reset();
            }
        }
예제 #2
0
        public IEnumerator <TExpression> /*!*/ GetEnumerator()
        {
            if (_expressions != null)
            {
                return(_expressions.GetEnumerator());
            }

            return(GetItemEnumerator());
        }
예제 #3
0
        private static void AssertEmpty <T>(ReadOnlyCollectionBuilder <T> rocb)
        {
            Assert.Equal(0, rocb.Count);

            Assert.False(rocb.Contains(default(T)));
            Assert.False(rocb.Remove(default(T)));
            Assert.InRange(rocb.IndexOf(default(T)), int.MinValue, -1);

            IEnumerator <T> e = rocb.GetEnumerator();

            Assert.False(e.MoveNext());
        }
예제 #4
0
        public void ReadOnlyCollectionBuilder_IEnumeratorOfT_Versioning_Reset(int index, Action <ReadOnlyCollectionBuilder <int> > edit)
        {
            var rocb = new ReadOnlyCollectionBuilder <int>(new[] { 1, 2, 3 });

            IEnumerator <int> enumerator = rocb.GetEnumerator();

            Assert.True(enumerator.MoveNext());

            edit(rocb);

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