Exemplo n.º 1
0
        public void ComplexQuery()
        {
            DateTime start  = DateTime.Now.AddDays(-1);
            DateTime finish = DateTime.Now.AddDays(1);

            string expected = $"((((Name IS NULL AND Age > 30) OR (Name LIKE '%e%' AND Age < 30)) AND BankBalance BETWEEN 0 AND 500000) OR (TimeCreated = '{start.ToString(DateFormat)}' OR TimeCreated = '{finish.ToString(DateFormat)}'))";

            SqlWhere query = SqlWhere.WhereEqual(left: "Name", right: default(string))
                             .And(SqlWhere.WhereGreaterThan("Age", 30))
                             .Or(SqlWhere.WhereLike("Name", "%e%").And(SqlWhere.WhereLessThan("Age", 30)))
                             .And(SqlWhere.WhereBetween("BankBalance", 0, 500000))
                             .Or(SqlWhere.WhereEqual("TimeCreated", start)
                                 .Or(SqlWhere.WhereEqual("TimeCreated", finish)));

            Assert.Equal(expected, query.Raw);
        }