Example #1
0
 public void Reverse()
 {
     var item = new OrderByItem("field1", SortOrder.Ascending);
     item.Reverse();
     Assert.AreEqual("field1 desc", item.ToString());
     Assert.AreEqual(SortOrder.Descending, item.Order);
 }
Example #2
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 #3
0
        public void Create()
        {
            var item = new OrderByItem("field1", SortOrder.Ascending);
            Assert.AreEqual("field1", item.GetSql());
            Assert.AreEqual("field1", item.ToString());

            item.Order = SortOrder.Descending;
            Assert.AreEqual("field1 desc",item.ToString());

            Assert.IsFalse(item.IsEmpty);
        }
Example #4
0
        public void Clone()
        {
            var item = new OrderByItem("field1", SortOrder.Descending);
            var clone = item.Clone();

            Assert.IsTrue(item.Equals(clone));
            clone.Reverse();
            Assert.IsFalse(item.Equals(clone));
            clone.Reverse();
            Assert.IsTrue(item.Equals(clone));
        }
Example #5
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());
        }
Example #6
0
        public void IsEmpty()
        {
            var item = new OrderByItem();
            Assert.IsTrue(item.IsEmpty);

            item.Field = "test";
            item.Order = SortOrder.Ascending;
            Assert.IsFalse(item.IsEmpty);
            Assert.AreEqual("test", item.GetSql());

            item.Order = SortOrder.Descending;
            Assert.AreEqual("test desc", item.GetSql());
        }
Example #7
0
        protected IOrderByClause Add(string field, SortOrder order, AddWhen when)
        {
            if (String.IsNullOrEmpty(field))
            {
                throw new ArgumentOutOfRangeException("The field name cannot be missing to add a sort");
            }
            string sortOrder      = order == SortOrder.Ascending ? "" : " DESC";
            int    index          = InnerList.Count - 1;
            string fieldNameClean = unAliased(field.Trim().ToLower());
            var    crit           = new OrderByItem(fieldNameClean, order);

            return(Add(crit, when));
        }
Example #8
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 #9
0
 public OrderByItem Clone()
 {
     OrderByItem clone = new OrderByItem(Field,Order);
     return clone;
 }
Example #10
0
        protected IOrderByClause Add(string field, SortOrder order,AddWhen when)
        {
            if (String.IsNullOrEmpty(field))
            {
                throw new ArgumentOutOfRangeException("The field name cannot be missing to add a sort");
            }
            string sortOrder = order == SortOrder.Ascending ? "" : " DESC";
            int index = InnerList.Count - 1;
            string fieldNameClean = unAliased(field.Trim().ToLower());
            var crit = new OrderByItem(fieldNameClean, order);

            return Add(crit,when);
        }
Example #11
0
        public OrderByItem Clone()
        {
            OrderByItem clone = new OrderByItem(Field, Order);

            return(clone);
        }