Ejemplo n.º 1
0
        public void Apply_SortByName_SortedHighestToLowest()
        {
            // arrange
            var sort = new DynamicSort <FakeSortClass>(t => t.Name);

            sort.AddKey("age", "age desc", t => t.Age);
            var coll = GetSampleList();

            // act
            var result     = sort.Apply("age", coll);
            var enumerated = result.ToList();

            // assert
            FakeSortClass current = null;

            foreach (var e in enumerated)
            {
                if (current == null)
                {
                    current = e;
                    continue;
                }

                Assert.True(e.Age > current.Age);

                current = e;
            }
        }
Ejemplo n.º 2
0
        public void Apply_NoMapper_SortsByDefault()
        {
            // arrange
            var sort = new DynamicSort <FakeSortClass>(t => t.Name);
            var coll = GetSampleList();

            // act
            var result = sort.Apply("age", coll);

            // assert
            Assert.Equal("Jeremy", result.First().Name);
        }
Ejemplo n.º 3
0
        public void Apply_EmptyKey_SortsByDefault()
        {
            // arrange
            var sort = new DynamicSort <FakeSortClass>(t => t.Name);

            sort.AddKey("age", "age desc", t => t.Age);
            var coll = GetSampleList().ToList();

            // act
            var result = sort.Apply(string.Empty, coll);

            // assert
            Assert.Equal("Jeremy", result.First().Name);
        }
Ejemplo n.º 4
0
        public void Apply_WithThenBy_ExpectedOrder()
        {
            // arrange
            var sort = new DynamicSort <FakeSortClass>(t => t.Name);

            sort.AddKey("age", "age desc", t => t.Name, t => t.Age);
            var coll = GetSampleList();

            // act
            var result = sort.Apply("age", coll);

            // assert (verify that the grouping is ordered, basically)
            var oldestJulieAge = result.Where(p => p.Name.Equals("Julie")).Max(p => p.Age);
            var julies         = result.Where(p => p.Name.Equals("Julie"));

            Assert.Equal(oldestJulieAge, julies.Last().Age);
        }