Пример #1
0
        public void IsSorted_TrueWhenSorted()
        {
            IBindingList       bindingList        = SortableBindingListFactory.Create();
            PropertyDescriptor propertyDescriptor = PropertyDescriptorHelper.Get(bindingList[0], "Id");

            bindingList.ApplySort(propertyDescriptor, ListSortDirection.Ascending);

            Assert.IsTrue(bindingList.IsSorted);
        }
Пример #2
0
        public void RemoveSort_SetSortPropertyToNull()
        {
            IBindingList       bindingList        = SortableBindingListFactory.Create();
            PropertyDescriptor propertyDescriptor = PropertyDescriptorHelper.Get(bindingList[0], "Id");

            bindingList.ApplySort(propertyDescriptor, ListSortDirection.Ascending);
            bindingList.RemoveSort();

            Assert.IsNull(bindingList.SortProperty);
        }
Пример #3
0
        public void RemoveSort_ReturnFalseForIsSorted()
        {
            IBindingList       bindingList        = SortableBindingListFactory.Create();
            PropertyDescriptor propertyDescriptor = PropertyDescriptorHelper.Get(bindingList[0], "Id");

            bindingList.ApplySort(propertyDescriptor, ListSortDirection.Ascending);
            bindingList.RemoveSort();

            Assert.IsFalse(bindingList.IsSorted);
        }
Пример #4
0
        public void SetSortDirectionCore()
        {
            IBindingList       bindingList        = SortableBindingListFactory.Create();
            PropertyDescriptor propertyDescriptor = PropertyDescriptorHelper.Get(bindingList[0], "Id");

            bindingList.ApplySort(propertyDescriptor, ListSortDirection.Descending);
            ListSortDirection actual   = bindingList.SortDirection;
            ListSortDirection expected = ListSortDirection.Descending;

            Assert.AreEqual(expected, actual);
        }
Пример #5
0
        public void Find_ItemNotFound_ReturnMinusOne()
        {
            IBindingList       bindingList        = SortableBindingListFactory.Create();
            PropertyDescriptor propertyDescriptor = PropertyDescriptorHelper.Get(bindingList[0], "Address");

            bindingList.ApplySort(propertyDescriptor, ListSortDirection.Descending);

            object key    = new GenericComparableAddress("4");
            int    actual = bindingList.Find(propertyDescriptor, key);

            int expected = -1;

            Assert.AreEqual(expected, actual);
        }
Пример #6
0
        public void ApplySort_GenericComparable_Asc()
        {
            IBindingList bindingList = SortableBindingListFactory.Create();

            IList sortedByAddressAscending = new[]
            {
                bindingList[0],
                bindingList[1],
                bindingList[2]
            };

            PropertyDescriptor propertyDescriptor = PropertyDescriptorHelper.Get(bindingList[0], "Address");

            bindingList.ApplySort(propertyDescriptor, ListSortDirection.Ascending);
            AssertSortableBindingList.HaveSameElements(sortedByAddressAscending, bindingList);
        }
Пример #7
0
        public void SortOnPropertiesOfSameType()
        {
            IBindingList bindingList = SortableBindingListFactory.Create();

            IList sortedByFirstNameAscending = new[]
            {
                bindingList[0],
                bindingList[1],
                bindingList[2]
            };

            IList sortedByFirstNameDescending = new[]
            {
                bindingList[2],
                bindingList[1],
                bindingList[0]
            };

            IList sortedByLastNameAscending = new[]
            {
                bindingList[1],
                bindingList[2],
                bindingList[0]
            };

            IList sortedByLastNameDescending = new[]
            {
                bindingList[0],
                bindingList[2],
                bindingList[1]
            };

            PropertyDescriptor firstNameProperty = PropertyDescriptorHelper.Get(bindingList[0], "FirstName");
            PropertyDescriptor lastNameProperty  = PropertyDescriptorHelper.Get(bindingList[0], "LastName");

            bindingList.ApplySort(lastNameProperty, ListSortDirection.Descending);
            AssertSortableBindingList.HaveSameElements(sortedByLastNameDescending, bindingList);

            bindingList.ApplySort(firstNameProperty, ListSortDirection.Descending);
            AssertSortableBindingList.HaveSameElements(sortedByFirstNameDescending, bindingList);

            bindingList.ApplySort(firstNameProperty, ListSortDirection.Ascending);
            AssertSortableBindingList.HaveSameElements(sortedByFirstNameAscending, bindingList);

            bindingList.ApplySort(lastNameProperty, ListSortDirection.Ascending);
            AssertSortableBindingList.HaveSameElements(sortedByLastNameAscending, bindingList);
        }
Пример #8
0
        public void ReusePropertyComparerIfSortIsAppliedForSecondTime()
        {
            IBindingList bindingList = SortableBindingListFactory.Create();

            IList sortedByAddressDescneding = new[]
            {
                bindingList[2],
                bindingList[1],
                bindingList[0]
            };

            PropertyDescriptor propertyDescriptor = PropertyDescriptorHelper.Get(bindingList[0], "Address");

            bindingList.ApplySort(propertyDescriptor, ListSortDirection.Descending);
            bindingList.ApplySort(propertyDescriptor, ListSortDirection.Descending);
            AssertSortableBindingList.HaveSameElements(sortedByAddressDescneding, bindingList);
        }