public void IteratorWithDepenedenciesDoesNotEnumerateSourceUntilResultIsEnumerated() { var sourceCollection = new SourceCollection(With.Inputs(Tom, Tim, Jack)); Assert.AreEqual(0, sourceCollection.GetEnumeratorCalls); var contactIterator = new SimpleIterator <Contact>(sourceCollection.AsBindable()); Assert.AreEqual(0, sourceCollection.GetEnumeratorCalls); contactIterator.AcceptDependency(new ItemDependencyDefinition("Name")); Assert.AreEqual(0, sourceCollection.GetEnumeratorCalls); foreach (var c in contactIterator) { } Assert.AreEqual(1, sourceCollection.GetEnumeratorCalls); contactIterator.Dispose(); Assert.AreEqual(1, sourceCollection.GetEnumeratorCalls); }
public void IteratorUnsubscribesFromItemWhenRemoved() { var sourceCollection = With.Inputs(Mike, Tom, Jack); var contactIterator = new SimpleIterator <Contact>(sourceCollection); Assert.IsFalse(Mike.HasPropertyChangedSubscribers); Assert.IsFalse(Tom.HasPropertyChangedSubscribers); Assert.IsFalse(Jack.HasPropertyChangedSubscribers); // TODO: Assert.IsTrue(sourceCollection.HasPropertyChangedSubscribers); // TODO: Assert.IsTrue(sourceCollection.HasCollectionChangedSubscribers); contactIterator.AcceptDependency(new ItemDependencyDefinition("Name")); foreach (var c in contactIterator) { } Assert.IsTrue(Mike.HasPropertyChangedSubscribers); Assert.IsTrue(Tom.HasPropertyChangedSubscribers); Assert.IsTrue(Jack.HasPropertyChangedSubscribers); // TODO: Assert.IsTrue(sourceCollection.HasPropertyChangedSubscribers); // TODO: Assert.IsTrue(sourceCollection.HasCollectionChangedSubscribers); sourceCollection.Remove(Tom); Assert.IsTrue(Mike.HasPropertyChangedSubscribers); Assert.IsFalse(Tom.HasPropertyChangedSubscribers); Assert.IsTrue(Jack.HasPropertyChangedSubscribers); // TODO: Assert.IsTrue(sourceCollection.HasPropertyChangedSubscribers); // TODO: Assert.IsTrue(sourceCollection.HasCollectionChangedSubscribers); contactIterator.Dispose(); Assert.IsFalse(Mike.HasPropertyChangedSubscribers); Assert.IsFalse(Tom.HasPropertyChangedSubscribers); Assert.IsFalse(Jack.HasPropertyChangedSubscribers); // TODO: Assert.IsFalse(sourceCollection.HasPropertyChangedSubscribers); // TODO: Assert.IsFalse(sourceCollection.HasCollectionChangedSubscribers); }