Ejemplo n.º 1
0
        public void AddJoin_WithWhere_AlsoAddWhere_AddAnotherJoin()
        {
            //---------------Set up test pack-------------------
            const string startSql    = "select * from bob WHERE that = this";
            var          builder     = new SqlStatementBuilder(_connection, startSql);
            const string expectedSql = "select DISTINCT * from (bob LEFT JOIN [bobby] ON bobs = bobbys) " +
                                       "LEFT JOIN [bobbin] ON bobbys = bobbins WHERE that = this AND this = that";

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

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

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

            //---------------Test Result -----------------------
            Assert.AreEqual(expectedSql, actual);
        }
Ejemplo n.º 3
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.º 4
0
        public void AddJoin_WithEmptyStatement()
        {
            //---------------Set up test pack-------------------
            const string startSql = "";
            var          builder  = new SqlStatementBuilder(_connection, startSql);

            //---------------Execute Test ----------------------
            try
            {
                builder.AddJoin("left join", "bobby", "bobs = bobbys");
                Assert.Fail("Expected to throw an SqlStatementException");
            }
            //---------------Test Result -----------------------
            catch (SqlStatementException ex)
            {
                StringAssert.Contains("Cannot add a join clause to a SQL statement that does not contain a from clause", ex.Message);
            }
        }