using System; using System.Text; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace SqlLinq.UnitTests { [TestClass] public class OrderByTests { [TestMethod] public void OrderByValue() { IEnumerable<int> source = TestData.GetInts(); IEnumerable<int> result = source.Query<int>("SELECT * FROM this ORDER BY value()"); Assert.IsTrue(result.SequenceEqual(source.OrderBy(i => i))); } [TestMethod] public void OrderByProperty() { IEnumerable<Person> source = TestData.GetPeople(); IEnumerable<Person> result = source.Query<Person>("SELECT * FROM this ORDER BY age"); Assert.IsTrue(result.SequenceEqual(source.OrderBy(p => p.Age))); } [TestMethod] public void OrderByTwoProperties() { IEnumerable<Person> source = TestData.GetPeople(); IEnumerable<Person> result = source.Query<Person>("SELECT * FROM this ORDER BY age, name"); IEnumerable<Person> answer = source.OrderBy(p => p.Age).ThenBy(p => p.Name); Assert.IsTrue(result.SequenceEqual(answer)); } [TestMethod] public void OrderByPropertySelectOtherProperty() { IEnumerable<Person> source = TestData.GetPeople(); IEnumerable<string> result = source.Query<Person, string>("SELECT Name FROM this ORDER BY age"); Assert.IsTrue(result.SequenceEqual(source.OrderBy(p => p.Age).Select(p => p.Name))); } [TestMethod] public void OrderByPropertyDescending() { IEnumerable<Person> source = TestData.GetPeople(); IEnumerable<Person> result = source.Query<Person>("SELECT * FROM this ORDER BY age DESC"); Assert.IsTrue(result.SequenceEqual(source.OrderByDescending(p => p.Age))); } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
10 PRINT "Don is cool" 20 GOTO 10