static void Main(string[] args) { NotifyCollection<int> list = new NotifyCollection<int>(); f observer = new f(); list.CollectionChanged += f.HandleEvent; list.Add(5); list.Add(6); list.Add(7); list.Add(8); list.RemoveAt(3); list.RemoveAt(2); }
public void TopX_Remove_CorrectResult() { var collection = new NotifyCollection <Dummy <int> >(); var collCasted = (INotifyCollection <Dummy <int> >)collection; var top1 = new Dummy <int>(43); var top2 = new Dummy <int>(42); var top3 = new Dummy <int>(30); collection.Add(top1); collection.Add(top2); collection.Add(top3); collection.Add(new Dummy <int>(23)); collection.Add(new Dummy <int>(6)); var topEx = Observable.Expression(() => collCasted.TopX(3, d => d.Item)); var top = topEx.Value; Assert.AreEqual(top1, top[0].Key); Assert.AreEqual(top2, top[1].Key); Assert.AreEqual(top3, top[2].Key); Assert.AreEqual(3, top.Length); var changed = false; topEx.ValueChanged += (o, e) => { Assert.IsNotNull(e.OldValue); Assert.IsNotNull(e.NewValue); changed = true; }; collection.RemoveAt(3); Assert.AreEqual(top, topEx.Value); Assert.IsFalse(changed); collection.Remove(top1); Assert.IsTrue(changed); Assert.AreEqual(42, topEx.Value[0].Key.Item); Assert.AreEqual(30, topEx.Value[1].Key.Item); Assert.AreEqual(6, topEx.Value[2].Key.Item); }