public static void AssertSubqueryEqual <T>(Expression <Func <JObject, T> > expectedResultExpression,
                                                   Expression <Func <JObject, JToken> > expectedPageInfoExpression,
                                                   Expression <Func <JObject, IEnumerable <JToken> > > expectedParentIdExpression,
                                                   Expression <Func <JObject, IEnumerable <JToken> > > expectedParentPageInfoExpression,
                                                   PagedSubquery <T> subquery)
        {
            var resultExpression = ExpressionCompiler.GetSourceExpression(subquery.MasterQuery.ResultBuilder);

            Assert.Equal(StripWhitespace(expectedResultExpression.ToReadableString()), StripWhitespace(resultExpression.ToReadableString()));

            var pageInfoExpression = ExpressionCompiler.GetSourceExpression(subquery.PageInfo);

            Assert.Equal(StripWhitespace(expectedPageInfoExpression.ToReadableString()), StripWhitespace(pageInfoExpression.ToReadableString()));

            var parentIdExpression = ExpressionCompiler.GetSourceExpression(subquery.ParentIds);

            Assert.Equal(StripWhitespace(expectedParentIdExpression.ToReadableString()), StripWhitespace(parentIdExpression.ToReadableString()));

            var parentPageInfoExpression = ExpressionCompiler.GetSourceExpression(subquery.ParentPageInfo);

            Assert.Equal(StripWhitespace(expectedParentPageInfoExpression.ToReadableString()), StripWhitespace(parentPageInfoExpression.ToReadableString()));
        }
Example #2
0
        private ISubquery BuildSubquery(
            Expression expression,
            Expression <Func <JObject, IEnumerable <JToken> > > parentIds,
            Expression <Func <JObject, IEnumerable <JToken> > > parentPageInfo)
        {
            Initialize();

            var resultType = typeof(IEnumerable <>).MakeGenericType(expression.Type.GenericTypeArguments[0]);
            var rewritten  = Visit(expression);
            var toList     = ToFinalList(rewritten, resultType);
            var lambda     = Expression.Lambda(
                toList.AddCast(resultType),
                RootDataParameter);
            var master = SimpleSubquery <object> .Create(
                resultType,
                root,
                lambda,
                parentIds,
                pageInfo,
                parentPageInfo);

            if (subqueries.Count == 0)
            {
                return(master);
            }
            else
            {
                return(PagedSubquery <object> .Create(
                           resultType,
                           master,
                           subqueries,
                           parentIds,
                           pageInfo,
                           parentPageInfo));
            }
        }