Пример #1
0
        public static void SingleValueKeyEqual(object value1, object value2, bool expected)
        {
            var key1 = new IndexKey(SqlObject.New(SqlValueUtil.FromObject(value1)));
            var key2 = new IndexKey(SqlObject.New(SqlValueUtil.FromObject(value2)));

            Assert.Equal(expected, key1.Equals(key2));
        }
Пример #2
0
        public static void CompareSingleValue(object value1, object value2, int expetced)
        {
            var key1 = new IndexKey(SqlObject.New(SqlValueUtil.FromObject(value1)));
            var key2 = new IndexKey(SqlObject.New(SqlValueUtil.FromObject(value2)));

            Assert.Equal(expetced, key1.CompareTo(key2));
        }
Пример #3
0
        private static SqlBinaryExpression BinaryExpression(Func <SqlExpression, SqlExpression, SqlBinaryExpression> factory,
                                                            object value1, object value2)
        {
            var left  = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value1)));
            var right = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value2)));

            return(factory(left, right));
        }
Пример #4
0
        public static void CreateConstant(object value)
        {
            var obj = SqlObject.New(SqlValueUtil.FromObject(value));
            var exp = SqlExpression.Constant(obj);

            Assert.NotNull(exp.Value);
            Assert.Equal(obj, exp.Value);
        }
        public void CreateInvalidQuantify(SqlExpressionType expressionType, SqlExpressionType opType)
        {
            var left  = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(212)));
            var right = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(array)));

            var binary = SqlExpression.Binary(opType, left, right);

            Assert.Throws <ArgumentException>(() => SqlExpression.Quantify(expressionType, binary));
        }
Пример #6
0
        public void GetSqlTypeOfVarAssign(string name, object value, SqlTypeCode typeCode, int p)
        {
            var exp = SqlExpression.VariableAssign(name, SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value))));

            var varType = exp.GetSqlType(context);
            var type    = PrimitiveTypes.Type(typeCode, new { precision = p, maxSize = p, size = p });

            Assert.Equal(type, varType);
        }
        public async Task SimpleSelect(string column, SqlExpressionType op, object value, long expectedRowCount)
        {
            var columnName = new ObjectName(left.TableInfo.TableName, column);
            var expression = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value)));
            var result     = await left.SimpleSelectAsync(null, columnName, op, expression);

            Assert.NotNull(result);
            Assert.Equal(expectedRowCount, result.RowCount);
        }
        public static void CreateUnary(SqlExpressionType expressionType, object value)
        {
            var obj     = SqlObject.New(SqlValueUtil.FromObject(value));
            var operand = SqlExpression.Constant(obj);
            var exp     = SqlExpression.Unary(expressionType, operand);

            Assert.NotNull(exp.Operand);
            Assert.IsType <SqlConstantExpression>(exp.Operand);
        }
Пример #9
0
        public void GetVarAssingString(string name, object value, string expected)
        {
            var obj = SqlObject.New(SqlValueUtil.FromObject(value));
            var exp = SqlExpression.Constant(obj);

            var varRef = SqlExpression.VariableAssign(name, exp);
            var sql    = varRef.ToString();

            Assert.Equal(expected, sql);
        }
Пример #10
0
        public static void SerializeStringMatch(SqlExpressionType expressionType, string value, string pattern)
        {
            var exp = SqlExpression.StringMatch(expressionType,
                                                SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value))),
                                                SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(pattern))), null);

            var result = BinarySerializeUtil.Serialize(exp);

            Assert.Equal(exp.ExpressionType, result.ExpressionType);
        }
        public static void SerializeUnary(SqlExpressionType expressionType, object value)
        {
            var obj     = SqlObject.New(SqlValueUtil.FromObject(value));
            var operand = SqlExpression.Constant(obj);
            var exp     = SqlExpression.Unary(expressionType, operand);

            var result = BinarySerializeUtil.Serialize(exp);

            Assert.Equal(exp.ExpressionType, result.ExpressionType);
        }
Пример #12
0
        public static void GetCastType(object value, SqlTypeCode destTypeCode, int p, int s)
        {
            var targetType = PrimitiveTypes.Type(destTypeCode, new { precision = p, scale = s, maxSize = p, size = p });
            var obj        = SqlObject.New(SqlValueUtil.FromObject(value));
            var exp        = SqlExpression.Constant(obj);

            var cast = SqlExpression.Cast(exp, targetType);

            Assert.Equal(targetType, cast.TargetType);
        }
        public static void GetUnaryString(SqlExpressionType expressionType, object value, string expected)
        {
            var obj     = SqlObject.New(SqlValueUtil.FromObject(value));
            var operand = SqlExpression.Constant(obj);
            var exp     = SqlExpression.Unary(expressionType, operand);

            var s = exp.ToString();

            Assert.Equal(expected, s);
        }
        public static void GetUnaryType(SqlExpressionType expressionType, object value)
        {
            var obj     = SqlObject.New(SqlValueUtil.FromObject(value));
            var operand = SqlExpression.Constant(obj);
            var exp     = SqlExpression.Unary(expressionType, operand);

            var sqlType = exp.Type;

            Assert.Equal(obj.Type, sqlType);
        }
Пример #15
0
        public void CreateVarAssign(string name, object value)
        {
            var obj = SqlObject.New(SqlValueUtil.FromObject(value));
            var exp = SqlExpression.Constant(obj);

            var varRef = SqlExpression.VariableAssign(name, exp);

            Assert.NotNull(varRef.Value);
            Assert.Equal(exp, varRef.Value);
            Assert.Equal(name, varRef.VariableName);
        }
Пример #16
0
        private static SqlExpression FormDefaultValue(object value)
        {
            if (value == null)
            {
                return(null);
            }

            var obj = SqlObject.New(SqlValueUtil.FromObject(value));

            return(SqlExpression.Constant(obj));
        }
        public void CreateQuantify(SqlExpressionType expressionType, SqlExpressionType opType)
        {
            var left  = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(212)));
            var right = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(array)));

            var binary = SqlExpression.Binary(opType, left, right);
            var exp    = SqlExpression.Quantify(expressionType, binary);

            Assert.Equal(expressionType, exp.ExpressionType);
            Assert.Equal(opType, exp.Expression.ExpressionType);
        }
Пример #18
0
        public static void CreateStringMatch(SqlExpressionType expressionType, string value, string pattern)
        {
            var exp = SqlExpression.StringMatch(expressionType,
                                                SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value))),
                                                SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(pattern))), null);

            Assert.NotNull(exp);
            Assert.Equal(expressionType, exp.ExpressionType);
            Assert.NotNull(exp.Left);
            Assert.NotNull(exp.Pattern);
        }
Пример #19
0
        public static void GetStringMatchString(SqlExpressionType expressionType, string value, string pattern,
                                                string expected)
        {
            var exp = SqlExpression.StringMatch(expressionType,
                                                SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value))),
                                                SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(pattern))), null);

            var sql = exp.ToString();

            Assert.Equal(expected, sql);
        }
Пример #20
0
        public static void MultiValueKeyEqualToNull(object value1, object value2)
        {
            var key1 = new IndexKey(new[] {
                SqlObject.New(SqlValueUtil.FromObject(value1)),
                SqlObject.New(SqlValueUtil.FromObject(value2))
            });
            var key2 = key1.NullKey;

            Assert.NotEqual(key1, key2);
            Assert.True(key2.IsNull);
        }
Пример #21
0
        public static void SerializeCast(object value, SqlTypeCode destTypeCode, int p, int s)
        {
            var targetType = PrimitiveTypes.Type(destTypeCode, new { precision = p, scale = s, maxSize = p, size = p });
            var obj        = SqlObject.New(SqlValueUtil.FromObject(value));
            var exp        = SqlExpression.Constant(obj);

            var cast   = SqlExpression.Cast(exp, targetType);
            var result = BinarySerializeUtil.Serialize(cast);

            Assert.IsType <SqlConstantExpression>(result.Value);
        }
Пример #22
0
        public static void GetBinaryString(SqlExpressionType expressionType, object value1, object value2, string expected)
        {
            var obj1 = SqlObject.New(SqlValueUtil.FromObject(value1));
            var obj2 = SqlObject.New(SqlValueUtil.FromObject(value2));

            var exp = SqlExpression.Binary(expressionType, SqlExpression.Constant(obj1), SqlExpression.Constant(obj2));

            var s = exp.ToString();

            Assert.Equal(expected, s);
        }
Пример #23
0
        public async Task NonCorrelatedSelect(string column, SqlExpressionType op, SqlExpressionType subOp, object value1, object value2, long expected)
        {
            var columnName = new ObjectName(left.TableInfo.TableName, column);
            var exp1       = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value1)));
            var exp2       = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value2)));
            var array      = SqlExpression.Constant(SqlObject.Array(new SqlArray(new[] { exp1, exp2 })));
            var result     = await left.SelectNonCorrelatedAsync(null, columnName, op, subOp, array);

            Assert.NotNull(result);
            Assert.Equal(expected, result.RowCount);
        }
        public static void GetReferenceAssignString(string name, object value, string expected)
        {
            var objName = ObjectName.Parse(name);
            var obj     = SqlObject.New(SqlValueUtil.FromObject(value));
            var exp     = SqlExpression.Constant(obj);

            var refAssign = SqlExpression.ReferenceAssign(objName, exp);
            var sql       = refAssign.ToString();

            Assert.Equal(expected, sql);
        }
Пример #25
0
        public static void SerializeBinary(SqlExpressionType type, object value1, object value2)
        {
            var binary = SqlExpression.Binary(type, SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value1))),
                                              SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value2))));

            var result = BinarySerializeUtil.Serialize(binary);

            Assert.Equal(binary.ExpressionType, result.ExpressionType);
            Assert.Equal(binary.Left.ExpressionType, result.Left.ExpressionType);
            Assert.Equal(binary.Right.ExpressionType, result.Right.ExpressionType);
        }
Пример #26
0
        public static void CreateBinary(SqlExpressionType expressionType, object value1, object value2)
        {
            var obj1 = SqlObject.New(SqlValueUtil.FromObject(value1));
            var obj2 = SqlObject.New(SqlValueUtil.FromObject(value2));

            var exp = SqlExpression.Binary(expressionType, SqlExpression.Constant(obj1), SqlExpression.Constant(obj2));

            Assert.NotNull(exp);
            Assert.NotNull(exp.Left);
            Assert.NotNull(exp.Right);
        }
Пример #27
0
        public static void GetBinarySqlType(SqlExpressionType expressionType, object value1, object value2)
        {
            var obj1 = SqlObject.New(SqlValueUtil.FromObject(value1));
            var obj2 = SqlObject.New(SqlValueUtil.FromObject(value2));

            var exp = SqlExpression.Binary(expressionType, SqlExpression.Constant(obj1), SqlExpression.Constant(obj2));

            var sqltType = exp.Type;
            var wider    = obj1.Type.Wider(obj2.Type);

            Assert.Equal(wider, sqltType);
        }
Пример #28
0
        public static void GetConditionString(bool test, object ifTrue, object ifFalse, string expected)
        {
            var testExp    = SqlExpression.Constant(SqlObject.Boolean(test));
            var ifTrueExp  = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(ifTrue)));
            var ifFalseExp = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(ifFalse)));

            var condition = SqlExpression.Condition(testExp, ifTrueExp, ifFalseExp);

            var sql = condition.ToString();

            Assert.Equal(expected, sql);
        }
Пример #29
0
        public static void CreateInvokeWithMixedArguments(string methodName, string argName1, object value1, object value2)
        {
            var name = ObjectName.Parse(methodName);
            var arg1 = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value1)));
            var arg2 = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(value2)));

            var invoke = new Invoke(name);

            invoke.Arguments.Add(new InvokeArgument(argName1, arg1));

            Assert.Throws <ArgumentException>(() => invoke.Arguments.Add(new InvokeArgument(arg2)));
        }
        public void GetQuantifyString(SqlExpressionType expressionType, SqlExpressionType opType, string expected)
        {
            var left  = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(212)));
            var right = SqlExpression.Constant(SqlObject.New(SqlValueUtil.FromObject(array)));

            var binary = SqlExpression.Binary(opType, left, right);
            var exp    = SqlExpression.Quantify(expressionType, binary);

            var sql = exp.ToString();

            Assert.Equal(expected, sql);
        }