コード例 #1
0
 public void TestSort()
 {
     CollectionAssert.AreEqual(new string[] { }, StandardFilters.Sort(new string[] { }));
     CollectionAssert.AreEqual(new[] { 1, 2, 3, 4 }, StandardFilters.Sort(new[] { 4, 3, 2, 1 }));
     CollectionAssert.AreEqual(new[] { new { a = 1 }, new { a = 2 }, new { a = 3 }, new { a = 4 } },
                               StandardFilters.Sort(new[] { new { a = 4 }, new { a = 3 }, new { a = 1 }, new { a = 2 } }, "a"));
 }
コード例 #2
0
        public void TestSort_OnHashList_WithProperty_DoesNotFlattenList()
        {
            var  list  = new System.Collections.Generic.List <Hash>();
            Hash hash1 = CreateHash("1", "Text1");
            Hash hash2 = CreateHash("2", "Text2");
            Hash hash3 = CreateHash("3", "Text3");

            list.Add(hash3);
            list.Add(hash1);
            list.Add(hash2);

            Hash[] result = StandardFilters.Sort(list, "sortby").Cast <Hash>().ToArray();
            Assert.AreEqual(3, result.Count());
            Assert.AreEqual(hash1["content"], result[0]["content"]);
            Assert.AreEqual(hash2["content"], result[1]["content"]);
            Assert.AreEqual(hash3["content"], result[2]["content"]);
        }
コード例 #3
0
        public void TestSort_OnDictionaryWithPropertyOnlyInSomeElement_ReturnsSortedDictionary()
        {
            var list  = new System.Collections.Generic.List <Hash>();
            var hash1 = CreateHash("1", "Text1");
            var hash2 = CreateHash("2", "Text2");
            var hashWithNoSortByProperty = new Hash();

            hashWithNoSortByProperty.Add("content", "Text 3");
            list.Add(hash2);
            list.Add(hashWithNoSortByProperty);
            list.Add(hash1);

            var result = StandardFilters.Sort(list, "sortby").Cast <Hash>().ToArray();

            Assert.AreEqual(3, result.Count());
            Assert.AreEqual(hashWithNoSortByProperty["content"], result[0]["content"]);
            Assert.AreEqual(hash1["content"], result[1]["content"]);
            Assert.AreEqual(hash2["content"], result[2]["content"]);
        }