示例#1
0
        public void AddOrderBy_Test2()
        {
            var dummy_list = new Article[] {
                new Article() {Title="Z"},
                new Article() {Title="A"},
                new Article() {Title="M"}
            };
            var sortdef = new ChimaLib.Models.SortFieldDefinition<Article, string>(obj => obj.Title);

            var articles = (from a in dummy_list select a).AsQueryable();

            articles = sortdef.AddOrderBy(articles, "Title desc");  //ソートキー"Title"順に並べ替え
            var result = articles.ToArray();

            Assert.AreEqual("Z", result[0].Title);
            Assert.AreEqual("M", result[1].Title);
            Assert.AreEqual("A", result[2].Title);
        }
示例#2
0
 /// <summary>
 /// create dummy data
 /// </summary>
 /// <param name="num">num of data. must be an even number.</param>
 /// <returns></returns>
 private IQueryable<Article> TestData1(int num)
 {
     Article[] data = new Article[num];
     for(var i = 0; i < num; i++) {
         /* mixed index. if num=10 then 0,9,2,7,4,5,6,3,8,1 */
         var idx = (i % 2 == 0) ? i: num - i;
         System.Diagnostics.Debug.WriteLine(idx);
         data[i] = new Article() {
             Title = "Title" + idx.ToString(),
             Category = "Category" + idx.ToString(),
             Published = new DateTime(2015, 10, idx+1),
             Viewcount = idx
         };
     }
     return data.AsQueryable();
 }