Example #1
0
        public void IsEmpty()
        {
            var clause = new OrderByClause();

            Assert.IsTrue(clause.IsEmpty);

            var item = new OrderByItem("field1", SortOrder.Descending);

            clause.Add(item);

            Assert.IsFalse(clause.IsEmpty);
        }
Example #2
0
        public void Add()
        {
            IOrderByClause clause = new OrderByClause("field1 desc, field2");
            var            item   = new OrderByItem("field3", SortOrder.Descending);

            clause.Add(item);

            Assert.AreEqual("field1 desc,field2,field3 desc", clause.ToString());

            // can't add existing field
            Assert.Throws <ArgumentException>(() =>
            {
                clause.Add("field2");
            });

            clause.AddAlways("field1", SortOrder.Ascending);
            Assert.AreEqual("field2,field3 desc,field1", clause.ToString());

            item.Reverse();
            Assert.AreEqual("field2,field3,field1", clause.ToString());
        }
Example #3
0
        public void Create()
        {
            var item   = new OrderByItem("field1", SortOrder.Ascending);
            var clause = new OrderByClause("field1 asc");

            Assert.AreEqual(item, clause);

            clause.Add("field2 desc");
            Assert.AreEqual("field1,field2 desc", clause.ToString());

            clause = new OrderByClause("field1 desc, field2");
            Assert.AreEqual("field1 desc,field2", clause.ToString());
        }