public void Ctor_Collection_Multiple() { var d = new DisposedCounter(); var s = new CachedSequence <int> (d.Values(100)); Assert.AreEqual(0, d.Disposed); Assert.AreEqual(0, s.Head); Assert.IsNotNull(s.Tail); var t = s.Tail; Assert.AreEqual(0, d.Disposed); Assert.AreEqual(1, t.Head); Assert.IsNotNull(t.Tail); int c = 98; while (c-- > 0) { t = t.Tail; } Assert.AreEqual(null, t.Tail); Assert.AreEqual(1, d.Disposed); }
public void Ctor_Collection_Single_CheckDisposed() { var d = new DisposedCounter(); var s = new CachedSequence <int> (d.Values(1)); Assert.AreEqual(1, d.Disposed); Assert.AreEqual(0, s.Head); Assert.AreEqual(null, s.Tail); }
public void GetEnumerator_DisposeDisposesIterator() { var d = new DisposedCounter(); var s = CreateSequence(d.Values(2)); var i = s.GetEnumerator(); Assert.IsTrue(i.MoveNext()); i.Dispose(); Assert.AreEqual(1, d.Disposed); }
public void GetEnumerator_Dispose_Is_Forwarded() { var d = new DisposedCounter(); var s = new CachedSequence <int> (d.Values(100)); var q = s.Take(1); int n = 0; foreach (var e in q) { Assert.AreEqual(n, e); ++n; } Assert.AreEqual(1, n); // When the CachedSequence<T> enumerator is disposed, // the underlying enumerator should also be disposed. Assert.AreEqual(1, d.Disposed); // Note that we've "lost" 99 elements Assert.AreEqual(2, s.Count()); }