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

            list.Add(new NullableSortTestClass
            {
                Id = 1
            });
            list.Add(new NullableSortTestClass
            {
                Id = null
            });

            list = list.OrderBy(x => x.Id).ToList();

            var sorter = new SimpleSorter
            {
                Direction = SortDirection.Descending.Value,
                Property  = "Id"
            };
            var sortedList   = list.AsQueryable().OrderBy(sorter).ToList();
            var expectedList = list.OrderByDescending(x => x.Id).ToList();

            CollectionAssert.AreEqual(expectedList, sortedList);
        }
Example #2
0
        public void TestOrderByExension_SimpleSorter()
        {
            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 simpleSorter = new SimpleSorter
            {
                Direction = SortDirection.Ascending.Value,
                Property  = "Int1"
            };
            var sortedList   = list.AsQueryable().OrderBy(simpleSorter).ToList();
            var expectedList = list.OrderBy(x => x.Int1).ToList();

            CollectionAssert.AreEqual(expectedList, sortedList);
        }
Example #3
0
        public void TestToLinqSorter_ToString()
        {
            var simpleSorter = new SimpleSorter
            {
                Direction = SortDirection.Descending.Value,
                Property  = "Id"
            };

            Assert.IsNotNull(simpleSorter.ToString());
        }
Example #4
0
        public void TestToLinqSorter_Descending()
        {
            var simpleSorter = new SimpleSorter
            {
                Direction = SortDirection.Descending.Value,
                Property  = "Id"
            };

            var linqSorter = simpleSorter.ToLinqSorter <SimpleSorterTestClass>();

            Assert.AreEqual(SortDirection.Descending, linqSorter.Direction);
            Assert.AreEqual(simpleSorter.Property, linqSorter.PropertyInfo.Name);
        }
Example #5
0
        public void TestOrderByExension_MultipleSimpleSorters()
        {
            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 simpleSorter1 = new SimpleSorter
            {
                Direction = SortDirection.Descending.Value,
                Property  = "Int1"
            };
            var simpleSorter2 = new SimpleSorter
            {
                Direction = SortDirection.Descending.Value,
                Property  = "Int2"
            };

            var sortedList = list.AsQueryable().OrderBy(new List <SimpleSorter> {
                simpleSorter1, simpleSorter2
            }).ToList();
            var expectedList = list.OrderByDescending(x => x.Int1).ThenByDescending(x => x.Int2).ToList();

            CollectionAssert.AreEqual(expectedList, sortedList);
        }
        public void PartitionTest()
        {
            var data = new int[] { 15, 9, 8, 1, 4, 11, 7, 12, 13, 6, 5, 3, 16, 2, 10, 14 };
            var p    = new SimpleSorter().Partition(data, 0, data.Length - 1, 9);

            Assert.AreEqual(16, data.Length);
            Assert.AreEqual(1, data[0]);
            Assert.AreEqual(4, data[1]);
            Assert.AreEqual(5, data[2]);
            Assert.AreEqual(3, data[3]);
            Assert.AreEqual(2, data[4]);
            Assert.AreEqual(6, data[5]);
            Assert.AreEqual(7, data[6]);
            Assert.AreEqual(12, data[7]);
            Assert.AreEqual(13, data[8]);
            Assert.AreEqual(14, data[9]);
            Assert.AreEqual(8, data[10]);
            Assert.AreEqual(15, data[11]);
            Assert.AreEqual(16, data[12]);
            Assert.AreEqual(9, data[13]);
            Assert.AreEqual(10, data[14]);
            Assert.AreEqual(11, data[15]);
        }
        public void TestConstructor()
        {
            SimpleSorter arraySorter = new SimpleSorter();

            Assert.IsNotNull(arraySorter);
        }