Esempio n. 1
0
        public void reverse_employees()
        {
            var employees = new List <Employee>
            {
                new Employee {
                    FirstName = "Joey", LastName = "Chen"
                },
                new Employee {
                    FirstName = "Tom", LastName = "Li"
                },
                new Employee {
                    FirstName = "David", LastName = "Wang"
                }
            };

            var actual = MyOwnLinq.JoeyReverse(employees);

            var expected = new List <Employee>
            {
                new Employee {
                    FirstName = "David", LastName = "Wang"
                },
                new Employee {
                    FirstName = "Tom", LastName = "Li"
                },
                new Employee {
                    FirstName = "Joey", LastName = "Chen"
                }
            };

            expected.ToExpectedObject().ShouldMatch(actual);
        }
Esempio n. 2
0
        public void get_full_name_length()
        {
            var employees = new List <Employee>
            {
                new Employee {
                    FirstName = "Joey", LastName = "Chen"
                },
                new Employee {
                    FirstName = "Tom", LastName = "Li"
                },
                new Employee {
                    FirstName = "David", LastName = "Chen"
                }
            };
            var expected = new[]
            {
                8, 5, 9
                //"JoeyChen",
                //"TomLi",
                //"DavidChen",
            };

            var actual = MyOwnLinq.JoeySelect(employees, e => $"{e.FirstName}{e.LastName}".Length);

            expected.ToExpectedObject().ShouldMatch(actual);
        }
Esempio n. 3
0
        public void get_full_name()
        {
            var employees = new List <Employee>
            {
                new Employee {
                    FirstName = "Joey", LastName = "Chen"
                },
                new Employee {
                    FirstName = "Tom", LastName = "Li"
                },
                new Employee {
                    FirstName = "David", LastName = "Chen"
                }
            };
            var expected = new[]
            {
                "Joey-Chen",
                "Tom-Li",
                "David-Chen",
            };

            var actual = MyOwnLinq.JoeySelect(employees, e => $"{e.FirstName}-{e.LastName}");

            expected.ToExpectedObject().ShouldMatch(actual);
        }
Esempio n. 4
0
        public void orderBy_lastName_and_firstName_and_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 firstCombineComparer  = new CombineComparer <string>(element => element.LastName, Comparer <string> .Default);
            var secondCombineComparer = new CombineComparer <string>(element => element.FirstName, Comparer <string> .Default);
            var thirdCombineComparer  = new CombineComparer <int>(element => element.Age, Comparer <int> .Default);
            var firstCombo            = new ComboComparer(firstCombineComparer, secondCombineComparer);
            var finalCombo            = new ComboComparer(firstCombo, thirdCombineComparer);
            var actual = MyOwnLinq.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);
        }
Esempio n. 5
0
        public void replace_http_to_https_and_append_joey()
        {
            var urls = GetUrls();

            var actual   = MyOwnLinq.JoeySelect(urls, url => url.Replace("http://", "https://") + "/joey");
            var expected = new List <string>
            {
                "https://tw.yahoo.com/joey",
                "https://facebook.com/joey",
                "https://twitter.com/joey",
                "https://github.com/joey",
            };

            expected.ToExpectedObject().ShouldEqual(actual.ToList());
        }
Esempio n. 6
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 firstCombineComparer  = new CombineComparer <string>(element => element.LastName, Comparer <string> .Default);
            var secondCombineComparer = new CombineComparer <string>(element => element.FirstName, Comparer <string> .Default);

            var actual = MyOwnLinq.JoeyOrderBy(employees, new ComboComparer(firstCombineComparer, secondCombineComparer));

            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);
        }