コード例 #1
0
        private static Tuple <ThreadSafeBindableCollection <int>, SelectCollection <int, int> > BindingList1To5()
        {
            var ints = new ThreadSafeBindableCollection <int>();

            ints.AddRange(new[] { 0, 1, 2, 3, 4 });
            var sc = new SelectCollection <int, int>(ints, i => - i);

            return(Tuple.Create(ints, sc));
        }
コード例 #2
0
        public void RequeryOnSourceChange()
        {
            var list = new ThreadSafeBindableCollection <int>();

            list.AddRange(Enumerable.Range(1, 100));
            var filtered = new WhereCollection <int>(list, i => i % 2 == 0);

            Assert.Equal(50, filtered.Count);
            list.Add(3);
            Assert.Equal(50, filtered.Count);
            list.Add(4);
            Assert.Equal(51, filtered.Count);
        }
コード例 #3
0
        public void DisposeUnhooksFromCollectionChanged()
        {
            ThreadSafeBindableCollection <int> col = new ThreadSafeBindableCollection <int>();
            var mock            = new Mock <IListMonitor <int> >();
            var releaseDelegate = mock.Object.AttachToList(col);

            col.Add(1);
            mock.Verify(o => o.NewItem(It.IsAny <int>(), It.IsAny <int>()), Times.Once());

            releaseDelegate();

            col.Add(1);
            mock.Verify(o => o.NewItem(It.IsAny <int>(), It.IsAny <int>()), Times.Once());
        }
コード例 #4
0
        public SelectManyCollectionTest()
        {
            ints1 = new ThreadSafeBindableCollection <int> {
                0, 1, 2, 3, 4, 5
            };
            ints2 = new ThreadSafeBindableCollection <int> {
                6, 7, 8, 9
            };

            allInts = new ThreadSafeBindableCollection <ThreadSafeBindableCollection <int> >
            {
                ints1, ints2
            };
            smc = new SelectManyCollection <ThreadSafeBindableCollection <int>, int>(allInts, i => i);
        }
コード例 #5
0
        public void SendPropertyChangeNotification()
        {
            var list = new ThreadSafeBindableCollection <int>();

            list.AddRange(Enumerable.Range(1, 100));
            var filtered = new WhereCollection <int>(list, i => i % 2 == 0);
            int ccFired  = 0;

            filtered.PropertyChanged += (s, e) =>
            {
                Assert.Equal(filtered, s);
                Assert.Equal("Count", e.PropertyName);
                ccFired++;
            };
            list.Add(4);
            Assert.Equal(1, ccFired);
        }
コード例 #6
0
        public void SendListChangeNotification()
        {
            var list = new ThreadSafeBindableCollection <int>();

            list.AddRange(Enumerable.Range(1, 100));
            var filtered = new WhereCollection <int>(list, i => i % 2 == 0);
            int ccFired  = 0;

            filtered.CollectionChanged += (s, e) =>
            {
                Assert.Equal(filtered, s);
                Assert.Equal(NotifyCollectionChangedAction.Reset, e.Action);
                ccFired++;
            };
            list.Add(4);
            Assert.Equal(1, ccFired);
        }
コード例 #7
0
        public void PropogateRemoveAtToInerCollection()
        {
            int objectCount = 0;
            var baseColl    = new ThreadSafeBindableCollection <int>();
            var coll        = new SelectCollection <int, IntHolder>(baseColl,
                                                                    i => new IntHolder(objectCount++));

            baseColl.Add(1);
            baseColl.Add(2);
            baseColl.Add(3);

            Assert.Equal(0, coll[0].Value);
            Assert.Equal(1, coll[1].Value);
            Assert.Equal(2, coll[2].Value);

            coll.RemoveAt(1);
            Assert.Equal(2, coll[1].Value);
        }
コード例 #8
0
        public void SelectCollectionCachesObjects()
        {
            int objectCount = 0;
            var baseColl    = new ThreadSafeBindableCollection <int>();
            var coll        = new SelectCollection <int, IntHolder>(baseColl,
                                                                    i => new IntHolder(objectCount++));

            baseColl.Add(1);
            baseColl.Add(2);
            baseColl.Add(3);

            Assert.Equal(0, coll[0].Value);
            Assert.Equal(1, coll[1].Value);
            Assert.Equal(2, coll[2].Value);
            Assert.Equal(0, coll[0].Value);
            Assert.Equal(1, coll[1].Value);
            Assert.Equal(2, coll[2].Value);

            Assert.Equal(3, objectCount);
        }
コード例 #9
0
        public void SetDeletesObjectWorks()
        {
            int objectCount = 0;
            var baseColl    = new ThreadSafeBindableCollection <int>();
            var coll        = new SelectCollection <int, IntHolder>(baseColl,
                                                                    i => new IntHolder(objectCount++));

            baseColl.Add(1);
            baseColl.Add(2);
            baseColl.Add(3);

            Assert.Equal(0, coll[0].Value);
            Assert.Equal(1, coll[1].Value);
            Assert.Equal(2, coll[2].Value);

            baseColl[1] = 4;
            Assert.Equal(3, coll[1].Value);

            baseColl.Add(2);                // adding it back in should create a new object as old one was deleted
            Assert.Equal(4, coll[3].Value); // should not have created objects when deleting

            Assert.Equal(5, objectCount);
        }