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 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); }