Пример #1
0
        public void ConstructedError()
        {
#pragma warning disable 0429

            connection.Run(Query.Expr(() => 100 > 50 ? 1000 : ReQLExpression.Error <int>("unexpected error")));

            Action action = () => {
                connection.Run(Query.Expr(() => 50 > 100 ? 1000 : ReQLExpression.Error <int>("expected error")));
            };
            action.ShouldThrow <RethinkDbRuntimeException>()
            .WithMessage("Runtime error: expected error");

#pragma warning restore 0429
        }
        public static void RegisterOnConverterFactory(DefaultExpressionConverterFactory expressionConverterFactory)
        {
            expressionConverterFactory.RegisterTemplateMapping <string, string>(
                s => s.ToLowerInvariant(),
                s => new Term()
            {
                type = Term.TermType.DOWNCASE, args = { s }
            });

            expressionConverterFactory.RegisterTemplateMapping <string, string>(
                s => s.ToUpperInvariant(),
                s => new Term()
            {
                type = Term.TermType.UPCASE, args = { s }
            });

            expressionConverterFactory.RegisterTemplateMapping <string, string, MatchResponse>(
                (@string, regexp) => ReQLExpression.Match(@string, regexp),
                (@string, regexp) => new Term()
            {
                type = Term.TermType.MATCH, args = { @string, regexp }
            });
        }
        public static void RegisterOnConverterFactory(DefaultExpressionConverterFactory expressionConverterFactory)
        {
            var appendDelegate = (AppendDelegate <int>)ReQLExpression.Append;

            expressionConverterFactory.RegisterMethodCallMapping(appendDelegate.Method, ConvertAppendToTerm);

            var whereDelegate = (WhereDelegate <int>)Enumerable.Where;

            expressionConverterFactory.RegisterMethodCallMapping(whereDelegate.Method, ConvertEnumerableWhereToTerm);

            var anyDelegate = (AnyDelegate <int>)Enumerable.Any;

            expressionConverterFactory.RegisterMethodCallMapping(anyDelegate.Method, ConvertEnumerableAnyToTerm);

            expressionConverterFactory.RegisterTemplateMapping <IEnumerable <int>, int, bool>(
                (list, arg) => list.Contains(arg),
                (list, arg) => new Term()
            {
                type = Term.TermType.CONTAINS,
                args = { list, arg }
            });

            expressionConverterFactory.RegisterTemplateMapping <IList <int>, int, bool>(
                (list, arg) => list.Contains(arg),
                (list, arg) => new Term()
            {
                type = Term.TermType.CONTAINS,
                args = { list, arg }
            });

            expressionConverterFactory.RegisterTemplateMapping <List <int>, int, bool>(
                (list, arg) => list.Contains(arg),
                (list, arg) => new Term()
            {
                type = Term.TermType.CONTAINS,
                args = { list, arg }
            });

            expressionConverterFactory.RegisterTemplateMapping <IEnumerable <int>, int>(
                list => list.Count(),
                list => Count(list)
                );
            expressionConverterFactory.RegisterTemplateMapping <List <int>, int>(
                list => list.Count,
                list => Count(list)
                );
            expressionConverterFactory.RegisterTemplateMapping <ICollection <int>, int>(
                list => list.Count,
                list => Count(list)
                );

            expressionConverterFactory.RegisterTemplateMapping <int[], int, int[]>(
                (list, startIndex) => ReQLExpression.Slice(list, startIndex),
                (list, startIndex) => new Term()
            {
                type = Term.TermType.SLICE,
                args = { list, startIndex }
            });
            expressionConverterFactory.RegisterTemplateMapping <int[], int, int, int[]>(
                (list, startIndex, endIndex) => ReQLExpression.Slice(list, startIndex, endIndex),
                (list, startIndex, endIndex) => new Term()
            {
                type = Term.TermType.SLICE,
                args = { list, startIndex, endIndex }
            });
            expressionConverterFactory.RegisterTemplateMapping <int[], int, int, Bound, Bound, int[]>(
                (list, startIndex, endIndex, leftBound, rightBound) => ReQLExpression.Slice(list, startIndex, endIndex, leftBound, rightBound),
                (list, startIndex, endIndex, leftBound, rightBound) => new Term()
            {
                type    = Term.TermType.SLICE,
                args    = { list, startIndex, endIndex },
                optargs =
                {
                    new Term.AssocPair()
                    {
                        key = "left_bound",
                        val = leftBound,
                    },
                    new Term.AssocPair()
                    {
                        key = "right_bound",
                        val = rightBound,
                    }
                }
            });

            expressionConverterFactory.RegisterTemplateMapping <string, int>(
                (errorMessage) => ReQLExpression.Error <int>(errorMessage),
                (errorMessage) => new Term()
            {
                type = Term.TermType.ERROR,
                args = { errorMessage }
            });
        }