public void TestTranslationDictionaryDecodingAndSorting() { IList <SortClass> data = CreateSimpleSortData(); IDictionary <Expression <Func <SortClass, object> >, string> translationDictionary = new Dictionary <Expression <Func <SortClass, object> >, string> { { s => s.A, "0" }, { s => s.B, "1" }, }; Sorter <SortClass> sorter = new Sorter <SortClass>("n", translationDictionary, "n.0", "n.1!"); List <SortClass> sortedData = data.AsQueryable().OrderBy(sorter).ToList(); Assert.AreSame(data[3], sortedData[0]); Assert.AreSame(data[1], sortedData[1]); Assert.AreSame(data[2], sortedData[2]); Assert.AreSame(data[0], sortedData[3]); Assert.AreSame(data[4], sortedData[4]); translationDictionary = new Dictionary <Expression <Func <SortClass, object> >, string> { { s => s.A, "0" }, }; sorter = Sorter <SortClass> .Decode("n", translationDictionary, "n.0'n.B!"); sortedData = data.AsQueryable().OrderBy(sorter).ToList(); Assert.AreSame(data[3], sortedData[0]); Assert.AreSame(data[1], sortedData[1]); Assert.AreSame(data[2], sortedData[2]); Assert.AreSame(data[0], sortedData[3]); Assert.AreSame(data[4], sortedData[4]); }
public void TestDecodingInvalidString() { IDictionary <Expression <Func <SortClass, object> >, string> dict = new Dictionary <Expression <Func <SortClass, object> >, string> { { s => s.A, "0" }, { s => s.B, "1" }, }; TestHelper.ExpectException <SorterException>(() => Sorter <SortClass> .Decode(null, "A'D")); TestHelper.ExpectException <SorterException>(() => Sorter <SortClass> .Decode(null, "AD")); TestHelper.ExpectException <SorterException>(() => Sorter <SortClass> .Decode(null, "!AD")); TestHelper.ExpectException <SorterException>(() => Sorter <SortClass> .Decode(null, "a.A'B")); TestHelper.ExpectException <SorterException>(() => Sorter <SortClass> .Decode("a", "A!'B")); TestHelper.ExpectException <SorterException>(() => Sorter <SortClass> .Decode("a", "a.A!'B")); TestHelper.ExpectException <SorterException>(() => Sorter <SortClass> .Decode("a", dict, "a.0!'1")); TestHelper.ExpectException <SorterException>(() => Sorter <SortClass> .Decode("a", dict, "a.0!'11")); TestHelper.ExpectException <SorterException>(() => Sorter <SortClass> .Decode(null, dict, "a.0!'1")); }
public void TestPrefixedDecodingAndSorting() { IList <SortClass> data = CreateSimpleSortData(); Sorter <SortClass> sorter = new Sorter <SortClass>("p", "p.A", "p.B!"); List <SortClass> sortedData = data.AsQueryable().OrderBy(sorter).ToList(); Assert.AreSame(data[3], sortedData[0]); Assert.AreSame(data[1], sortedData[1]); Assert.AreSame(data[2], sortedData[2]); Assert.AreSame(data[0], sortedData[3]); Assert.AreSame(data[4], sortedData[4]); sorter = Sorter <SortClass> .Decode("p", "p.A'p.B!"); sortedData = data.AsQueryable().OrderBy(sorter).ToList(); Assert.AreSame(data[3], sortedData[0]); Assert.AreSame(data[1], sortedData[1]); Assert.AreSame(data[2], sortedData[2]); Assert.AreSame(data[0], sortedData[3]); Assert.AreSame(data[4], sortedData[4]); }