コード例 #1
0
        public void OnPropertyChangedTest()
        {
            List<EditableTestClass> efbList = new List<EditableTestClass>();
            ObservableCollection<TestClass> fbCollection = new ObservableCollection<TestClass>();

            PagedCollectionView pcv1 = new PagedCollectionView(efbList);
            PagedCollectionView pcv2 = new PagedCollectionView(fbCollection);
            pcv1.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(this.PagedCollectionViewPropertyChanged);
            pcv2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(this.PagedCollectionViewPropertyChanged);

            this._expectedPropertyNames.Clear();
            this._expectedPropertyNames.Add("Count");
            this._expectedPropertyNames.Add("IsEmpty");
            this._expectedPropertyNames.Add("IsCurrentAfterLast");
            this.AssertExpectedEvent(delegate { fbCollection.Add(new TestClass()); });
            this.CheckExpectedPropertyNamesFound();

            this._expectedPropertyNames.Clear();
            this._expectedPropertyNames.Add("IsCurrentBeforeFirst");
            this._expectedPropertyNames.Add("CurrentPosition");
            this._expectedPropertyNames.Add("CurrentItem");
            this.AssertExpectedEvent(delegate { pcv2.MoveCurrentToFirst(); });
            this.CheckExpectedPropertyNamesFound();

            this._expectedPropertyNames.Clear();
            this._expectedPropertyNames.Add("SortDescriptions");
            this.AssertExpectedEvent(delegate { pcv1.SortDescriptions.Add(new System.ComponentModel.SortDescription("IntProperty", System.ComponentModel.ListSortDirection.Ascending)); });
            this.CheckExpectedPropertyNamesFound();

            this._expectedPropertyNames.Clear();
            this._expectedPropertyNames.Add("Culture");
            this.AssertExpectedEvent(delegate { pcv1.Culture = CultureInfo.InvariantCulture; });
            this.CheckExpectedPropertyNamesFound();

            this._expectedPropertyNames.Clear();
            this._expectedPropertyNames.Add("Filter");
            this.AssertExpectedEvent(delegate { pcv2.Filter = new Predicate<object>(this.FilterNegativeNumbers); });
            this.CheckExpectedPropertyNamesFound();

            // Attempt to move to Page 0 should fail while PageSize is still 0.
            Assert.AreEqual(0, pcv1.PageSize);
            Assert.IsFalse(pcv1.MoveToPage(0));

            this._expectedPropertyNames.Clear();
            this._expectedPropertyNames.Add("PageSize");
            this.AssertExpectedEvent(delegate { pcv1.PageSize = 10; });
            this.CheckExpectedPropertyNamesFound();

            pcv1.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(this.PagedCollectionViewPropertyChanged);
            pcv2.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(this.PagedCollectionViewPropertyChanged);
        }
コード例 #2
0
        public void MoveToPageZeroWithNoItemsTest()
        {
            List<int> intList = new List<int>();

            PagedCollectionView pcv = new PagedCollectionView(intList);

            pcv.PageSize = 5;
            pcv.MoveToPage(0);

            Assert.AreEqual(0, pcv.Count);
            Assert.AreEqual(0, pcv.PageIndex);
        }
コード例 #3
0
        public void CountTestWithNoItems()
        {
            List<int> intList = new List<int>();
            PagedCollectionView pcv = new PagedCollectionView(intList);
            Assert.AreEqual(0, pcv.Count);

            // update the PageSize and verify that we still have a Count of 0.
            pcv.PageSize = 10;
            Assert.AreEqual(0, pcv.Count);

            // update the PageSize during a DeferRefresh and verify that we still have a Count of 0.
            pcv.PageSize = 0;
            using (pcv.DeferRefresh())
            {
                pcv.PageSize = 10;
                pcv.MoveToPage(1);
            }
            Assert.AreEqual(0, pcv.Count);

            // now try those same tests above with grouping
            pcv.GroupDescriptions.Add(new PropertyGroupDescription(""));
            pcv.PageSize = 0;
            Assert.AreEqual(0, pcv.Count);

            // update the PageSize and verify that we still have a Count of 0.
            pcv.PageSize = 10;
            Assert.AreEqual(0, pcv.Count);

            // update the PageSize during a DeferRefresh and verify that we still have a Count of 0.
            pcv.PageSize = 0;
            using(pcv.DeferRefresh())
            {
                pcv.PageSize = 5;
            }
            Assert.AreEqual(0, pcv.Count);
        }
コード例 #4
0
        public void GroupingInListBoxTest()
        {
            ObservableCollection<TestClass> collection = new ObservableCollection<TestClass>()
            {
                new TestClass { IntProperty = 1, StringProperty = "A" },
                new TestClass { IntProperty = 2, StringProperty = "B" }, 
                new TestClass { IntProperty = 3, StringProperty = "A" },
                new TestClass { IntProperty = 4, StringProperty = "B" } 
            };

            PagedCollectionView cv = new PagedCollectionView(collection);

            ListBox lb = new ListBox();
            lb.ItemsSource = cv;

            this.CreateAsyncTask(
                lb,
                delegate
                {
                    Assert.AreEqual(4, lb.Items.Count);

                    cv.GroupDescriptions.Add(new PropertyGroupDescription("StringProperty"));

                    Assert.AreEqual(4, lb.Items.Count);
                    Assert.AreEqual("A", (lb.Items[0] as TestClass).StringProperty);
                    Assert.AreEqual("A", (lb.Items[1] as TestClass).StringProperty);
                    Assert.AreEqual("B", (lb.Items[2] as TestClass).StringProperty);
                    Assert.AreEqual("B", (lb.Items[3] as TestClass).StringProperty);

                    cv.PageSize = 3;
                    cv.MoveToPage(1);

                    Assert.AreEqual(1, lb.Items.Count);
                    Assert.AreEqual("B", (lb.Items[0] as TestClass).StringProperty);

                    TestClass newItem = cv.AddNew() as TestClass;
                    newItem.StringProperty = "A";
                    newItem.IntProperty = 5;

                    // ---------------------
                    // |Page | 0  | 1  | 2  |
                    // ---------------------
                    // | 0   | A  | A  | B  |
                    // | 1   | B  |-A- |    | <---- Current Page
                    Assert.AreEqual("B", (lb.Items[0] as TestClass).StringProperty);
                    Assert.AreEqual("A", (lb.Items[1] as TestClass).StringProperty);
                    cv.CommitNew();

                    // ---------------------
                    // |Page | 0  | 1  | 2  |
                    // ---------------------
                    // | 0   | A  | A  |-A- |
                    // | 1   | B  | B  |    | <---- Current Page
                    Assert.AreEqual("B", (lb.Items[0] as TestClass).StringProperty);
                    Assert.AreEqual("B", (lb.Items[1] as TestClass).StringProperty);

                    cv.MoveToFirstPage();
                    Assert.AreEqual("A", (lb.Items[0] as TestClass).StringProperty);
                    Assert.AreEqual("A", (lb.Items[1] as TestClass).StringProperty);
                    Assert.AreEqual("A", (lb.Items[2] as TestClass).StringProperty);
                });

            EnqueueTestComplete();
        }
コード例 #5
0
        public void CannotMoveToPageTest()
        {
            List<TestClass> intList = new List<TestClass>();
            PagedCollectionView pcv = new PagedCollectionView(intList);
            Assert.AreEqual(0, pcv.PageSize);

            // if the PageSize is 0, you cannot move to page 0
            Assert.IsFalse(pcv.MoveToPage(0));

            // setting the PageSize to a positive number causes a 
            // move to page 0.
            pcv.PageSize = 1;
            Assert.AreEqual(0, pcv.PageIndex);
        }