public void Remove_DoesNotRaisesCollectionChanged_WhenCollectionDoesNotContainItem()
 {
     bool flag = false;
     var observableHash = new ObservableHashSet<int>();
     observableHash.CollectionChanged += (sender, args) => flag = true;
     observableHash.Remove(1);
     Assert.False(flag);
 }
 public void Remove_RaisesCollectionChanged()
 {
     bool flag = false;
     var observableHash = new ObservableHashSet<int>() {1};
     observableHash.CollectionChanged += (sender, args) => flag = true;
     observableHash.Remove(1);
     Assert.True(flag);
 }
        public void Can_remove()
        {
            var hashSet = new ObservableHashSet <string> {
                "Palmer", "Carmack"
            };
            var countChanging     = 0;
            var countChanged      = 0;
            var collectionChanged = 0;
            var currentCount      = 2;
            var countChange       = -1;
            var removing          = new string[0];

            hashSet.PropertyChanging  += (s, a) => AssertCountChanging(hashSet, s, a, currentCount, ref countChanging);
            hashSet.PropertyChanged   += (s, a) => AssertCountChanged(hashSet, s, a, ref currentCount, countChange, ref countChanged);
            hashSet.CollectionChanged += (s, a) =>
            {
                Assert.Equal(NotifyCollectionChangedAction.Remove, a.Action);
                Assert.Equal(removing, a.OldItems.OfType <string>());
                Assert.Null(a.NewItems);
                collectionChanged++;
            };

            removing = new[] { "Palmer" };
            Assert.True(hashSet.Remove("Palmer"));

            Assert.Equal(1, countChanging);
            Assert.Equal(1, countChanged);
            Assert.Equal(1, collectionChanged);
            Assert.Equal(new[] { "Carmack" }, hashSet);

            removing = new[] { "Carmack" };
            Assert.True(hashSet.Remove("Carmack"));

            Assert.Equal(2, countChanging);
            Assert.Equal(2, countChanged);
            Assert.Equal(2, collectionChanged);
            Assert.Empty(hashSet);

            Assert.False(hashSet.Remove("Palmer"));

            Assert.Equal(2, countChanging);
            Assert.Equal(2, countChanged);
            Assert.Equal(2, collectionChanged);
            Assert.Empty(hashSet);
        }
        public void Items_removed_from_ObservableHashSet_are_removed_from_binding_list()
        {
            var item = new ListElement(4);
            var oc   = new ObservableHashSet <ListElement> {
                3, 1, item, 1, 5, 9
            };
            var obbl = new ObservableBackedBindingList <ListElement>(oc);

            oc.Remove(item);

            Assert.False(obbl.Contains(item));
            Assert.Equal(5, obbl.Count);
        }
        public void TrimExcess_doesnt_throw()
        {
            var bigData   = CreateTestData();
            var smallData = CreateTestData(10);

            var hashSet = new ObservableHashSet <int>(bigData.Concat(smallData));

            foreach (var item in bigData)
            {
                hashSet.Remove(item);
            }

            hashSet.TrimExcess();
        }
Beispiel #6
0
        public void StartFollowActions(ObservableHashSet <FollowerUI> toFollow,
                                       ObservableHashSet <FollowerUI> unFollow, Action <ActionPerformArgument> callback)
        {
            var args = new ActionPerformArgument
            {
                Total     = toFollow.Count + unFollow.Count,
                Performed = 0
            };

            foreach (var l in toFollow)
            {
                var task = _instaApi.FollowUserAsync(l.OtherUser.Pk);
                task.GetAwaiter().OnCompleted(
                    () =>
                {
                    args.Performed++;
                    if (!task.Result.Value.Following)
                    {
                        toFollow.Remove(l);
                    }
                    callback(args);
                });
            }

            foreach (var l in unFollow)
            {
                var task = _instaApi.UnFollowUserAsync(l.OtherUser.Pk);
                task.GetAwaiter().OnCompleted(
                    () => {
                    args.Performed++;
                    if (task.Result.Value.Following)
                    {
                        unFollow.Remove(l);
                    }
                    callback(args);
                });
            }
        }
        public void WhenRemove_ThenRaisesCountPropertyChanged() {
            // Arrange
            var target = new ObservableHashSet<int>();

            target.Add(1);
            target.Add(2);
            target.Add(3);
            target.Add(4);

            bool wasEventRaised = false;
            target.PropertyChanged += (s, e) => {
                if (e.PropertyName == ObservableHashSet<int>.PropertyNames.Count) {
                    wasEventRaised = true;
                }
            };

            // Act
            target.Remove(3);

            // Assert
            Assert.IsTrue(wasEventRaised);
        }
        public void WhenRemove_ThenRaisesCollectionChanged() {
            // Arrange
            var target = new ObservableHashSet<int>();

            target.Add(1);
            target.Add(2);
            target.Add(3);
            target.Add(4);

            bool wasEventRaised = false;
            target.CollectionChanged += (s, e) => {
                if (e.Action == NotifyCollectionChangedAction.Remove && e.OldItems.Contains(3)) {
                    wasEventRaised = true;
                }
            };

            // Act
            target.Remove(3);

            // Assert
            Assert.IsTrue(wasEventRaised);
        }
        public void WhenRemove_ThenCountUpdated() {
            // Arrange
            var target = new ObservableHashSet<int>();

            target.Add(1);
            target.Add(2);
            target.Add(3);
            target.Add(4);

            // Act
            target.Remove(3);

            var actual = target.Count;

            // Assert
            Assert.AreEqual(3, actual);
        }
Beispiel #10
0
        public void DoesSupportObservableHashSet()
        {
            List <string> expected;
            List <int>    expectedForked;

            ObservableHashSet <int> source1 = new ObservableHashSet <int>();
            ObservableHashSet <int> source2 = new ObservableHashSet <int>();
            ObservableHashSet <int> source3 = new ObservableHashSet <int>();

            List <string> projection1 = new List <string>();
            List <string> projection2 = new List <string>();
            List <int>    projection3 = new List <int>();

            Func <int, string> transformation  = i => i.ToString();
            Func <int, bool>   filterPredicate = i => i <= 2;

            ListBinding <string> binding = new ListBinding <string>()
                                           .AddSource(source1, convert: transformation, filter: filterPredicate)
                                           .AddSource(source2, convert: transformation, filter: filterPredicate)
                                           .AddSource(source3, convert: transformation, filter: filterPredicate);

            source1.Add(0);
            source2.Add(1);
            source3.Add(2);
            source3.Add(3);
            source2.Add(4);

            binding.AddTarget(projection1);

            source1.Add(5);
            source2.Add(6);

            binding.AddTarget(projection2);

            source1.Add(7);
            source3.Add(8);

            expected = source1.Concat(source2).Concat(source3).Where(filterPredicate).Select(transformation).ToList();
            expected.Sort();
            Assert.Equal(expected, projection1);
            Assert.Equal(expected, projection2);

            var bindingForked = binding.Select <int>(item => int.Parse(item));

            source2.Remove(4);
            source1.Remove(5);
            source2.Remove(6);

            expected = source1.Concat(source2).Concat(source3).Where(filterPredicate).Select(transformation).ToList();
            expected.Sort();
            Assert.Equal(expected, projection1);
            Assert.Equal(expected, projection2);

            source1.Add(4);
            source3.Add(5);
            source1.Add(6);

            expected = source1.Concat(source2).Concat(source3).Where(filterPredicate).Select(transformation).ToList();
            expected.Sort();
            Assert.Equal(expected, projection1);
            Assert.Equal(expected, projection2);

            source1.Clear();

            expected = source1.Concat(source2).Concat(source3).Where(filterPredicate).Select(transformation).ToList();
            expected.Sort();
            Assert.Equal(expected, projection1);
            Assert.Equal(expected, projection2);

            source3.Clear();
            source2.Clear();

            expected = source1.Concat(source2).Concat(source3).Where(filterPredicate).Select(transformation).ToList();
            expected.Sort();
            Assert.Equal(expected, projection1);
            Assert.Equal(expected, projection2);

            expectedForked = source1.Concat(source2).Concat(source3).Where(filterPredicate).ToList();
            expectedForked.Sort();
            Assert.Equal(expectedForked, projection3);
        }
Beispiel #11
0
 public bool Remove(GameObjectMetadata metadata)
 {
     return(_collection.Remove(metadata));
 }