Exemplo n.º 1
0
        public void Test4()
        {
            OcConsumer consumer = new OcConsumer();
            ObservableCollection <int> sourceCollection = (new ObservableCollection <int>(new [] { 1, 2, 3 }));
            Extending <int>            collection       = sourceCollection.Extending().For(consumer);

            collection.InsertItemRequestHandler = (index, newItem) =>
            {
                sourceCollection.Insert(index, newItem);
            };

            collection.RemoveItemRequestHandler = (index) =>
            {
                sourceCollection.Remove(index);
            };

            collection.SetItemRequestHandler = (index, newItem) =>
            {
                sourceCollection[index] = newItem;
            };

            collection.MoveItemRequestHandler = (oldIndex, newIndex) =>
            {
                sourceCollection.Move(oldIndex, newIndex);
            };

            collection.ClearItemsRequestHandler = () =>
            {
                sourceCollection.Clear();
            };

            test(collection);

            consumer.Dispose();
        }
Exemplo n.º 2
0
        public void Test4()
        {
            OcConsumer consumer = new OcConsumer();
            ObservableCollection <int> sourceCollection = (new ObservableCollection <int>(new [] { 1, 2, 3 }));

            sourceCollection.CollectionChanged += (sender, args) =>
            {
                _lastNotifyCollectionChangedEventArgs = args;
            };

            Extending <int> collection = sourceCollection.Extending().For(consumer);


            Action <int, int> collectionInsertItemRequestHandler = (index, newItem) =>
            {
                sourceCollection.Insert(index, newItem);
            };

            collection.InsertItemRequestHandler = collectionInsertItemRequestHandler;
            Assert.IsTrue(collection.InsertItemRequestHandler == collectionInsertItemRequestHandler);

            Action <int> collectionRemoveItemRequestHandler = (index) =>
            {
                sourceCollection.Remove(index);
            };

            collection.RemoveItemRequestHandler = collectionRemoveItemRequestHandler;
            Assert.IsTrue(collection.RemoveItemRequestHandler == collectionRemoveItemRequestHandler);

            Action <int, int> collectionSetItemRequestHandler = (index, newItem) =>
            {
                sourceCollection[index] = newItem;
            };

            collection.SetItemRequestHandler = collectionSetItemRequestHandler;
            Assert.IsTrue(collection.SetItemRequestHandler == collectionSetItemRequestHandler);

            Action <int, int> collectionMoveItemRequestHandler = (oldIndex, newIndex) =>
            {
                sourceCollection.Move(oldIndex, newIndex);
            };

            collection.MoveItemRequestHandler = collectionMoveItemRequestHandler;
            Assert.IsTrue(collection.MoveItemRequestHandler == collectionMoveItemRequestHandler);

            Action collectionClearItemsRequestHandler = () =>
            {
                sourceCollection.Clear();
            };

            collection.ClearItemsRequestHandler = collectionClearItemsRequestHandler;
            Assert.IsTrue(collection.ClearItemsRequestHandler == collectionClearItemsRequestHandler);

            test(collection);

            consumer.Dispose();
        }
Exemplo n.º 3
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();
        }