Example #1
0
        public void EnumeratorOnlyReturnsItemsOfCorrectType()
        {
            var items = new object[] { 1, "string" };

            using (var comCleanupEnumerator = new ComCleanupEnumerator <string>(items.GetEnumerator(), o => {}))
            {
                comCleanupEnumerator.MoveNext();
                Assert.Equal("string", comCleanupEnumerator.Current);
                Assert.Equal(false, comCleanupEnumerator.MoveNext());
            }
        }
        public void EnumeratorOnlyReturnsItemsOfCorrectType()
        {
            var items = new object[] { 1, "string" };

            using (var comCleanupEnumerator = new ComCleanupEnumerator<string>(items.GetEnumerator(), o => {}))
            {
                comCleanupEnumerator.MoveNext();
                Assert.Equal("string", comCleanupEnumerator.Current);
                Assert.Equal(false, comCleanupEnumerator.MoveNext());
            }
        }
Example #3
0
        public void EnumeratorCallsCleanupOnSingleElement()
        {
            var cleanupCalled = false;
            var enumerable    = new[] { "string" };

            using (var comCleanupEnumerator = new ComCleanupEnumerator <string>(enumerable.GetEnumerator(), o => cleanupCalled = true))
            {
                //Move to first item, then move next will return false because no more elements
                comCleanupEnumerator.MoveNext();
                comCleanupEnumerator.MoveNext();
            }

            Assert.True(cleanupCalled);
        }
        public void EnumeratorCallsCleanupOnSingleElement()
        {
            var cleanupCalled = false;
            var enumerable = new[] { "string" };

            using (var comCleanupEnumerator = new ComCleanupEnumerator<string>(enumerable.GetEnumerator(), o => cleanupCalled = true))
            {
                //Move to first item, then move next will return false because no more elements
                comCleanupEnumerator.MoveNext();
                comCleanupEnumerator.MoveNext();
            }

            Assert.True(cleanupCalled);
        }
Example #5
0
        public void EnumeratorCallsCleanupIfDisposeCalledBeforeMoveNextReturnsFalse()
        {
            var cleanupCalled = false;
            var enumerable    = new[] { "string" };

            using (var comCleanupEnumerator = new ComCleanupEnumerator <string>(enumerable.GetEnumerator(), o => cleanupCalled = true))
            {
                //MoveNext will return true, leaving the current value not cleaned up yet.
                comCleanupEnumerator.MoveNext();
            }

            Assert.True(cleanupCalled);
        }
        public void EnumeratorCallsCleanupIfDisposeCalledBeforeMoveNextReturnsFalse()
        {
            var cleanupCalled = false;
            var enumerable = new[] { "string" };

            using (var comCleanupEnumerator = new ComCleanupEnumerator<string>(enumerable.GetEnumerator(), o => cleanupCalled = true))
            {
                //MoveNext will return true, leaving the current value not cleaned up yet.
                comCleanupEnumerator.MoveNext();
            }

            Assert.True(cleanupCalled);
        }