示例#1
0
        public void ModifyOnlySubset()
        {
            // Arrange
            ObservableCollection <int>        set    = new ObservableCollection <int>(new[] { 2, 3, 5, 6, 7 });
            IObservableCollectionSubset <int> subSet = set.Where(i => i % 2 == 0);

            CollectionListener collectionListener = new CollectionListener();

            subSet.AddListener(collectionListener);

            int[] array1 = subSet.ToArray();

            // Act
            subSet.Remove(6, false);
            int[] array2 = subSet.ToArray();

            // Assert
            CollectionAssert.AreEqual(new[] { 2, 6 }, array1);
            CollectionAssert.AreEqual(new[] { 2 }, array2);
            CollectionAssert.AreEqual(new[] { 2, 3, 5, 6, 7 }, set); // Origin set mustn't be modified
            Assert.AreEqual(1, collectionListener.Removed);
        }
示例#2
0
        public void WhereIteration()
        {
            // Arrange
            ObservableCollection <int>  set    = new ObservableCollection <int>(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            IObservableEnumerable <int> subset = set.Where(i => i % 2 == 0);

            CollectionListener collectionListener = new CollectionListener();

            subset.AddListener(collectionListener);

            int[] array1 = subset.ToArray();

            // Act
            set.Add(12);
            set.Add(13);
            set.Add(14);
            int[] array2 = subset.ToArray();

            // Assert
            CollectionAssert.AreEqual(new[] { 2, 4, 6, 8 }, array1);
            CollectionAssert.AreEqual(new[] { 2, 4, 6, 8, 12, 14 }, array2);
            CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 13, 14 }, set); // Origin set must(!) be modified
            Assert.AreEqual(2, collectionListener.Added);
        }