public bool MoveNext() { if (copyManager.IsEndOfTheLine) { if (isEndOfTheLine) { return(false); } var hasAny = source.MoveNext(); if (hasAny) { copyManager.Add(source.Current); } else { isEndOfTheLine = true; source.Dispose(); } return(hasAny); } else { /* the return value must be ignored and "true" returned because the presence of * of an item will be checked on next invocation of the current method. * if there isn't any, it will attempt to read it from the source enumerable */ copyManager.MoveNext(); return(true); } }
public void Current__When_SourceIsEmptyInitially_WhenAnItemIsAdded_TheItemMustBeTheCurrentItem( IList <string> values) { target = new WritingEnumerator <string>(new List <string>()); foreach (var value in values) { target.Add(value); Assert.AreEqual(value, target.Current); } }
public void AddingItems__When_SourceIsEmptyInitially__Must_AddItemAtTheEndOfCollection(IList <string> values) { var source = new List <string>(); target = new WritingEnumerator <string>(source); foreach (var value in values) { target.Add(value); } AssertionExtensions.SequencesAreEqual(values, source); }
public void AddingItems__When_SourceIsNotEmptyInitially__Must_AddItemAtTheEndOfCollection( IList <string> source, IList <string> values) { var expectedCollection = source.Concat(values).ToList(); target = new WritingEnumerator <string>(source); foreach (var value in values) { target.Add(value); } AssertionExtensions.SequencesAreEqual(expectedCollection, source); }
public void FullEnumeration__When_SourceIsEmptyInitially_When_ItemsAreAdded__AndPositionIsReset__MustReturnEveryItem_InTheOriginalSequence( IList <string> values) { var source = new List <string>(); target = new WritingEnumerator <string>(source); foreach (var value in values) { target.Add(value); } target.ResetPosition(); foreach (var value in values) { target.MoveNext(); Assert.AreEqual(value, target.Current); } }