public void Union()
        {
            var expression = new RootQuery()
                             .Union
                             .Select(x => x.Simple)
                             .Select(x => new
            {
                x.Name,
                x.Description,
            });

            Expression <Func <JObject, object> > expected = data =>
                                                            ExpressionMethods.Select(
                ((Func <JToken, IQueryable <JToken> >)(x => ExpressionMethods.ChildrenOfType(x, "Simple")))((data["data"]["union"])),
                x => new
            {
                Name        = x["name"].ToObject <string>(),
                Description = x["description"].ToObject <string>(),
            });

            // We need to remove the (Func<JToken, IQueryable<JToken>>) cast that is needed by
            // C# but not by expression trees.
            expected = (Expression <Func <JObject, object> >)RemoveConvert.Default.Visit(expected);

            var query = new QueryBuilder().Build(expression);

            Assert.Equal(expected.ToString(), query.Expression.ToString());
        }
Beispiel #2
0
        public void Search_User_Name_Via_Edges()
        {
            var expression = new Query()
                             .Search("foo", SearchType.User, 30)
                             .Edges.Select(x => x.Node)
                             .Select(x => x.User.Name);

            Expression <Func <JObject, IEnumerable <object> > > expected = data =>
                                                                           ExpressionMethods.Select(
                ExpressionMethods.ChildrenOfType(data["data"]["search"]["edges"], "User"),
                x => x["name"].ToObject <string>());

            var query = new QueryBuilder().Build(expression);

            Assert.Equal(expected.ToString(), query.Expression.ToString());
        }
        public void Inline_Fragment()
        {
            var expression = new RootQuery()
                             .Data
                             .OfType <NestedData>()
                             .Select(x => new
            {
                x.Id,
                Items = x.Items.Select(i => i.Name),
            });

            Expression <Func <JObject, object> > expected = data =>
                                                            ExpressionMethods.Select(
                ExpressionMethods.ChildrenOfType(data["data"]["data"], "NestedData"),
                x => new
            {
                Id    = x["id"].ToObject <string>(),
                Items = ExpressionMethods.SelectEntity(x["items"], i => i["name"].ToObject <string>())
            });

            var query = new QueryBuilder().Build(expression);

            Assert.Equal(expected.ToString(), query.Expression.ToString());
        }