Esempio n. 1
0
        private void test(INotifyCollectionChangedExtended notifyCollectionChangedExtended)
        {
            ObservableCollection <int> collection = (ObservableCollection <int>)notifyCollectionChangedExtended;
            PropertyInfo newItemPropertyInfo      = notifyCollectionChangedExtended.GetType().GetProperty("NewItem");

            NotifyCollectionChangedAction?currentChange = null;
            int newItem  = 0;
            int oldIndex = -1;
            int newIndex = -1;

            notifyCollectionChangedExtended.PreCollectionChanged += (sender, args) =>
            {
                Assert.AreEqual(notifyCollectionChangedExtended.CurrentChange, currentChange);
                Assert.AreEqual(newItemPropertyInfo.GetValue(notifyCollectionChangedExtended), newItem);
                Assert.AreEqual(notifyCollectionChangedExtended.NewItemObject, newItem);
                Assert.AreEqual(notifyCollectionChangedExtended.OldIndex, oldIndex);
                Assert.AreEqual(notifyCollectionChangedExtended.NewIndex, newIndex);
            };

            notifyCollectionChangedExtended.PostCollectionChanged += (sender, args) =>
            {
                Assert.AreEqual(notifyCollectionChangedExtended.CurrentChange, currentChange);
                Assert.AreEqual(newItemPropertyInfo.GetValue(notifyCollectionChangedExtended), newItem);
                Assert.AreEqual(notifyCollectionChangedExtended.NewItemObject, newItem);
                Assert.AreEqual(notifyCollectionChangedExtended.OldIndex, oldIndex);
                Assert.AreEqual(notifyCollectionChangedExtended.NewIndex, newIndex);
            };

            currentChange = NotifyCollectionChangedAction.Add;
            newItem       = 7;
            oldIndex      = -1;
            newIndex      = 0;
            collection.Insert(0, 7);

            currentChange = NotifyCollectionChangedAction.Remove;
            newItem       = default;
            oldIndex      = 0;
            newIndex      = -1;
            collection.RemoveAt(0);

            currentChange = NotifyCollectionChangedAction.Replace;
            newItem       = 10;
            oldIndex      = 0;
            newIndex      = 0;
            collection[0] = 10;

            currentChange = NotifyCollectionChangedAction.Move;
            newItem       = default;
            oldIndex      = 0;
            newIndex      = 1;
            collection.Move(0, 1);

            currentChange = NotifyCollectionChangedAction.Reset;
            newItem       = default;
            oldIndex      = -1;
            newIndex      = -1;
            collection.Clear();
        }
Esempio n. 2
0
        private void test(INotifyCollectionChangedExtended notifyCollectionChangedExtended)
        {
            ObservableCollection <int> collection = (ObservableCollection <int>)notifyCollectionChangedExtended;
            PropertyInfo newItemPropertyInfo      = notifyCollectionChangedExtended.GetType().GetProperty("NewItem");

            NotifyCollectionChangedAction?currentChange = null;
            int newItem  = 0;
            int oldIndex = -1;
            int newIndex = -1;

            Extending <int> extending = notifyCollectionChangedExtended as Extending <int>;

            notifyCollectionChangedExtended.PreCollectionChanged += (sender, args) =>
            {
                Assert.AreEqual(notifyCollectionChangedExtended.CurrentChange, currentChange);
                Assert.AreEqual(newItemPropertyInfo.GetValue(notifyCollectionChangedExtended), newItem);
                Assert.AreEqual(notifyCollectionChangedExtended.NewItemObject, newItem);
                Assert.AreEqual(notifyCollectionChangedExtended.OldIndex, oldIndex);
                Assert.AreEqual(notifyCollectionChangedExtended.NewIndex, newIndex);
                if (extending != null)
                {
                    Assert.AreEqual(extending.HandledEventSender, extending.Source);
                    Assert.AreEqual(extending.HandledEventArgs, _lastNotifyCollectionChangedEventArgs);
                }
            };

            if (notifyCollectionChangedExtended is CollectionComputing <int> collectionComputing)
            {
                Assert.IsTrue(((IComputingInternal)collectionComputing).Consumers.Count() > 0);
                Assert.IsTrue(collectionComputing.Consumers.Count() > 0);
                Assert.NotNull(collectionComputing.ToString());
                collectionComputing.DebugTag = "DebugTag";
                Assert.AreEqual(collectionComputing.DebugTag, "DebugTag");

                collectionComputing.Tag = "Tag";
                Assert.AreEqual(collectionComputing.Tag, "Tag");
                Assert.NotNull(collectionComputing.ToString());
                Assert.AreEqual(collectionComputing.ItemType, typeof(int));
                Assert.IsTrue(collectionComputing.UserCodeIsCalledFrom == null);
                Assert.AreEqual(collectionComputing.InitialCapacity, 3);
            }

            notifyCollectionChangedExtended.PostCollectionChanged += (sender, args) =>
            {
                Assert.AreEqual(notifyCollectionChangedExtended.CurrentChange, currentChange);
                Assert.AreEqual(newItemPropertyInfo.GetValue(notifyCollectionChangedExtended), newItem);
                Assert.AreEqual(notifyCollectionChangedExtended.NewItemObject, newItem);
                Assert.AreEqual(notifyCollectionChangedExtended.OldIndex, oldIndex);
                Assert.AreEqual(notifyCollectionChangedExtended.NewIndex, newIndex);
                if (extending != null)
                {
                    Assert.AreEqual(extending.HandledEventSender, extending.Source);
                    Assert.AreEqual(extending.HandledEventArgs, _lastNotifyCollectionChangedEventArgs);
                }
            };

            currentChange = NotifyCollectionChangedAction.Add;
            newItem       = 7;
            oldIndex      = -1;
            newIndex      = 0;
            collection.Insert(0, 7);

            currentChange = NotifyCollectionChangedAction.Remove;
            newItem       = default;
            oldIndex      = 0;
            newIndex      = -1;
            collection.RemoveAt(0);

            currentChange = NotifyCollectionChangedAction.Replace;
            newItem       = 10;
            oldIndex      = 0;
            newIndex      = 0;
            collection[0] = 10;

            currentChange = NotifyCollectionChangedAction.Move;
            newItem       = default;
            oldIndex      = 0;
            newIndex      = 1;
            collection.Move(0, 1);

            currentChange = NotifyCollectionChangedAction.Reset;
            newItem       = default;
            oldIndex      = -1;
            newIndex      = -1;
            collection.Clear();
        }