public void EnumerableCount() { var enumerable = Enumerable.Range(0, 100); var proxy = new ListProxy(enumerable, 10); int changed = 0; proxy.CountChanged += (o, e) => changed++; var enumerator = proxy.GetEnumerator(); enumerator.MoveNext(); Assert.AreEqual(10, proxy.Count); Assert.AreEqual(1, changed); enumerator.MoveNext(); Assert.AreEqual(10, proxy.Count); Assert.AreEqual(1, changed); while (enumerator.MoveNext()) { } enumerator.Dispose(); Assert.AreEqual(100, proxy.Count); Assert.AreEqual(19, changed); using (enumerator = proxy.GetEnumerator()) { Assert.AreEqual(100, proxy.Count); while (enumerator.MoveNext()) { Assert.AreEqual(100, proxy.Count); } Assert.AreEqual(100, proxy.Count); } Assert.AreEqual(19, changed); }
[Test()] public void TestGetEnumerator() { IEnumerable<int> list_proxy = new ListProxy<int>(CreateSequence(), CreateOddSequence()); var enumerator = list_proxy.GetEnumerator(); foreach (int e in CreateEvenSequence()) { enumerator.MoveNext(); Assert.AreEqual(e, enumerator.Current); } }
[Test()] public void TestGetEnumerator() { IEnumerable <int> list_proxy = new ListProxy <int>(CreateSequence(), CreateOddSequence()); var enumerator = list_proxy.GetEnumerator(); foreach (int e in CreateEvenSequence()) { enumerator.MoveNext(); Assert.AreEqual(e, enumerator.Current); } }
public void EnumeratorForEnumerable() { var proxy = new ListProxy(Enumerable.Range(0, 2)); var enumerator = proxy.GetEnumerator(); Assert.That(enumerator.Current, Is.Null); Assert.That(enumerator.MoveNext(), Is.True); Assert.That(enumerator.Current, Is.EqualTo(0)); Assert.That(enumerator.MoveNext(), Is.True); Assert.That(enumerator.Current, Is.EqualTo(1)); Assert.That(enumerator.MoveNext(), Is.False); }
public void ClearList() { var proxy = new ListProxy(Enumerable.Range(0, 100).ToList()); var enumerator = proxy.GetEnumerator(); enumerator.MoveNext(); enumerator.MoveNext(); proxy.Clear(); Assert.AreEqual(100, proxy.Count); Assert.That(() => enumerator.MoveNext(), Throws.InvalidOperationException); }
public void CollectionChangedWhileEnumerating() { var c = new ObservableCollection <string> { "foo", "bar" }; var p = new ListProxy(c); IEnumerator <object> e = p.GetEnumerator(); Assert.IsTrue(e.MoveNext(), "Initial MoveNext() failed, test can't continue"); c.Add("baz"); Assert.That(() => e.MoveNext(), Throws.InvalidOperationException, "MoveNext did not throw an exception when the underlying collection had changed"); }