Пример #1
0
        public void CompareValuesByProperties_ItemWithoutNullProperties_ReturnedSorted()
        {
            // Arrange
            var firstItem = new ListItem {
                FirstColumn = "A"
            };
            var secondItem = new ListItem {
                FirstColumn = "B"
            };
            var list = new List <ListItem> {
                secondItem, firstItem
            };
            var descriptor     = typeof(ListItem).GetProperty(nameof(ListItem.FirstColumn));
            var sortCollection = new[]
            {
                new ListSortDescription(GetPropertyDescriptor(descriptor), ListSortDirection.Ascending)
            };
            var comparer = ListObjectComparer.FromSort <ListItem>(new ListSortDescriptionCollection(sortCollection));

            // Act
            list.Sort(comparer.CompareValuesByProperties);

            // Assert
            list.Should().BeEquivalentTo(new List <ListItem> {
                firstItem, secondItem
            });
        }
Пример #2
0
        public void CompareValuesByProperties_ItemWithNullProperties_ReturnedNullFirst()
        {
            // Arrange
            var itemWithNull = new ListItem {
                FirstColumn = null
            };
            var itemWithValue = new ListItem {
                FirstColumn = "Something"
            };
            var list = new List <ListItem> {
                itemWithValue, itemWithNull
            };
            var descriptor     = typeof(ListItem).GetProperty(nameof(ListItem.FirstColumn));
            var sortCollection = new[]
            {
                new ListSortDescription(GetPropertyDescriptor(descriptor), ListSortDirection.Ascending)
            };
            var comparer = ListObjectComparer.FromSort <ListItem>(new ListSortDescriptionCollection(sortCollection));

            // Act
            list.Sort(comparer.CompareValuesByProperties);

            // Assert
            list.Should().BeEquivalentTo(new List <ListItem> {
                itemWithNull, itemWithValue
            });
        }