Beispiel #1
0
        public void PassThePropertyCorrectly_FirstShouldBeExpectedFirstName(string sortBy, string expectedFirstName)
        {
            var people = new PersonCollection();
            var sorted = people.AsQueryable().OrderBy(sortBy);

            Assert.AreEqual(expectedFirstName, sorted.FirstOrDefault().FirstName);
        }
Beispiel #2
0
        static void Main()
        {
            // Applying using sort property.
            // If not passing string sort it will take out data that is on sort property
            var people = new PersonCollection();

            // Apply sort
            var sorted = people.AsQueryable().OrderBy();

            WriteCollection(sorted);

            // Using implicit
            sorted = new PersonCollection().AsQueryable().OrderBy();
            WriteCollection(sorted);

            // Using string sort
            sorted = new PersonCollection().AsQueryable().OrderBy("FirstName, LastName");
            WriteCollection(sorted);


            // Pass unexists property name it will launch exception
            try
            {
                sorted = new PersonCollection().AsQueryable().OrderBy("FirstName, LastName desc, SomeProperty");
                WriteCollection(sorted);
            }
            catch (ParseException ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.Read();
        }
Beispiel #3
0
        public void UsingDefaultSort_ShouldBeExpectedHash()
        {
            var expected = new Person("Channing", "Tatum", new DateTime(1965, 4, 4));
            var people   = new PersonCollection();
            var sorted   = people.AsQueryable().OrderBy();

            Assert.AreEqual(expected.GetHashCode(), sorted.FirstOrDefault().GetHashCode());
        }
Beispiel #4
0
        public void PassNoExistsPropertyName_ShouldThrowsParseExpection(string sortBy)
        {
            var people = new PersonCollection();

            Assert.Throws <ParseException>(() => people.AsQueryable().OrderBy(sortBy));
        }