Example #1
0
        public void ROC_Insert()
        {
            roc.AddRange(new[] { "A", "B", "C" });
            roc.InsertRange(1, new[] { "D", "E", "F" });

            Assert.AreEqual(2, changedevents.Count);
            Assert.AreEqual("Reset", changedevents.Last());
            Assert.AreEqual("A", roc[0]);
            Assert.AreEqual("D", roc[1]);
            Assert.AreEqual("B", roc[4]);
        }
Example #2
0
        public void TestInsertRange()
        {
            List <int> list = new List <int> {
                5, 6
            };

            collection.InsertRange(2, list.Select((arg) => IncrementCounter(arg)).Where(arg => arg >= 0));

            Assert.AreEqual(2, counter);
            Assert.AreEqual(2, index);
            Assert.AreEqual(5, collection [index]);
            Assert.AreEqual(actionsPerformed [0], NotifyCollectionChangedAction.Add);
            Assert.AreEqual(1, notifications);
            Assert.AreEqual(1, countNotifications);
        }
Example #3
0
        protected virtual void HandleViewModelsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (editing)
            {
                return;
            }
            editing = true;
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                model.InsertRange(e.NewStartingIndex, e.NewItems.OfType <TViewModel> ().Select((arg) => arg.Model));
                foreach (TViewModel vm in e.NewItems)
                {
                    modelToViewModel [vm.Model] = vm;
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                model.RemoveRange(e.OldItems.OfType <TViewModel> ().Select((arg) => arg.Model));
                foreach (TViewModel vm in e.OldItems)
                {
                    modelToViewModel [vm.Model] = vm;
                }
                break;

            case NotifyCollectionChangedAction.Replace:
                model.Reset(ViewModels.Select(vm => vm.Model));
                foreach (TViewModel vm in ViewModels)
                {
                    modelToViewModel [vm.Model] = vm;
                }

                break;

            case NotifyCollectionChangedAction.Reset:
                model.Reset(ViewModels.Select(vm => vm.Model));
                modelToViewModel.Clear();
                foreach (TViewModel vm in ViewModels)
                {
                    modelToViewModel.Add(vm.Model, vm);
                }
                break;
            }
            editing = false;
        }