示例#1
0
            /// <summary>
            /// Handles the <see cref="INotifyCollectionChanged.CollectionChanged"/> event of the
            /// master list of plugins.
            /// </summary>
            /// <remarks>
            /// This applies any changes that are made to the maser list to the transacted list
            /// with which we are currently working.
            /// </remarks>
            /// <param name="sender">The object that raised the event.</param>
            /// <param name="e">A <see cref="NotifyCollectionChangedEventArgs"/> describing the event arguments.</param>
            private void MasterPlugins_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
            {
                switch (e.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    foreach (Plugin plgAdded in e.NewItems)
                    {
                        m_ostActivePlugins.Add(plgAdded);
                    }
                    break;

                case NotifyCollectionChangedAction.Remove:
                    foreach (Plugin plgRemoved in e.OldItems)
                    {
                        m_ostActivePlugins.Remove(plgRemoved);
                    }
                    break;

                case NotifyCollectionChangedAction.Replace:
                    foreach (Plugin plgRemoved in e.OldItems)
                    {
                        m_ostActivePlugins.Remove(plgRemoved);
                    }
                    foreach (Plugin plgAdded in e.NewItems)
                    {
                        m_ostActivePlugins.Add(plgAdded);
                    }
                    break;

                case NotifyCollectionChangedAction.Reset:
                    m_ostActivePlugins.Clear();
                    break;
                }
            }
        public void ObserveSkilledPassiveNodesGeneratesCorrectValues()
        {
            var modifiers    = CreateModifiers(6);
            var skilledNodes = CreateSkillNodes(3);
            var parseResults = CreateParseResults(modifiers);
            var expected     = new[]
            {
                new CalculatorUpdate(modifiers, new Modifier[0]),
                new CalculatorUpdate(new Modifier[0], parseResults[0].Modifiers),
                new CalculatorUpdate(new Modifier[0], parseResults[1].Modifiers),
            };
            var observableSet = new ObservableSet <SkillNode>();
            var sut           = CreateSut(MockSkilledPassiveNodeParser(parseResults));

            var actual = new List <CalculatorUpdate>();

            using (sut.ObserveSkilledPassiveNodes(observableSet).Subscribe(actual.Add))
            {
                observableSet.UnionWith(skilledNodes);
                observableSet.Remove(skilledNodes[0]);
                observableSet.Remove(skilledNodes[1]);
            }

            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        /// Handles the <see cref="INotifyPropertyChanged.PropertyChanged"/> event of tasks.
        /// </summary>
        /// <remarks>
        /// This adds or removes tasks from the active task list as appropriate.
        /// </remarks>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">A <see cref="PropertyChangedEventArgs"/> describing the event arguments.</param>
        private void Task_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName.Equals(ObjectHelper.GetPropertyName <AddModTask>(x => x.IsActive)))
            {
                AddModTask tskTask = (AddModTask)sender;
                if (tskTask.IsActive)
                {
                    m_setActiveTasks.Add(tskTask);
                }
                else
                {
                    m_setActiveTasks.Remove(tskTask);
                }
            }

            if (e.PropertyName.Equals(ObjectHelper.GetPropertyName <AddModTask>(x => x.TaskSpeed)))
            {
                int   speed       = 0;
                Int64 progress    = 0;
                Int64 maxprogress = 0;
                foreach (AddModTask Task in ActiveTasks)
                {
                    speed       += Task.TaskSpeed;
                    progress    += Task.ItemProgress;
                    maxprogress += Task.ItemProgressMaximum;
                }

                TotalMaximumProgress = maxprogress;
                TotalProgress        = progress;
                TotalSpeed           = speed;
            }
        }
示例#4
0
        public void TestRemove()
        {
            ExpectCollectionChange(NotifyCollectionChangedAction.Remove, "item 2");

            _set.Remove("item");
            ExpectChangeCalls(0);

            _set.Remove("item 2");
            ExpectChangeCalls(1);

            _set.Remove("item 2");
            ExpectChangeCalls(0);
        }
        public void TestRemove()
        {
            ExpectCollectionRemove("item 2");

            _set.Remove("item");
            ExpectChangeCalls(0);

            _set.Remove("item 2");
            ExpectChangeCalls(1);

            _set.Remove("item 2");
            ExpectChangeCalls(0);
        }
 /// <summary>
 /// Handles the <see cref="INotifyPropertyChanged.PropertyChanged"/> event of tasks.
 /// </summary>
 /// <remarks>
 /// This adds or removes tasks from the active task list as appropriate.
 /// </remarks>
 /// <param name="sender">The object that raised the event.</param>
 /// <param name="e">A <see cref="PropertyChangedEventArgs"/> describing the event arguments.</param>
 private void Task_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName.Equals(ObjectHelper.GetPropertyName <IBackgroundTask>(x => x.IsActive)))
     {
         IBackgroundTask tskTask = (IBackgroundTask)sender;
         if (tskTask.IsActive)
         {
             m_setActiveTasks.Add(tskTask);
         }
         else
         {
             m_setActiveTasks.Remove(tskTask);
         }
     }
 }
示例#7
0
        public void TestRemove()
        {
            var list = new List <string> {
                "aaa", "bbb", "ccc"
            };
            var set = new ObservableSet <string>(list);

            Assert.Equal(set.Count, list.Count);
            bool propertyChangedInvoked   = false;
            bool collectionChangedInvoked = false;

            set.PropertyChanged += (sender, e) =>
            {
                Assert.Equal(nameof(ObservableSet <string> .Count), e.PropertyName);
                propertyChangedInvoked = true;
            };
            set.CollectionChanged += (sender, e) =>
            {
                Assert.Equal(NotifyCollectionChangedAction.Remove, e.Action);
                Assert.Equal(1, e.OldStartingIndex);
                Assert.NotNull(e.OldItems);
                Assert.Equal(1, e.OldItems.Count);
                Assert.Equal("bbb", e.OldItems[0]);
                collectionChangedInvoked = true;
            };
            set.Remove("bbb");
            Assert.Equal(2, set.Count);
            Assert.Equal("aaa", set[0]);
            Assert.Equal("ccc", set[1]);
            Assert.True(propertyChangedInvoked);
            Assert.True(collectionChangedInvoked);
        }
示例#8
0
        public void remove_should_raise_propertychanged()
        {
            bool eventWasRaisedForCount   = false;
            bool eventWasRaisedForIsEmpty = false;

            var observableSet = new ObservableSet <int> {
                1, 2, 3
            };

            observableSet.PropertyChanged += (sender, args) =>
            {
                sender.Should().Be.EqualTo(observableSet);
                if (args.PropertyName == ISEMPTY_PROPERTY_NAME)
                {
                    eventWasRaisedForIsEmpty = true;
                }
                if (args.PropertyName == COUNT_PROPERTY_NAME)
                {
                    eventWasRaisedForCount = true;
                }
            };

            observableSet.Remove(1);
            eventWasRaisedForIsEmpty.Should().Be.True();
            eventWasRaisedForCount.Should().Be.True();
        }
示例#9
0
        ///// <summary>
        ///// Given a collection, will move an item from the oldIndex to the newIndex.
        ///// </summary>
        //public void MoveItemTest(ObservableSet<string> collection, int oldIndex, int newIndex)
        //{
        //    INotifyPropertyChanged collectionPropertyChanged = collection;
        //    collectionPropertyChanged.PropertyChanged += Collection_PropertyChanged;
        //    _expectedPropertyChanged = new[] { new PropertyNameExpected(ITEMARRAY) };

        //    collection.CollectionChanged += Collection_CollectionChanged;

        //    string itemAtOldIndex = collection[oldIndex];

        //    ExpectedCollectionChangedFired++;
        //    ExpectedAction = NotifyCollectionChangedAction.Move;
        //    ExpectedNewItems = new string[] { itemAtOldIndex };
        //    ExpectedNewStartingIndex = newIndex;
        //    ExpectedOldItems = new string[] { itemAtOldIndex };
        //    ExpectedOldStartingIndex = oldIndex;

        //    int expectedCount = collection.Count;

        //    collection.Move(oldIndex, newIndex);
        //    Assert.Equal(expectedCount, collection.Count);
        //    Assert.Equal(itemAtOldIndex, collection[newIndex]);
        //    Assert.Equal(ExpectedCollectionChangedFired, NumCollectionChangedFired);

        //    foreach (var item in _expectedPropertyChanged)
        //        Assert.True(item.IsFound, "The propertychanged event should have fired for" + item.Name + ", since we just moved an item");

        //    collection.CollectionChanged -= Collection_CollectionChanged;
        //    collectionPropertyChanged.PropertyChanged -= Collection_PropertyChanged;
        //}

        ///// <summary>
        ///// Will set that new item at the specified index in the given collection.
        ///// </summary>
        //public void ReplaceItemTest(ObservableSet<string> collection, int index, string newItem)
        //{
        //    INotifyPropertyChanged collectionPropertyChanged = collection;
        //    collectionPropertyChanged.PropertyChanged += Collection_PropertyChanged;
        //    _expectedPropertyChanged = new[] { new PropertyNameExpected(ITEMARRAY) };

        //    collection.CollectionChanged += Collection_CollectionChanged;

        //    string itemAtOldIndex = collection.ToArray()[index];

        //    ExpectedCollectionChangedFired++;
        //    ExpectedAction = NotifyCollectionChangedAction.Replace;
        //    ExpectedNewItems = new string[] { newItem };
        //    ExpectedNewStartingIndex = index;
        //    ExpectedOldItems = new string[] { itemAtOldIndex };
        //    ExpectedOldStartingIndex = index;

        //    int expectedCount = collection.Count;

        //    collection[index] = newItem;
        //    Assert.Equal(expectedCount, collection.Count);
        //    Assert.Equal(newItem, collection[index]);
        //    Assert.Equal(ExpectedCollectionChangedFired, NumCollectionChangedFired);

        //    foreach (var item in _expectedPropertyChanged)
        //        Assert.True(item.IsFound, "The propertychanged event should have fired for" + item.Name + ", since we just replaced an item");

        //    collection.CollectionChanged -= Collection_CollectionChanged;
        //    collectionPropertyChanged.PropertyChanged -= Collection_PropertyChanged;
        //}

        /// <summary>
        /// Given a collection, index and item to remove, will try to remove that item
        /// from the index. If the item has duplicates, will verify that only the first
        /// instance was removed.
        /// </summary>
        public void RemoveItemTest(ObservableSet <string> collection, int itemIndex, string itemToRemove, bool isSuccessfulRemove, bool hasDuplicates)
        {
            INotifyPropertyChanged collectionPropertyChanged = collection;

            collectionPropertyChanged.PropertyChanged += Collection_PropertyChanged;
            _expectedPropertyChanged = new[]
            {
                new PropertyNameExpected(COUNT),
                //new PropertyNameExpected(ITEMARRAY)
            };

            collection.CollectionChanged += Collection_CollectionChanged;

            if (isSuccessfulRemove)
            {
                ExpectedCollectionChangedFired++;
            }

            ExpectedAction           = NotifyCollectionChangedAction.Remove;
            ExpectedNewItems         = null;
            ExpectedNewStartingIndex = -1;
            ExpectedOldItems         = new string[] { itemToRemove };
            ExpectedOldStartingIndex = itemIndex;

            int expectedCount = isSuccessfulRemove ? collection.Count - 1 : collection.Count;

            bool removedItem = collection.Remove(itemToRemove);

            Assert.Equal(expectedCount, collection.Count);
            Assert.Equal(ExpectedCollectionChangedFired, NumCollectionChangedFired);

            if (isSuccessfulRemove)
            {
                foreach (var item in _expectedPropertyChanged)
                {
                    Assert.True(item.IsFound, "The propertychanged event should have fired for" + item.Name + ", since there were items removed.");
                }

                Assert.True(removedItem, "Should have been successful in removing the item.");
            }
            else
            {
                foreach (var item in _expectedPropertyChanged)
                {
                    Assert.False(item.IsFound, "The propertychanged event should have fired for" + item.Name + ", since there were no items removed.");
                }

                Assert.False(removedItem, "Should not have been successful in removing the item.");
            }
            if (hasDuplicates)
            {
                return;
            }

            Assert.DoesNotContain(itemToRemove, collection);

            collection.CollectionChanged -= Collection_CollectionChanged;
            collectionPropertyChanged.PropertyChanged -= Collection_PropertyChanged;
        }
示例#10
0
        public void remove_should_work()
        {
            var observableSet = new ObservableSet <int> {
                1, 2, 3, 4, 5
            };

            observableSet.Remove(1);
            observableSet.Count.Should().Be.EqualTo(4);
            observableSet.Should().Have.SameSequenceAs(new[] { 2, 3, 4, 5 });
        }
        internal void UpdateAssetStatus(AssetViewModel asset)
        {
            if (asset.Sources.NeedUpdateFromSource && !asset.IsDeleted)
            {
                assetsToUpdate.Add(asset);
            }
            else
            {
                assetsToUpdate.Remove(asset);
            }

            UpdateAllAssetsWithModifiedSourceCommand.IsEnabled = assetsToUpdate.Count > 0;
        }
示例#12
0
        public void SetOperationsTest()
        {
            const int initialCount = 15;
            const int removeItems  = 4;
            const int insertItems  = 2;
            var       items        = new[] { 40, 63, 98, 20, 24, 76, 96, 53, 5, 11, 29, 12, 46, 59, 7, 45, 86, 91, 57, 95 };
            var       indexes      = new[] { 6, 2, 5, 11, 0, 3, 13, 1 };

            var originalSet = new HashSet <Person>(items.Take(initialCount).Select(x => new Person(x)), new PersonEqualityComparer());
            var set         = new ObservableSet <Person>(originalSet);
            var sorted      = new SortedReadOnlyObservableList <Person>(set, (x, y) => x.Age.CompareTo(y.Age),
                                                                        new PersonEqualityComparer(), nameof(Person.Age));

            Assert.AreEqual(initialCount, set.Count);
            Assert.AreEqual(initialCount, sorted.Count);
            Assert.IsTrue(items.Take(initialCount).Select(x => new Person(x)).OrderBy(p => p.Age).SequenceEqual(sorted, new PersonEqualityComparer()));

            foreach (var person in indexes.Take(removeItems).Select(i => new Person(items[i])))
            {
                set.Remove(person);
            }

            Assert.AreEqual(initialCount - removeItems, set.Count);
            Assert.AreEqual(initialCount - removeItems, sorted.Count);
            Assert.IsTrue(originalSet.OrderBy(p => p.Age).SequenceEqual(sorted, new PersonEqualityComparer()));

            foreach (var person in items.Skip(initialCount).Take(insertItems).Select(x => new Person(x)))
            {
                set.Add(person);
            }

            Assert.AreEqual(initialCount - removeItems + insertItems, set.Count);
            Assert.AreEqual(initialCount - removeItems + insertItems, sorted.Count);
            Assert.IsTrue(originalSet.OrderBy(p => p.Age).SequenceEqual(sorted, new PersonEqualityComparer()));

            foreach (var result in indexes.Skip(removeItems)
                     .Zip(items.Skip(initialCount + insertItems),
                          (i, x) => new { OldItem = new Person(items[i]), NewItem = new Person(x) }))
            {
                set.SymmetricExceptWith(new[] { result.OldItem, result.NewItem });
            }

            Assert.AreEqual(initialCount - removeItems + insertItems, set.Count);
            Assert.AreEqual(initialCount - removeItems + insertItems, sorted.Count);
            Assert.IsTrue(originalSet.OrderBy(p => p.Age).SequenceEqual(sorted, new PersonEqualityComparer()));

            set.Clear();

            Assert.AreEqual(0, set.Count);
            Assert.AreEqual(0, sorted.Count);
        }
示例#13
0
        public void TestIndexOf()
        {
            var list = new List <string> {
                "aaa", "bbb", "ccc"
            };
            var set = new ObservableSet <string>(list);

            Assert.Equal(set.IndexOf("aaa"), 0);
            Assert.Equal(set.IndexOf("bbb"), 1);
            Assert.Equal(set.IndexOf("ccc"), 2);
            Assert.Equal(set.IndexOf("ddd"), -1);
            set.Add("ddd");
            Assert.Equal(set.IndexOf("ddd"), 3);
            set.Remove("bbb");
            Assert.Equal(set.IndexOf("bbb"), -1);
            Assert.Equal(set.IndexOf("ddd"), 2);
        }
示例#14
0
        public void TestIndexOf()
        {
            var list = new List <string> {
                "aaa", "bbb", "ccc"
            };
            var set = new ObservableSet <string>(list);

            Assert.Equal(0, set.IndexOf("aaa"));
            Assert.Equal(1, set.IndexOf("bbb"));
            Assert.Equal(2, set.IndexOf("ccc"));
            Assert.Equal(-1, set.IndexOf("ddd"));
            set.Add("ddd");
            Assert.Equal(3, set.IndexOf("ddd"));
            set.Remove("bbb");
            Assert.Equal(-1, set.IndexOf("bbb"));
            Assert.Equal(2, set.IndexOf("ddd"));
        }
示例#15
0
        public void SetOperationsTest()
        {
            var values = new[] { 15, 14, 89, 56, 8, 68, 17, 39, 31, 93, 78, 80, 87, 85, 57, 20, 6, 1 };

            var people     = new ObservableSet <Observable>(values.Select(x => new Observable(x)).ToList());
            var transfList = new DynamicTransformingReadOnlyObservableList <Observable, int>(people,
                                                                                             x => x.Subject);
            var copy = new TransformingReadOnlyObservableList <int, int>(transfList, x => x);

            Assert.AreEqual(people.Count, transfList.Count);
            Assert.IsTrue(new HashSet <int>(people.Select(x => x.Prop)).SetEquals(transfList));
            Assert.IsTrue(new HashSet <int>(people.Select(x => x.Prop)).SetEquals(copy));

            people.Add(new Observable(19));
            people.First().Prop = 82;
            people.Remove(people.Last());

            Assert.AreEqual(people.Count, transfList.Count);
            Assert.IsTrue(new HashSet <int>(people.Select(x => x.Prop)).SetEquals(transfList));
            Assert.IsTrue(new HashSet <int>(people.Select(x => x.Prop)).SetEquals(copy));
        }
示例#16
0
        public void remove_should_raise_collectionchanged()
        {
            bool eventWasRaised = false;


            var observableSet = new ObservableSet <int> {
                1, 2, 3
            };

            observableSet.CollectionChanged += (sender, args) =>
            {
                sender.Should().Be.EqualTo(observableSet);
                args.Action.Should().Be.EqualTo(
                    NotifyCollectionChangedAction.Remove);
                args.OldItems[0].Should().Be.EqualTo(2);
                args.OldStartingIndex.Should().Be.EqualTo(1);
                eventWasRaised = true;
            };

            observableSet.Remove(2);
            eventWasRaised.Should().Be.True();
        }
        public void ObserveSkillsGeneratesCorrectValues()
        {
            var modifiers    = CreateModifiers(6);
            var skills       = CreateSkills();
            var parseResults = CreateParseResults(modifiers);
            var expected     = new[]
            {
                new CalculatorUpdate(parseResults[0].Modifiers, new Modifier[0]),
                new CalculatorUpdate(new Modifier[0], parseResults[0].Modifiers),
            };
            var parser = MockSkillParser(skills, parseResults);
            var sut    = CreateSut(parser);
            var observableCollection = new ObservableSet <IReadOnlyList <Skill> >();

            var actual = new List <CalculatorUpdate>();

            using (sut.ObserveSkills(observableCollection).Subscribe(actual.Add))
            {
                observableCollection.Add(skills[0]);
                observableCollection.Remove(skills[0]);
            }

            Assert.AreEqual(expected, actual);
        }
示例#18
0
 public void TestRemove()
 {
     var list = new List<string> { "aaa", "bbb", "ccc" };
     var set = new ObservableSet<string>(list);
     Assert.AreEqual(set.Count, list.Count);
     bool propertyChangedInvoked = false;
     bool collectionChangedInvoked = false;
     set.PropertyChanged += (sender, e) =>
     {
         Assert.AreEqual(e.PropertyName, nameof(ObservableSet<string>.Count));
         propertyChangedInvoked = true;
     };
     set.CollectionChanged += (sender, e) =>
     {
         Assert.AreEqual(e.Action, NotifyCollectionChangedAction.Remove);
         Assert.AreEqual(e.OldStartingIndex, 1);
         Assert.NotNull(e.OldItems);
         Assert.AreEqual(e.OldItems.Count, 1);
         Assert.AreEqual(e.OldItems[0], "bbb");
         collectionChangedInvoked = true;
     };
     set.Remove("bbb");
     Assert.AreEqual(set.Count, 2);
     Assert.AreEqual(set[0], "aaa");
     Assert.AreEqual(set[1], "ccc");
     Assert.True(propertyChangedInvoked);
     Assert.True(collectionChangedInvoked);
 }
示例#19
0
 public void TestIndexOf()
 {
     var list = new List<string> { "aaa", "bbb", "ccc" };
     var set = new ObservableSet<string>(list);
     Assert.AreEqual(set.IndexOf("aaa"), 0);
     Assert.AreEqual(set.IndexOf("bbb"), 1);
     Assert.AreEqual(set.IndexOf("ccc"), 2);
     Assert.AreEqual(set.IndexOf("ddd"), -1);
     set.Add("ddd");
     Assert.AreEqual(set.IndexOf("ddd"), 3);
     set.Remove("bbb");
     Assert.AreEqual(set.IndexOf("bbb"), -1);
     Assert.AreEqual(set.IndexOf("ddd"), 2);
 }