Ejemplo n.º 1
0
        public void AppendCriteria_Complex()
        {
            //---------------Set up test pack-------------------
            const string startSql    = "select [FAKE WHERE CLAUSE] from bob WHERE that = 'FAKE WHERE CLAUSE'";
            var          builder     = new SqlStatementBuilder(_connection, startSql);
            const string appendSql   = "this = that";
            const string expectedSql = startSql + " AND " + appendSql;

            //---------------Execute Test ----------------------
            builder.AppendCriteria(appendSql);
            var actual = builder.GetStatement().Statement.ToString();

            //---------------Test Result -----------------------
            Assert.AreEqual(expectedSql, actual);
        }
Ejemplo n.º 2
0
        public void AddJoin_Complex()
        {
            //---------------Set up test pack-------------------
            const string startSql    = "select [FALSE FROM CLAUSE], [FALSE WHERE CLAUSE] from bob WHERE that = this";
            var          builder     = new SqlStatementBuilder(_connection, startSql);
            const string expectedSql = "select DISTINCT [FALSE FROM CLAUSE], [FALSE WHERE CLAUSE] from bob LEFT JOIN [bobby] ON bobs = bobbys WHERE that = this AND this = that";

            //---------------Execute Test ----------------------
            builder.AddJoin("left join", "bobby", "bobs = bobbys");
            builder.AppendCriteria("this = that");
            var actual = builder.GetStatement().Statement.ToString();

            //---------------Test Result -----------------------
            Assert.AreEqual(expectedSql, actual);
        }
Ejemplo n.º 3
0
        public void AppendCriteria_WithNoWhere_AddWhere()
        {
            //---------------Set up test pack-------------------
            const string startSql    = "select * from bob";
            var          builder     = new SqlStatementBuilder(_connection, startSql);
            const string appendSql   = "this = that";
            const string expectedSql = startSql + " WHERE " + appendSql;

            //---------------Execute Test ----------------------
            builder.AppendCriteria(appendSql);
            var actual = builder.GetStatement().Statement.ToString();

            //---------------Test Result -----------------------
            Assert.AreEqual(expectedSql, actual);
        }
Ejemplo n.º 4
0
        public void AddJoin_WithNoWhere_AlsoAddWhere()
        {
            //---------------Set up test pack-------------------
            const string startSql    = "select * from bob";
            var          builder     = new SqlStatementBuilder(_connection, startSql);
            const string expectedSql = "select DISTINCT * from bob LEFT JOIN [bobby] ON bobs = bobbys WHERE this = that";

            //---------------Execute Test ----------------------
            builder.AddJoin("left join", "bobby", "bobs = bobbys");
            builder.AppendCriteria("this = that");
            var actual = builder.GetStatement().Statement.ToString();

            //---------------Test Result -----------------------
            Assert.AreEqual(expectedSql, actual);
        }