Beispiel #1
0
    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);
    }
Beispiel #2
0
    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);
    }
Beispiel #3
0
    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)
            );
    }
Beispiel #4
0
    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);
    }