Example #1
0
        public void Select_All_From()
        {
            //arrange
            SqlConnect sql      = new CSharpedSql.SqlServer.SqlServerConnect();
            var        expected = "SELECT * FROM [test];";

            //act
            sql.Query(Select.From("test"));
            var actual = sql.ToString().TrimEnd();

            //assert
            Assert.AreEqual(expected, actual);
        }
Example #2
0
        public void Select_SomeColumns_From()
        {
            //arrange
            SqlConnect sql      = new CSharpedSql.SqlServer.SqlServerConnect();
            var        expected = "SELECT [hello], [name] FROM [test];";

            //act
            sql.Query(Select.From("test", "hello", "name"));
            var actual = sql.ToString().TrimEnd();

            //assert
            Assert.AreEqual(expected, actual);
        }
Example #3
0
        public void Select_From_Where_OrderBy_Join()
        {
            //arrange
            SqlConnect sql      = new CSharpedSql.SqlServer.SqlServerConnect();
            var        expected = "SELECT [test].[hello], [test2].[name] FROM [test] LEFT JOIN [test2] ON [test].[id] = [test2].[name] WHERE [test].[id] = @item0 ORDER BY [test2].[name] ASC;";

            //act
            sql.Query(Select.From("test", "test.hello", "test2.name") + Where.Equal("test.id", 2) + Join.Left("test", "id", "test2", "name") + OrderBy.ASC("test2.name"));
            var actual = sql.ToString().TrimEnd();

            //assert
            Assert.AreEqual(expected, actual);
        }
Example #4
0
        public void OrderBy_ASC()
        {
            //arrange
            SqlConnect sql      = new CSharpedSql.SqlServer.SqlServerConnect();
            var        expected = "SELECT * FROM [test] ORDER BY [id] ASC;";

            //act
            sql.Query(Select.From("test") + OrderBy.ASC("id"));
            var actual = sql.ToString().TrimEnd();

            //assert
            Assert.AreEqual(expected, actual);
        }
Example #5
0
        public void Join_Inner()
        {
            //arrange
            SqlConnect sql      = new CSharpedSql.SqlServer.SqlServerConnect();
            var        expected = "SELECT [test].[id] FROM [test] INNER JOIN [test2] ON [test].[id] = [test2].[name];";

            //act
            sql.Query(Select.From("test", "test.id") + Join.Inner("test", "id", "test2", "name"));
            var actual = sql.ToString().TrimEnd();

            //assert
            Assert.AreEqual(expected, actual);
        }
Example #6
0
        public void Where_Between()
        {
            //arrange
            SqlConnect sql      = new CSharpedSql.SqlServer.SqlServerConnect();
            var        expected = "SELECT * FROM [test] WHERE [id] BETWEEN @item0 AND @item1;";

            //act
            sql.Query(Select.From("test") + Where.Between("id", 3, 6));
            var actual = sql.ToString().TrimEnd();

            //assert
            Assert.AreEqual(expected, actual);
        }
Example #7
0
        public void Where_NotEqual()
        {
            //arrange
            SqlConnect sql      = new CSharpedSql.SqlServer.SqlServerConnect();
            var        expected = "SELECT * FROM [test] WHERE [id] <> @item0;";

            //act
            sql.Query(Select.From("test") + Where.NotEqual("id", 5));
            var actual = sql.ToString().TrimEnd();

            //assert
            Assert.AreEqual(expected, actual);
        }
Example #8
0
        public void Where_Any()
        {
            //arrange
            SqlConnect sql      = new CSharpedSql.SqlServer.SqlServerConnect();
            var        expected = "SELECT * FROM [test] WHERE [id] = ANY (SELECT * FROM [table]);";

            //act
            sql.Query(Select.From("test") + Where.Any("id", Select.From("table")));
            var actual = sql.ToString().TrimEnd();

            //assert
            Assert.AreEqual(expected, actual);
        }
Example #9
0
        public void Where_Or_Where()
        {
            //arrange
            SqlConnect sql      = new CSharpedSql.SqlServer.SqlServerConnect();
            var        expected = "SELECT * FROM [test] WHERE [id] = @item0 OR [name] <> @item1;";

            //act
            sql.Query(Select.From("test") + (Where.Equal("id", 87) | Where.NotEqual("name", "Tim")));
            var actual = sql.ToString().TrimEnd();

            //assert
            Assert.AreEqual(expected, actual);
        }
Example #10
0
        public void Where_NotExists()
        {
            //arrange
            SqlConnect sql      = new CSharpedSql.SqlServer.SqlServerConnect();
            var        expected = "SELECT * FROM [test] WHERE NOT EXISTS (SELECT [id] FROM [user] WHERE [id] = @item0);";

            //act
            sql.Query(Select.From("test") + Where.NotExists(Select.From("user", "id") + Where.Equal("id", 7)));
            var actual = sql.ToString().TrimEnd();

            //assert
            Assert.AreEqual(expected, actual);
        }