public void GetEnumeratorWorksWithItemsSource()
        {
            var         collection  = new ItemsSourceCollection();
            var         itemsSource = CreateIntItemsSource(5);
            IEnumerator collectionEnumerator;
            IEnumerator itemsEnumerator;

            collection.ItemsSource = itemsSource;
            collectionEnumerator   = collection.GetEnumerator();
            itemsEnumerator        = itemsSource.GetEnumerator();

            TestEnumeratorEquality(collectionEnumerator, itemsEnumerator);
        }
        public void GetEnumeratorWorksWithDefaultCollection()
        {
            var         collection = new ItemsSourceCollection();
            var         items      = new int[] { 1, 2, 3, 4, 5 };
            IEnumerator collectionEnumerator;
            IEnumerator itemsEnumerator;

            foreach (var item in items)
            {
                collection.Add(item);
            }
            collectionEnumerator = collection.GetEnumerator();
            itemsEnumerator      = items.GetEnumerator();

            TestEnumeratorEquality(collectionEnumerator, itemsEnumerator);
        }
        public void GetEnumeratorWorksWithNonEnumerableItemsSource()
        {
            var         collection  = new ItemsSourceCollection();
            var         itemsSource = CreateNonEnumerableItemsSource();
            IEnumerator enumerator;

            collection.ItemsSource = itemsSource;
            enumerator             = collection.GetEnumerator();

            var enumerationNotStartedEx = Record.Exception(() => enumerator.Current);

            Assert.IsType <InvalidOperationException>(enumerationNotStartedEx);

            Assert.True(enumerator.MoveNext());
            Assert.Same(itemsSource, enumerator.Current);

            Assert.False(enumerator.MoveNext());
            var enumerationStoppedEx = Record.Exception(() => enumerator.Current);

            Assert.IsType <InvalidOperationException>(enumerationStoppedEx);
        }