Ejemplo n.º 1
0
        public void AscendingKeyThenDescendingKey()
        {
            Record[] source = new Record[]
            {
                new Record{ Name = "Jim", City = "Minneapolis", Country = "USA" },
                new Record{ Name = "Tim", City = "Seattle", Country = "USA" },
                new Record{ Name = "Philip", City = "Orlando", Country = "USA" },
                new Record{ Name = "Chris", City = "London", Country = "UK" },
                new Record{ Name = "Rob", City = "Kent", Country = "UK" }
            };
            Record[] expected = new Record[]
            {
                new Record{ Name = "Chris", City = "London", Country = "UK" },
                new Record{ Name = "Rob", City = "Kent", Country = "UK" },
                new Record{ Name = "Tim", City = "Seattle", Country = "USA" },
                new Record{ Name = "Philip", City = "Orlando", Country = "USA" },
                new Record{ Name = "Jim", City = "Minneapolis", Country = "USA" }
            };

            Assert.Equal(expected, source.OrderBy((e) => e.Country).ThenByDescending((e) => e.City));
        }
Ejemplo n.º 2
0
        public void OrderByAndThenByOnSameField()
        {
            Record[] source = new Record[]
            {
                new Record{ Name = "Jim", City = "Minneapolis", Country = "USA" },
                new Record{ Name = "Prakash", City = "Chennai", Country = "India" },
                new Record{ Name = "Rob", City = "Kent", Country = "UK" }
            };
            Record[] expected = new Record[]
            {
                new Record{ Name = "Prakash", City = "Chennai", Country = "India" },
                new Record{ Name = "Rob", City = "Kent", Country = "UK" },
                new Record{ Name = "Jim", City = "Minneapolis", Country = "USA" }
            };

            Assert.Equal(expected, source.OrderBy((e) => e.Country).ThenBy((e) => e.Country, null));
        }
Ejemplo n.º 3
0
        public void SecondKeyRepeatAcrossDifferentPrimary()
        {
            Record[] source = new Record[]
            {
                new Record{ Name = "Jim", City = "Minneapolis", Country = "USA" },
                new Record{ Name = "Tim", City = "Seattle", Country = "USA" },
                new Record{ Name = "Philip", City = "Orlando", Country = "USA" },
                new Record{ Name = "Chris", City = "Minneapolis", Country = "USA" },
                new Record{ Name = "Rob", City = "Seattle", Country = "USA" }
            };
            Record[] expected = new Record[]
            {
                new Record{ Name = "Chris", City = "Minneapolis", Country = "USA" },
                new Record{ Name = "Jim", City = "Minneapolis", Country = "USA" },
                new Record{ Name = "Philip", City = "Orlando", Country = "USA" },
                new Record{ Name = "Rob", City = "Seattle", Country = "USA" },
                new Record{ Name = "Tim", City = "Seattle", Country = "USA" }
            };

            Assert.Equal(expected, source.OrderBy((e) => e.Name).ThenBy((e) => e.City, null));
        }