Beispiel #1
0
        public void RemoveRange_NotSequentialRemove3_FiresRemoveEvent()
        {
            var col = new ConcurrentObservableCollection <string>(new[] { "a", "b", "c", "d", "e", "f", "g" });

            var received = new List <NotifyCollectionChangedEventArgs>();

            col.CollectionChanged += (sender, args) =>
            {
                if (args.Action == NotifyCollectionChangedAction.Remove)
                {
                    received.Add(args);
                }
            };
            col.RemoveRange(new[] { "b", "c", "a", "g" });

            received.Count.Should().Be(3);
            received[0].OldItems.Should().BeEquivalentTo(new[] { "b", "c" });
            received[0].OldStartingIndex.Should().Be(1);
            received[1].OldItems.Should().BeEquivalentTo(new[] { "a" });
            received[1].OldStartingIndex.Should().Be(0);
            received[2].OldItems.Should().BeEquivalentTo(new[] { "g" });
            received[2].OldStartingIndex.Should().Be(3);

            col.Should().BeEquivalentTo("d", "e", "f");
        }
        public void Test_ConcurrentObservableCollection_RemoveRange_ByIndex()
        {
            var initial     = Enumerable.Range(0, 100).ToList();
            var startIndex  = 50;
            var removeCount = 40;
            var collection  = new ConcurrentObservableCollection <int>();

            collection.AddRange(initial);
            Assert.AreEqual(100, collection.Count);

            // Record all the collection changed events
            List <(object, NotifyCollectionChangedEventArgs)> returnedList = new List <(object, NotifyCollectionChangedEventArgs)>();

            collection.CollectionChanged += (s, e) => returnedList.Add((s, e));

            collection.RemoveRange(startIndex, removeCount);

            // Check just one collection changed event was fired
            Assert.AreEqual(1, returnedList.Count);
            (var returnedObject, var returnedArgs) = returnedList[0];

            Assert.IsNotNull(returnedObject);
            Assert.IsNotNull(returnedArgs);

            Assert.AreEqual(returnedObject, collection);
            Assert.AreEqual(NotifyCollectionChangedAction.Remove, returnedArgs.Action);
            Assert.AreEqual(startIndex, returnedArgs.OldStartingIndex);
            Assert.IsNull(returnedArgs.NewItems);
            Assert.IsNotNull(returnedArgs.OldItems);
            Assert.AreEqual(removeCount, returnedArgs.OldItems.Count);
            var toRemove = initial.Skip(startIndex).Take(removeCount).ToList();

            Assert.IsTrue(CollectionsAreEqual(toRemove, returnedArgs.OldItems));
        }
        public void Write_RemoveRange_ElementsRemoved()
        {
            var col = new ConcurrentObservableCollection <string>(new[] { "b", "c", "d" });

            col.RemoveRange(new[] { "b", "c" });
            CollectionAssert.AreEquivalent(new[] { "d" }, col);
        }
        public void RemoveRange_NotSequentialRemove3_FiresRemoveEvent()
        {
            var col = new ConcurrentObservableCollection <string>(new[] { "a", "b", "c", "d", "e", "f", "g" });

            var received = new List <NotifyCollectionChangedEventArgs>();

            col.CollectionChanged += (sender, args) =>
            {
                if (args.Action == NotifyCollectionChangedAction.Remove)
                {
                    received.Add(args);
                }
            };
            col.RemoveRange(new[] { "b", "c", "a", "g" });

            Assert.That(received.Count, Is.EqualTo(3));

            CollectionAssert.AreEquivalent(received[0].OldItems, new[] { "b", "c" });
            Assert.That(received[0].OldStartingIndex, Is.EqualTo(1));
            CollectionAssert.AreEquivalent(received[1].OldItems, new[] { "a" });
            Assert.That(received[1].OldStartingIndex, Is.EqualTo(0));
            CollectionAssert.AreEquivalent(received[2].OldItems, new[] { "g" });
            Assert.That(received[2].OldStartingIndex, Is.EqualTo(3));
            CollectionAssert.AreEquivalent(col, new[] { "d", "e", "f" });
        }
        public void Write_RemoveNotExisting_DoesntFail()
        {
            var col = new ConcurrentObservableCollection <string>(new[] { "b", "c", "d" });

            col.RemoveRange(new[] { "b", "X" });
            CollectionAssert.AreEquivalent(new[] { "c", "d" }, col);
        }
Beispiel #6
0
        public void Write_RemoveRange_ElementsRemoved()
        {
            var col = new ConcurrentObservableCollection <string>(new[] { "b", "c", "d" });

            col.RemoveRange(new[] { "b", "c" });

            col.Should().BeEquivalentTo("d");
        }
Beispiel #7
0
        public void Write_RemoveNotExisting_DoesntFail()
        {
            var col = new ConcurrentObservableCollection <string>(new[] { "b", "c", "d" });

            col.RemoveRange(new[] { "b", "X" });

            col.Should().BeEquivalentTo("c", "d");
        }
Beispiel #8
0
        public void RemoveRange_AcquireRangeToRemoveUsingLinq_RangeRemovedWithoutExceptions()
        {
            var col    = new ConcurrentObservableCollection <string>(new[] { "a", "b", "c" });
            var select = col.Where(c => c.Equals("c"));

            col.RemoveRange(select);

            col.Should().BeEquivalentTo("a", "b");
        }
        public void Write_ComplexOperation_CollectionUpdatedProperly()
        {
            var col = new ConcurrentObservableCollection <string>(new[] { "a", "b", "c" });

            col.Add("d");
            col.Remove("b");
            col.Insert(0, "x");
            col.AddRange(new[] { "z", "f", "y" });
            col.RemoveAt(4);
            col.RemoveRange(new[] { "y", "c" });
            col[2] = "p";
            CollectionAssert.AreEquivalent(new[] { "x", "a", "p", "f" }, col);
        }
        public void RemoveRange_FiresRemoveEvent()
        {
            var    col      = new ConcurrentObservableCollection <string>(new[] { "a", "b", "c" });
            string received = string.Empty;

            col.CollectionChanged += (sender, args) =>
            {
                if (args.Action == NotifyCollectionChangedAction.Remove)
                {
                    received = args.OldItems.OfType <string>().First();
                }
            };
            col.RemoveRange(new[] { "a", "b" });
            Assert.That(received, Is.EqualTo("a"));
        }
Beispiel #11
0
        public void RemoveRange_AllRemove_FiresResetEvent()
        {
            var col = new ConcurrentObservableCollection <string>(new[] { "a", "b", "c", "d", "e", "f" });

            int received = 0;

            col.CollectionChanged += (sender, args) =>
            {
                if (args.Action == NotifyCollectionChangedAction.Reset)
                {
                    ++received;
                }
            };

            col.RemoveRange(new[] { "a", "b", "c", "d", "e", "f" });

            received.Should().Be(1);
            col.Should().BeEmpty();
        }
        public void RemoveRange_AllRemove_FiresResetEvent()
        {
            var col = new ConcurrentObservableCollection <string>(new[] { "a", "b", "c", "d", "e", "f" });

            int received = 0;

            col.CollectionChanged += (sender, args) =>
            {
                if (args.Action == NotifyCollectionChangedAction.Reset)
                {
                    ++received;
                }
            };

            col.RemoveRange(new[] { "a", "b", "c", "d", "e", "f" });

            Assert.That(received, Is.EqualTo(1));
            CollectionAssert.IsEmpty(col);
        }
Beispiel #13
0
        public void RemoveRange_RemoveOneElement_FiresRemoveEvent()
        {
            var col      = new ConcurrentObservableCollection <string>(new[] { "a", "b", "c", "d", "e", "f", "g" });
            var received = new List <string>();
            int oldIndex = -1;

            col.CollectionChanged += (sender, args) =>
            {
                if (args.Action == NotifyCollectionChangedAction.Remove)
                {
                    received.AddRange(args.OldItems.OfType <string>());
                    oldIndex = args.OldStartingIndex;
                }
            };
            col.RemoveRange(new[] { "d" });

            oldIndex.Should().Be(3);
            received.Should().BeEquivalentTo("d");
            col.Should().BeEquivalentTo("a", "b", "c", "e", "f", "g");
        }
        public void RemoveRange_RemoveOneElement_FiresRemoveEvent()
        {
            var col = new ConcurrentObservableCollection <string>(new[] { "a", "b", "c", "d", "e", "f", "g" });

            var received = new List <string>();
            int oldIndex = -1;

            col.CollectionChanged += (sender, args) =>
            {
                if (args.Action == NotifyCollectionChangedAction.Remove)
                {
                    received.AddRange(args.OldItems.OfType <string>());
                    oldIndex = args.OldStartingIndex;
                }
            };
            col.RemoveRange(new[] { "d" });
            Assert.That(oldIndex, Is.EqualTo(3));
            CollectionAssert.AreEquivalent(received, new[] { "d" });
            CollectionAssert.AreEquivalent(col, new[] { "a", "b", "c", "e", "f", "g" });
        }