Example #1
0
        public void TestOrderByExension_OrderByAscending_SimpleSort()
        {
            var list = new List <SimpleSortTestClass>();

            list.Add(new SimpleSortTestClass
            {
                Int1 = 1,
            });
            list.Add(new SimpleSortTestClass
            {
                Int1 = 1,
            });
            list.Add(new SimpleSortTestClass
            {
                Int1 = 2,
            });
            list.Add(new SimpleSortTestClass
            {
                Int1 = 2,
            });

            list = list.OrderByDescending(x => x.Int1).ToList();

            var sorter       = new LinqSorter <SimpleSortTestClass>("Int1", SortDirection.Ascending);
            var sortedList   = list.AsQueryable().OrderBy(sorter).ToList();
            var expectedList = list.OrderBy(x => x.Int1).ToList();

            CollectionAssert.AreEqual(expectedList, sortedList);
        }
Example #2
0
        public void TestOrderByExension_OrderByDescending_MultiSort()
        {
            var list = new List <MultiSortTestClass>();

            list.Add(new MultiSortTestClass
            {
                Int1 = 1,
                Int2 = 1,
            });
            list.Add(new MultiSortTestClass
            {
                Int1 = 1,
                Int2 = 2,
            });
            list.Add(new MultiSortTestClass
            {
                Int1 = 2,
                Int2 = 1,
            });
            list.Add(new MultiSortTestClass
            {
                Int1 = 2,
                Int2 = 2
            });

            list = list.OrderBy(x => x.Int1).ThenBy(x => x.Int2).ToList();

            var sorter1    = new LinqSorter <MultiSortTestClass>("Int1", SortDirection.Descending);
            var sorter2    = new LinqSorter <MultiSortTestClass>("Int2", SortDirection.Descending);
            var sortedList = list.AsQueryable().OrderBy(new List <LinqSorter <MultiSortTestClass> > {
                sorter1, sorter2
            }).ToList();
            var expectedList = list.OrderByDescending(x => x.Int1).ThenByDescending(x => x.Int2).ToList();

            CollectionAssert.AreEqual(expectedList, sortedList);
        }