public void IterateUnpaused() { var enumerator = new int[] { 0, 1, 2 }.GetEnumerator(); var pausable = new MockPausable(); var result = new List <int>(); enumerator = pausable.Manage(enumerator); while (enumerator.MoveNext()) { result.Add((int)enumerator.Current); } CollectionAssert.AreEqual(new int[] { 0, 1, 2 }, result); }
public void IterateWithIntermittenedPause() { var enumerator = new int[] { 0, 1, 2 }.GetEnumerator(); var pausable = new MockPausable(); var result = new List <int>(); enumerator = pausable.Manage(enumerator); while (enumerator.MoveNext()) { result.Add((int)enumerator.Current); pausable.Paused = !pausable.Paused; } CollectionAssert.AreEqual(new int[] { 0, -1, 1, -1, 2, -1 }, result); }
public void PauseIteration() { IEnumerator generate() { yield return(42); } var enumerator = generate(); var pausable = new MockPausable(); enumerator = pausable.Manage(enumerator); pausable.Paused = true; Assert.AreEqual( (true, -1), ((bool, int))(enumerator.MoveNext(), enumerator.Current) ); }
public void WhenPausedPreventFirstIteration() { var ran = false; IEnumerator generate() { ran = true; yield break; } var enumerator = generate(); var pausable = new MockPausable(); enumerator = pausable.Manage(enumerator); pausable.Paused = true; enumerator.MoveNext(); Assert.False(ran); }