public void CollectionComputingChildTest() { ObservableCollection <Item> items = new ObservableCollection <Item>( new Item[] { new Item(0, "0"), new Item(1, "0"), new Item(2, "2"), new Item(3, "3"), new Item(4, "3"), new Item(5, "3") }); NotifyCollectionChangedEventArgs lastNotifyCollectionChangedEventArgs = null; items.CollectionChanged += (sender, args) => { lastNotifyCollectionChangedEventArgs = args; }; OcConsumer consumer = new OcConsumer(); Grouping <Item, string> grouping = items.Grouping(i => i.Value); bool activationInProgress = true; bool inActivationInProgress = false; grouping.CollectionChanged += (sender, args) => { Assert.AreEqual(grouping.ActivationInProgress, activationInProgress); Assert.AreEqual(grouping.InactivationInProgress, inActivationInProgress); if (grouping.Count >= 3) { Assert.AreEqual(grouping[2].ActivationInProgress, activationInProgress); Assert.AreEqual(grouping[2].InactivationInProgress, inActivationInProgress); } }; grouping.For(consumer); activationInProgress = false; Group <Item, string> group = grouping[2]; group.DebugTag = "DebugTag"; Assert.AreEqual(group.DebugTag, "DebugTag"); Assert.IsNull(group.UserCodeIsCalledFrom); group.Tag = "Tag"; Assert.AreEqual(group.Tag, "Tag"); Assert.IsTrue(group.IsActive); Assert.AreEqual(group.ItemType, typeof(Item)); Assert.IsTrue(group.IsConsistent); if (OcConfiguration.SaveInstantiationStackTrace) { Assert.IsNotNull(group.InstantiationStackTrace); } PropertyInfo newItemPropertyInfo = group.GetType().GetProperty("NewItem"); NotifyCollectionChangedAction?currentChange = null; Item newItem = null; int oldIndex = -1; int newIndex = -1; group.PreCollectionChanged += (sender, args) => { Assert.AreEqual(group.CurrentChange, currentChange); Assert.AreEqual(newItemPropertyInfo.GetValue(group), newItem); Assert.AreEqual(group.NewItemObject, newItem); Assert.AreEqual(group.OldIndex, oldIndex); Assert.AreEqual(group.NewIndex, newIndex); if (group.HandledEventArgs is NotifyCollectionChangedEventArgs) { Assert.AreEqual(group.HandledEventSender, items); Assert.AreEqual(group.HandledEventArgs, lastNotifyCollectionChangedEventArgs); } }; group.PostCollectionChanged += (sender, args) => { Assert.AreEqual(group.CurrentChange, currentChange); Assert.AreEqual(newItemPropertyInfo.GetValue(group), newItem); Assert.AreEqual(group.NewItemObject, newItem); Assert.AreEqual(group.OldIndex, oldIndex); Assert.AreEqual(group.NewIndex, newIndex); }; currentChange = NotifyCollectionChangedAction.Add; newItem = new Item(6, "3"); oldIndex = -1; newIndex = 0; items.Insert(0, newItem); currentChange = NotifyCollectionChangedAction.Remove; newItem = default; oldIndex = 0; newIndex = -1; items.RemoveAt(3); currentChange = NotifyCollectionChangedAction.Replace; newItem = new Item(7, "3"); oldIndex = 0; newIndex = 0; items[0] = newItem; currentChange = NotifyCollectionChangedAction.Move; newItem = default; oldIndex = 1; newIndex = 2; items.Move(3, 4); inActivationInProgress = true; consumer.Dispose(); }