Exemple #1
0
        public void FromShouldAppendSource()
        {
            var select = new Select <DataClass>(c => c.Text).From("mytable");

            Assert.IsAssignableFrom(typeof(From <DataClass>), select);
            Assert.Equal("SELECT Text FROM mytable", select.ToString());
        }
Exemple #2
0
        public void WhereWithLikeShouldAddLIKE()
        {
            var where = new Select <DataSource>(c => c.Text)
                        .Where(c => c.Text)
                        .Like("abc");

            Assert.Equal("SELECT Text FROM DataSourceTable WHERE Text LIKE 'abc'", where.ToString());
        }
Exemple #3
0
        public void WhereConditionWithNullShouldPrintNULL(string funcName, string expectedEnd)
        {
            var condition = FuncProvider(funcName);

            var where = new Select <DataSource>(c => c.Text)
                        .Where(condition);

            Assert.True(where.ToString().EndsWith(expectedEnd), $"expected: {expectedEnd}, actual: {where.ToString()}");
        }
Exemple #4
0
        public void SimpleWhereClauseShouldWriteCorrectWhereString(string func, string expected)
        {
            var whereFunc = FuncProvider(func);

            var where = new Select <DataSource>(s => s.Text).Where(whereFunc);
            var firstPart = "SELECT Text FROM DataSourceTable ";
            var complete  = firstPart + expected;

            Assert.Equal(complete, where.ToString());
        }
Exemple #5
0
        public void TwoWhereConditionsConnectedViaORShouldBePutInParenthesis()
        {
            var where = new Select <DataSource>(s => s.Text)
                        .Where(s => s.Value > 10)
                        .Or(s => s.Text == "abc");

            var expected = "SELECT Text FROM DataSourceTable WHERE (Value > 10) OR Text = 'abc'";

            Assert.Equal(expected, where.ToString());
        }
Exemple #6
0
        public void ThreeWhereConditionsLinkedWithORShouldHaveCorrectParenthesis()
        {
            var where = new Select <DataSource>(s => s.Text)
                        .Where(s => s.Text != "abc")
                        .Or(s => s.Value < 5)
                        .Or(s => s.Value <= 10);

            var expected = "SELECT Text FROM DataSourceTable WHERE (Text != 'abc') OR (Value < 5) OR Value <= 10";

            Assert.Equal(expected, where.ToString());
        }
Exemple #7
0
        public void FromWithPrefixedSourceShouldPrependPrefixBeforeTableName()
        {
            var from = new Select <PrefixedSource>(p => p.Text).From(typeof(PrefixedSource));

            Assert.Equal("SELECT Text FROM dbo.Prefixed", from.ToString());
        }
Exemple #8
0
        public void WhereNotInConditionWithStringsShouldQuoteStrings()
        {
            var where = new Select <DataSource>(c => c.Text)
                        .Where(c => c.Text)
                        .NotIn(new[] { "a", "b", "c" });

            Assert.Equal("SELECT Text FROM DataSourceTable WHERE Text NOT IN ('a','b','c')", where.ToString());
        }
Exemple #9
0
        public void WhereNotInConditionWithIntsShouldSetCorrectParenthesis()
        {
            var where = new Select <DataSource>(c => c.Text)
                        .Where(c => c.Value)
                        .NotIn(new[] { 1, 2, 3, 4, 5 });

            Assert.Equal("SELECT Text FROM DataSourceTable WHERE Value NOT IN (1,2,3,4,5)", where.ToString());
        }
Exemple #10
0
        public void SelectWithPropertyShouldReturnCorrectSelectPart(string funcName, string expected)
        {
            var select = new Select <DataSource>(FuncProvider(funcName));

            Assert.Equal(expected, select.ToString());
        }
Exemple #11
0
        public void TwoWhereConditionsConnectedViaANDShouldBePutInParenthesis()
        {
            var where = new Select <DataSource>(s => s.Text)
                        .Where(s => s.Text != "abc")
                        .And(s => s.Text != "dce");

            Assert.Equal("SELECT Text FROM DataSourceTable WHERE (Text != 'abc') AND Text != 'dce'", where.ToString());
        }
Exemple #12
0
        public void SimpleWhereClauseComparingStringShouldPutStringInQuotes()
        {
            var where = new Select <DataSource>(s => s.Text).Where(s => s.Text == "abc");

            Assert.Equal("SELECT Text FROM DataSourceTable WHERE Text = 'abc'", where.ToString());
        }
Exemple #13
0
        public void FromWithNormalTypeShouldUseNameOfType()
        {
            var from = new Select <DataClass>(s => s.Text).From(typeof(DataClass));

            Assert.Equal("SELECT Text FROM DataClass", from.ToString());
        }
Exemple #14
0
        public void FromWithIDataSourceShouldUseNameOfAttribute()
        {
            var from = new Select <DataSource>(s => s.Text).From(typeof(DataSource));

            Assert.Equal("SELECT Text FROM DataSourceTable", from.ToString());
        }
Exemple #15
0
        public void FromWithoutPrefixedSourceShouldNotPrependPrefixBeforeTableName()
        {
            var from = new Select <DataClass>(c => c.Text).From(typeof(DataClass));

            Assert.Equal("SELECT Text FROM DataClass", from.ToString());
        }
Exemple #16
0
        public void FromWithExplicitPrefixShouldPrependPrefixBeforeTableName()
        {
            var from = new Select <DataSource>(c => c.Text).From(prefix: "prefix.");

            Assert.Equal("SELECT Text FROM prefix.DataSourceTable", from.ToString());
        }
Exemple #17
0
        public void NewSelectShouldReturnSelect()
        {
            var select = new Select <DataClass>();

            Assert.Equal("SELECT ", select.ToString());
        }