示例#1
0
        public void orderBy_lastName_then_by_firstName_than_by_Age()
        {
            var employees = new[]
            {
                new Employee {
                    FirstName = "Joey", LastName = "Wang", Age = 50
                },
                new Employee {
                    FirstName = "Tom", LastName = "Li", Age = 31
                },
                new Employee {
                    FirstName = "Joseph", LastName = "Chen", Age = 32
                },
                new Employee {
                    FirstName = "Joey", LastName = "Chen", Age = 33
                },
                new Employee {
                    FirstName = "Joey", LastName = "Wang", Age = 20
                },
            };

            //JoeyOrderByKeepComparer(employees,)
            var firstComparer =
                new CombineKeyComparer <string>(firstKeySelector => firstKeySelector.LastName, Comparer <string> .Default);
            var secondComparer =
                new CombineKeyComparer <string>(secondKeySelector => secondKeySelector.FirstName, Comparer <string> .Default);

            var firstCombo = new ComboCompare(firstComparer, secondComparer);

            var thirdComparer =
                new CombineKeyComparer <int>(thirdSelector => thirdSelector.Age, Comparer <int> .Default);

            var finalCombo = new ComboCompare(firstCombo, thirdComparer);

            var actual = JoeyOrderBy(employees, finalCombo);

            var expected = new[]
            {
                new Employee {
                    FirstName = "Joey", LastName = "Chen", Age = 33
                },
                new Employee {
                    FirstName = "Joseph", LastName = "Chen", Age = 32
                },
                new Employee {
                    FirstName = "Tom", LastName = "Li", Age = 31
                },
                new Employee {
                    FirstName = "Joey", LastName = "Wang", Age = 20
                },
                new Employee {
                    FirstName = "Joey", LastName = "Wang", Age = 50
                },
            };

            expected.ToExpectedObject().ShouldMatch(actual);
        }
示例#2
0
        public void lastName_firstname_Age()
        {
            var employees = new[]
            {
                new Employee {
                    FirstName = "Joey", LastName = "Wang", Age = 50
                },
                new Employee {
                    FirstName = "Tom", LastName = "Li", Age = 31
                },
                new Employee {
                    FirstName = "Joseph", LastName = "Chen", Age = 32
                },
                new Employee {
                    FirstName = "Joey", LastName = "Chen", Age = 33
                },
                new Employee {
                    FirstName = "Joey", LastName = "Wang", Age = 20
                },
            };

            var firstComparer  = new CombineKeyComparer <string>(element => element.LastName, Comparer <string> .Default);
            var secondComparer = new CombineKeyComparer <string>(element => element.FirstName, Comparer <string> .Default);

            var firstCombo = new ComboComparer(firstComparer, secondComparer);

            var thirdComparer = new CombineKeyComparer <int>(element => element.Age, Comparer <int> .Default);

            var finalCombo = new ComboComparer(firstCombo, thirdComparer);

            var actual = JoeyOrderBy(employees, finalCombo);

            var expected = new[]
            {
                new Employee {
                    FirstName = "Joey", LastName = "Chen", Age = 33
                },
                new Employee {
                    FirstName = "Joseph", LastName = "Chen", Age = 32
                },
                new Employee {
                    FirstName = "Tom", LastName = "Li", Age = 31
                },
                new Employee {
                    FirstName = "Joey", LastName = "Wang", Age = 20
                },
                new Employee {
                    FirstName = "Joey", LastName = "Wang", Age = 50
                },
            };

            expected.ToExpectedObject().ShouldMatch(actual);
        }
示例#3
0
        public void orderBy_lastName_then_by_firstName()
        {
            var employees = new[]
            {
                new Employee {
                    FirstName = "Joey", LastName = "Wang"
                },
                new Employee {
                    FirstName = "Tom", LastName = "Li"
                },
                new Employee {
                    FirstName = "Joseph", LastName = "Chen"
                },
                new Employee {
                    FirstName = "Joey", LastName = "Chen"
                },
            };

            var firstComparer =
                new CombineKeyComparer <string>(firstKeySelector => firstKeySelector.LastName, Comparer <string> .Default);
            var secondComparer =
                new CombineKeyComparer <string>(secondKeySelector => secondKeySelector.FirstName, Comparer <string> .Default);

            var actual = JoeyOrderBy(employees
                                     , new ComboCompare(firstComparer, secondComparer));


            var expected = new[]
            {
                new Employee {
                    FirstName = "Joey", LastName = "Chen"
                },
                new Employee {
                    FirstName = "Joseph", LastName = "Chen"
                },
                new Employee {
                    FirstName = "Tom", LastName = "Li"
                },
                new Employee {
                    FirstName = "Joey", LastName = "Wang"
                },
            };

            expected.ToExpectedObject().ShouldMatch(actual);
        }
示例#4
0
        public void orderBy_lastName_and_firstName()
        {
            var employees = new[]
            {
                new Employee {
                    FirstName = "Joey", LastName = "Wang"
                },
                new Employee {
                    FirstName = "Tom", LastName = "Li"
                },
                new Employee {
                    FirstName = "Joseph", LastName = "Chen"
                },
                new Employee {
                    FirstName = "Joey", LastName = "Chen"
                },
            };

            var firstComparer  = new CombineKeyComparer <string>(employee => employee.LastName, Comparer <string> .Default);
            var secondComparer = new CombineKeyComparer <string>(employee => employee.FirstName, Comparer <string> .Default);

            var actual = JoeyOrderByLastNameAndFirstName(
                employees,
                new ComboComparer(firstComparer, secondComparer));

            var expected = new[]
            {
                new Employee {
                    FirstName = "Joey", LastName = "Chen"
                },
                new Employee {
                    FirstName = "Joseph", LastName = "Chen"
                },
                new Employee {
                    FirstName = "Tom", LastName = "Li"
                },
                new Employee {
                    FirstName = "Joey", LastName = "Wang"
                },
            };

            expected.ToExpectedObject().ShouldMatch(actual);
        }
示例#5
0
 public MyCompareBuilder <TType> AddComparer <TKey>(CombineKeyComparer <TType, TKey> comparer)
 {
     _untilNowComparer = new ComboComparer <TType>(_untilNowComparer, comparer);
     return(this);
 }