Add() public static method

public static Add ( SqlExpression left, SqlExpression right ) : SqlBinaryExpression
left SqlExpression
right SqlExpression
return SqlBinaryExpression
Ejemplo n.º 1
0
        public void NumericAddToString()
        {
            var exp1   = SqlExpression.Constant(Field.Number(new SqlNumber(4566, 10)));
            var exp2   = SqlExpression.Constant(Field.Number(new SqlNumber(8991.67, 10)));
            var addExp = SqlExpression.Add(exp1, exp2);

            string s = null;

            Assert.DoesNotThrow(() => s = addExp.ToString());
            Assert.IsNotNull(s);
            Assert.IsNotEmpty(s);
            Assert.AreEqual("4566 + 8991.670000", s);
        }
Ejemplo n.º 2
0
        public static void SimpleCase()
        {
            var first            = SqlExpression.Constant(34);
            var second           = SqlExpression.Add(SqlExpression.Constant(10), SqlExpression.Constant(24));
            var condition        = SqlExpression.Equal(first, second);
            var returnExpression = SqlExpression.Constant("It was equal");
            var conditional      = SqlExpression.Conditional(condition, returnExpression);

            var result = conditional.EvaluateToConstant(null, null);

            Assert.IsNotNull(result);
            Assert.IsFalse(Field.IsNullField(result));
            Assert.AreEqual("It was equal", result.Value.ToString());
        }
Ejemplo n.º 3
0
        public static void CaseNestedFalse()
        {
            var first         = SqlExpression.Constant(34);
            var second        = SqlExpression.Add(SqlExpression.Constant(10), SqlExpression.Constant(34));
            var condition     = SqlExpression.Equal(first, second);
            var ifTrue        = SqlExpression.Constant("It was equal");
            var ifFalseReturn = SqlExpression.Constant("It was not equal");
            var ifFalse       = SqlExpression.Conditional(SqlExpression.Constant(true), ifFalseReturn);

            var conditional = SqlExpression.Conditional(condition, ifTrue, ifFalse);

            var result = conditional.EvaluateToConstant(null, null);

            Assert.IsNotNull(result);
            Assert.IsFalse(Field.IsNullField(result));
            Assert.AreEqual("It was not equal", result.Value.ToString());
        }
Ejemplo n.º 4
0
        public void StringAndStringAdd()
        {
            var exp1   = SqlExpression.Constant(Field.String("The quick brown fox "));
            var exp2   = SqlExpression.Constant(Field.VarChar("jumps over the lazy dog"));
            var addExp = SqlExpression.Add(exp1, exp2);

            SqlExpression resultExp = null;

            Assert.DoesNotThrow(() => resultExp = addExp.Evaluate());
            Assert.IsNotNull(resultExp);
            Assert.IsInstanceOf <SqlConstantExpression>(resultExp);

            var constExp = (SqlConstantExpression)resultExp;

            Assert.IsNotNull(constExp.Value.Value);
            Assert.IsInstanceOf <StringType>(constExp.Value.Type);
            Assert.IsInstanceOf <SqlString>(constExp.Value.Value);
            Assert.AreEqual(new SqlString("The quick brown fox jumps over the lazy dog"), (SqlString)constExp.Value.Value);
        }
Ejemplo n.º 5
0
        public void NumericAndBooleanAdd()
        {
            var exp1   = SqlExpression.Constant(Field.Number(new SqlNumber(4566)));
            var exp2   = SqlExpression.Constant(Field.Boolean(true));
            var addExp = SqlExpression.Add(exp1, exp2);

            SqlExpression resultExp = null;

            Assert.DoesNotThrow(() => resultExp = addExp.Evaluate());
            Assert.IsNotNull(resultExp);
            Assert.IsInstanceOf <SqlConstantExpression>(resultExp);

            var constExp = (SqlConstantExpression)resultExp;

            Assert.IsNotNull(constExp.Value.Value);
            Assert.IsInstanceOf <NumericType>(constExp.Value.Type);
            Assert.IsInstanceOf <SqlNumber>(constExp.Value.Value);

            var actual   = ((SqlNumber)constExp.Value.Value).Round(2);
            var expected = new SqlNumber(4567, 2);

            Assert.AreEqual(expected, actual);
        }