public void BugTestOnNotifyChangeAfterClear() { int fired = 0; smc.CollectionChanged += (s, e) => fired++; ints2.Add(12); // should work Assert.Equal(1, fired); allInts.Clear(); // now we have some outstanding property change notifications Assert.Equal(4, fired); // we get a notification for the clear operation Assert.Empty(smc); ints2.Add(13); // we get an add at an invalid index, but now the bug is fixed Assert.Equal(4, fired); // the second prop notification should be suppressed. }
public void RequeryOnSourceChange() { var list = new ThreadSafeBindableCollection <int>(); list.AddRange(Enumerable.Range(1, 100)); var filtered = new WhereCollection <int>(list, i => i % 2 == 0); Assert.Equal(50, filtered.Count); list.Add(3); Assert.Equal(50, filtered.Count); list.Add(4); Assert.Equal(51, filtered.Count); }
public void DisposeUnhooksFromCollectionChanged() { ThreadSafeBindableCollection <int> col = new ThreadSafeBindableCollection <int>(); var mock = new Mock <IListMonitor <int> >(); var releaseDelegate = mock.Object.AttachToList(col); col.Add(1); mock.Verify(o => o.NewItem(It.IsAny <int>(), It.IsAny <int>()), Times.Once()); releaseDelegate(); col.Add(1); mock.Verify(o => o.NewItem(It.IsAny <int>(), It.IsAny <int>()), Times.Once()); }
public void PropogateRemoveAtToInerCollection() { int objectCount = 0; var baseColl = new ThreadSafeBindableCollection <int>(); var coll = new SelectCollection <int, IntHolder>(baseColl, i => new IntHolder(objectCount++)); baseColl.Add(1); baseColl.Add(2); baseColl.Add(3); Assert.Equal(0, coll[0].Value); Assert.Equal(1, coll[1].Value); Assert.Equal(2, coll[2].Value); coll.RemoveAt(1); Assert.Equal(2, coll[1].Value); }
public void SelectCollectionCachesObjects() { int objectCount = 0; var baseColl = new ThreadSafeBindableCollection <int>(); var coll = new SelectCollection <int, IntHolder>(baseColl, i => new IntHolder(objectCount++)); baseColl.Add(1); baseColl.Add(2); baseColl.Add(3); Assert.Equal(0, coll[0].Value); Assert.Equal(1, coll[1].Value); Assert.Equal(2, coll[2].Value); Assert.Equal(0, coll[0].Value); Assert.Equal(1, coll[1].Value); Assert.Equal(2, coll[2].Value); Assert.Equal(3, objectCount); }
public void SetDeletesObjectWorks() { int objectCount = 0; var baseColl = new ThreadSafeBindableCollection <int>(); var coll = new SelectCollection <int, IntHolder>(baseColl, i => new IntHolder(objectCount++)); baseColl.Add(1); baseColl.Add(2); baseColl.Add(3); Assert.Equal(0, coll[0].Value); Assert.Equal(1, coll[1].Value); Assert.Equal(2, coll[2].Value); baseColl[1] = 4; Assert.Equal(3, coll[1].Value); baseColl.Add(2); // adding it back in should create a new object as old one was deleted Assert.Equal(4, coll[3].Value); // should not have created objects when deleting Assert.Equal(5, objectCount); }
public void SendPropertyChangeNotification() { var list = new ThreadSafeBindableCollection <int>(); list.AddRange(Enumerable.Range(1, 100)); var filtered = new WhereCollection <int>(list, i => i % 2 == 0); int ccFired = 0; filtered.PropertyChanged += (s, e) => { Assert.Equal(filtered, s); Assert.Equal("Count", e.PropertyName); ccFired++; }; list.Add(4); Assert.Equal(1, ccFired); }
public void SendListChangeNotification() { var list = new ThreadSafeBindableCollection <int>(); list.AddRange(Enumerable.Range(1, 100)); var filtered = new WhereCollection <int>(list, i => i % 2 == 0); int ccFired = 0; filtered.CollectionChanged += (s, e) => { Assert.Equal(filtered, s); Assert.Equal(NotifyCollectionChangedAction.Reset, e.Action); ccFired++; }; list.Add(4); Assert.Equal(1, ccFired); }
public void InsertInMainList() { int fired = 0; smc.CollectionChanged += (s, e) => { Assert.Equal(NotifyCollectionChangedAction.Reset, e.Action); fired++; }; using (var foo = INPCCounter.VerifyInpcFired(smc, i => i.Count)) { allInts.Add(new ThreadSafeBindableCollection <int>()); } Assert.Equal(1, fired); }