示例#1
0
        public void Deserializes_Pdu()
        {
            var data = new byte[]
            {
                0x00, 0x00, 0x00, 0x24,                   // length
                0x00, 0x00, 0x00, 0x03,                   // command
                0x00, 0x00, 0x00, 0x00,                   // status
                0x00, 0x00, 0x00, 0x10,                   // sequence
                0x73, 0x6f, 0x6d, 0x65, 0x69, 0x64, 0x00, // message_id
                0x02,                                     // source_ton
                0x08,                                     // source_npi
                0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, // source_address
                0x38, 0x39, 0x30, 0x00
            };

            var serializer = new QuerySerializer();
            var pdu = serializer.Deserialize(data);

            Assert.AreEqual(SmppCommand.Query, pdu.Command);
            Assert.AreEqual(16, pdu.SequenceNumber);
            Assert.AreEqual("someid", pdu.MessageId);
            Assert.AreEqual(TypeOfNumber.National, pdu.Source.Ton);
            Assert.AreEqual(NumericPlanIndicator.Internet, pdu.Source.Npi);
            Assert.AreEqual("1234567890", pdu.Source.Value);
        }
        public void Search_User_Name_Via_Edges()
        {
            var expected = @"{
  search(query: ""foo"", type: USER, first: 30) {
    edges {
      node {
        ... on User {
          __typename
          name
        }
      }
    }
  }
}";

            var expression = new Query()
                             .Search("foo", SearchType.User, 30)
                             .Edges.Select(x => x.Node)
                             .Select(x => x.User.Name);

            var serializer = new QuerySerializer(2);
            var result     = serializer.Serialize(new QueryBuilder().Build(expression).OperationDefinition);

            Assert.Equal(expected, result);
        }
        public void Repository_Details_With_Viewer()
        {
            var expected = @"{
  repositoryOwner(login: ""foo"") {
    repositories(first: 30) {
      edges {
        node {
          name
          isPrivate
        }
      }
    }
  }
  viewer
}";

            var expression = new Query()
                             .Select(x => x.RepositoryOwner("foo")
                                     .Repositories(30, null, null, null, null, null, null, null, null)
                                     .Edges
                                     .Select(y => y.Node)
                                     .Select(y => new
            {
                y.Name,
                y.IsPrivate,
                x.Viewer
            }));

            var serializer = new QuerySerializer(2);
            var result     = serializer.Serialize(new QueryBuilder().Build(expression).OperationDefinition);

            Assert.Equal(expected, result);
        }
示例#4
0
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            // make sure the channel uses the shared cookie container
            channel.GetProperty <IHttpCookieContainerManager>().CookieContainer =
                _factory.CookieContainer;

            request.Headers.Action = RewriteAction(request.Headers.Action);

            // Check for Query Options
            if (OperationContext.Current != null)
            {
                object queryProperty;
                object includeTotalCountProperty;

                OperationContext.Current.OutgoingMessageProperties.TryGetValue(QueryPropertyName, out queryProperty);
                OperationContext.Current.OutgoingMessageProperties.TryGetValue(IncludeTotalCountPropertyName, out includeTotalCountProperty);

                // Add Query Options header if any options were specified
                if (queryProperty != null || includeTotalCountProperty != null)
                {
                    var queryParts        = (queryProperty != null) ? QuerySerializer.Serialize((IQueryable)queryProperty) : null;
                    var includeTotalCount = (bool?)includeTotalCountProperty;

                    // Prepare the request message copy to be modified
                    MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
                    request = buffer.CreateMessage();
                    var header = new QueryOptionsHeader(queryParts, includeTotalCount == true);
                    request.Headers.Add(header);
                }
            }

            return(null);
        }
示例#5
0
            object IClientMessageInspector.BeforeSendRequest(ref Message request, IClientChannel channel)
            {
                request.Headers.Action = RewriteAction(request.Headers.Action);

                // Add Query Options if any are set
                var messageProperties = OperationContext.Current?.OutgoingMessageProperties;

                if (messageProperties != null)
                {
                    messageProperties.TryGetValue(QueryPropertyName, out object queryProperty);
                    messageProperties.TryGetValue(IncludeTotalCountPropertyName, out object includeTotalCountProperty);

                    // Add Query Options header if any options were specified
                    if (queryProperty != null || includeTotalCountProperty != null)
                    {
                        var queryParts        = (queryProperty != null) ? QuerySerializer.Serialize((IQueryable)queryProperty) : null;
                        var includeTotalCount = (bool?)includeTotalCountProperty;

                        var header = new QueryOptionsHeader(queryParts, includeTotalCount == true);
                        request.Headers.Add(header);
                    }
                }

                return(null);
            }
示例#6
0
        public void Union()
        {
            var expected = @"{
    union {
        ... on Simple {
            __typename
            name
            description
        }
    }
}";

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

            var query  = new QueryBuilder().Build(expression);
            var result = new QuerySerializer(4).Serialize(query.OperationDefinition);

            Assert.Equal(expected, result);
        }
示例#7
0
        public static UriBuilder WithQuery <TPayload>(UriBuilder builder, TPayload payload)
            where TPayload : class
        {
            QuerySerializer <TPayload> serializerFilter = new QuerySerializer <TPayload>();

            builder.Query = serializerFilter.Serialize(payload);
            return(builder);
        }
        public void TestQueryOperators_QueryComprehension()
        {
            // test where
            EntityQuery <City> citiesQuery = new EntityQuery <City>(_testClient, "GetCities", null, false, true);

            citiesQuery = from c in citiesQuery
                          where c.CountyName == "Lucas"
                          select c;
            List <ServiceQueryPart> parts = QuerySerializer.Serialize(citiesQuery.Query);

            Assert.AreEqual(1, parts.Count);
            Assert.AreEqual("where", parts[0].QueryOperator);
            Assert.AreEqual("(it.CountyName==\"Lucas\")", parts[0].Expression);
            Assert.AreSame(typeof(City), citiesQuery.EntityType);

            // test orderby, thenby
            citiesQuery = new EntityQuery <City>(_testClient, "GetCities", null, false, true);
            citiesQuery = from c in citiesQuery
                          orderby c.Name, c.StateName
            select c;

            parts = QuerySerializer.Serialize(citiesQuery.Query);
            Assert.AreEqual(1, parts.Count);
            Assert.AreEqual("orderby", parts[0].QueryOperator);
            Assert.AreEqual("it.Name, it.StateName", parts[0].Expression);

            // test orderby desc, thenby desc
            citiesQuery = new EntityQuery <City>(_testClient, "GetCities", null, false, true);
            citiesQuery = from c in citiesQuery
                          orderby c.Name descending, c.StateName descending
            select c;

            parts = QuerySerializer.Serialize(citiesQuery.Query);
            Assert.AreEqual(1, parts.Count);
            Assert.AreEqual("orderby", parts[0].QueryOperator);
            Assert.AreEqual("it.Name desc, it.StateName desc", parts[0].Expression);

            // test skip and take
            citiesQuery = new EntityQuery <City>(_testClient, "GetCities", null, false, true);
            citiesQuery = citiesQuery.Skip(20).Take(10);
            parts       = QuerySerializer.Serialize(citiesQuery.Query);
            Assert.AreEqual(2, parts.Count);
            Assert.AreEqual("skip", parts[0].QueryOperator);
            Assert.AreEqual("20", parts[0].Expression);
            Assert.AreEqual("take", parts[1].QueryOperator);
            Assert.AreEqual("10", parts[1].Expression);

            // test all together
            citiesQuery =
                (from c in new EntityQuery <City>(_testClient, "GetCities", null, false, true)
                 where c.CountyName == "Lucas"
                 orderby c.Name descending, c.StateName descending
                 select c
                ).Skip(20).Take(10);
            parts = QuerySerializer.Serialize(citiesQuery.Query);
            Assert.AreEqual(4, parts.Count);
        }
示例#9
0
        /// <summary>
        /// Converts the specified <paramref name="parameters"/> into an outbound
        /// <see cref="Message"/>. For query requests with query properties, stores the query
        /// parameters either in the To/Via or the message body.
        /// </summary>
        /// <param name="messageVersion">The version of the message to use.</param>
        /// <param name="parameters">The parameters passed to the client operation.</param>
        /// <returns>The message to send.</returns>
        public Message SerializeRequest(MessageVersion messageVersion, object[] parameters)
        {
            Message request = this._innerFormatter.SerializeRequest(messageVersion, parameters);

            object queryProperty             = null;
            object includeTotalCountProperty = null;

            if (OperationContext.Current != null)
            {
                OperationContext.Current.OutgoingMessageProperties.TryGetValue(WebDomainClient <object> .QueryPropertyName, out queryProperty);
                OperationContext.Current.OutgoingMessageProperties.TryGetValue(WebDomainClient <object> .IncludeTotalCountPropertyName, out includeTotalCountProperty);
            }

            List <KeyValuePair <string, string> > queryOptions = new List <KeyValuePair <string, string> >();

            if (queryProperty != null)
            {
                foreach (ServiceQueryPart queryPart in QuerySerializer.Serialize((IQueryable)queryProperty))
                {
                    queryOptions.Add(
                        new KeyValuePair <string, string>(
                            queryPart.QueryOperator,
                            queryPart.Expression));
                }
            }

            if (includeTotalCountProperty != null)
            {
                queryOptions.Add(
                    new KeyValuePair <string, string>("includeTotalCount", includeTotalCountProperty.ToString()));
            }

            if (queryOptions.Count > 0)
            {
                Debug.Assert(OperationContext.Current != null, "OpeartionContext.Current cannot be null at this point.");
                if (MessageUtility.IsHttpPOSTMethod(OperationContext.Current.OutgoingMessageProperties))
                {
                    MessageUtility.AddMessageQueryOptions(ref request, queryOptions);
                }
                else
                {
                    MessageUtility.AddQueryToUrl(ref request, queryOptions);
                }
            }

            if (request.Headers.To.AbsoluteUri.Length > WebHttpQueryClientMessageFormatter.MaximumUriLength)
            {
                throw new InvalidOperationException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              Resource.WebDomainClient_MaximumUriLengthExceeded,
                              WebHttpQueryClientMessageFormatter.MaximumUriLength));
            }

            return(request);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleQuery{TResult}"/> class.
        /// </summary>
        /// <param name="operationDefinition">The GraphQL operation definition.</param>
        /// <param name="resultBuilder">
        /// A function which transforms JSON data into the final result.
        /// </param>
        public SimpleQuery(
            OperationDefinition operationDefinition,
            Expression <Func <JObject, TResult> > resultBuilder)
        {
            var serializer = new QuerySerializer();

            OperationDefinition = operationDefinition;
            Query         = serializer.Serialize(operationDefinition);
            ResultBuilder = ExpressionCompiler.Compile(resultBuilder);
        }
示例#11
0
        public void QuerySerializerSerialize()
        {
            //-- Arrange
            QueryType queryObject = new QueryType()
            {
                Property  = "test_property_value",
                Array     = new string[] { "test_array_value_1", "test_array_value_2" },
                ArrayJson = new JsonType[]
                {
                    new JsonType()
                    {
                        Property = "property1"
                    },
                    new JsonType()
                    {
                        Property = "property2"
                    }
                },
                ArrayJsonWithMetadata = new JsonTypeWithMetadata[]
                {
                    new JsonTypeWithMetadata
                    {
                        Metadata = new Voucherify.Core.DataModel.Metadata(new System.Collections.Generic.Dictionary <string, object>()
                        {
                            { "property1", "value1" }
                        })
                    },
                    new JsonTypeWithMetadata
                    {
                        Metadata = new Voucherify.Core.DataModel.Metadata(new System.Collections.Generic.Dictionary <string, object>()
                        {
                            { "property2", "value2" }
                        })
                    }
                },
                Enum = EnumType.EnumValue2
            };
            string queryExpectedSerializedObject = "property_test=test_property_value" +
                                                   "&array_test=test_array_value_1" +
                                                   "&array_test=test_array_value_2" +
                                                   "&array_json[0][property_test]=property1" +
                                                   "&array_json[1][property_test]=property2" +
                                                   "&array_json_with_metadata[0][metadata][property1]=value1" +
                                                   "&array_json_with_metadata[1][metadata][property2]=value2" +
                                                   "&enum_test=Enum-Value-2";

            QuerySerializer <QueryType> querySerializer = new QuerySerializer <QueryType>();

            //-- Act
            string querySerializedObject = querySerializer.Serialize(queryObject);

            //-- Assert
            Assert.Equal(queryExpectedSerializedObject, querySerializedObject);
        }
示例#12
0
        public void SerializeSnake()
        {
            var testObject = new {
                Test1          = "Test",
                TestThing2     = 12345,
                LongTestThing3 = new DateTime(2021, 01, 25).ToString("yyyy-MM-dd")
            };

            var query = QuerySerializer.Serialize(testObject, new PascalToSnakeNamingPolicy());

            Assert.AreEqual("test1=Test&test_thing2=12345&long_test_thing3=2021-01-25", query);
        }
示例#13
0
        public void Serialize()
        {
            var testObject = new {
                Thing1 = "Test",
                Thing2 = 12345,
                Thing3 = new DateTime(2021, 01, 25).ToString("yyyy-MM-dd")
            };

            var query = QuerySerializer.Serialize(testObject);

            Assert.AreEqual("Thing1=Test&Thing2=12345&Thing3=2021-01-25", query);
        }
示例#14
0
        /// <summary>
        /// Method called by the framework to begin the asynchronous query operation.
        /// </summary>
        /// <param name="query">The query to invoke.</param>
        /// <param name="callback">The callback to invoke when the query has been executed.</param>
        /// <param name="userState">Optional user state associated with this operation.</param>
        /// <returns>
        /// An asynchronous result that identifies this query.
        /// </returns>
        protected override async Task <QueryCompletedResult> QueryAsyncCore(EntityQuery query, CancellationToken cancellationToken)
        {
            List <ServiceQueryPart> queryOptions = query.Query != null?QuerySerializer.Serialize(query.Query) : null;

            if (query.IncludeTotalCount)
            {
                queryOptions = queryOptions ?? new List <ServiceQueryPart>();
                queryOptions.Add(new ServiceQueryPart()
                {
                    QueryOperator = "includeTotalCount",
                    Expression    = "True"
                });
            }

            var response = await ExecuteRequestAsync(query.QueryName, query.HasSideEffects, query.Parameters, queryOptions, cancellationToken)
                           .ConfigureAwait(false);

#if DEBUG
            var Response = await response.Content.ReadAsStringAsync();
#endif

            IEnumerable <ValidationResult> validationErrors = null;
            try
            {
                var queryType   = typeof(QueryResult <>).MakeGenericType(query.EntityType);
                var queryResult = (QueryResult)ReadResponse(response, query.QueryName, queryType);
                if (queryResult != null)
                {
                    return(new QueryCompletedResult(
                               queryResult.GetRootResults().Cast <Entity>(),
                               queryResult.GetIncludedResults().Cast <Entity>(),
                               queryResult.TotalCount,
                               Enumerable.Empty <ValidationResult>()));
                }
            }
            catch (FaultException <RiaServiceBase.DomainServiceFault> fe)
            {
                if (fe.Detail.OperationErrors != null)
                {
                    validationErrors = fe.Detail.GetValidationErrors();
                }
                else
                {
                    throw GetExceptionFromServiceFault(fe.Detail);
                }
            }

            return(new QueryCompletedResult(
                       Enumerable.Empty <Entity>(),
                       Enumerable.Empty <Entity>(),
                       /* totalCount */ 0,
                       validationErrors ?? Enumerable.Empty <ValidationResult>()));
        }
示例#15
0
        public void Data_Select_Single_Member()
        {
            var expected = "{data{id}}";

            var expression = new RootQuery()
                             .Data
                             .Select(x => x.Id);

            var query  = new QueryBuilder().Build(expression);
            var result = new QuerySerializer().Serialize(query.OperationDefinition);

            Assert.Equal(expected, result);
        }
示例#16
0
        public void Select_Schema_QueryType_Kind()
        {
            var expected = "{__schema{queryType{kind}}}";

            var expression = new IntrospectionQuery()
                             .Schema.QueryType
                             .Select(x => x.Kind);

            var query  = new QueryBuilder().Build(expression);
            var result = new QuerySerializer().Serialize(query.OperationDefinition);

            Assert.Equal(expected, result);
        }
示例#17
0
        public void SimpleQuery_Select_Single_Member_Append_String()
        {
            var expected = "{simple(arg1:\"foo\"){name}}";

            var expression = new RootQuery()
                             .Simple("foo")
                             .Select(x => x.Name + " World!");

            var query  = new QueryBuilder().Build(expression);
            var result = new QuerySerializer().Serialize(query.OperationDefinition);

            Assert.Equal(expected, result);
        }
示例#18
0
        public void SimpleQuery_Select_Multiple_Members()
        {
            var expected = "{simple(arg1:\"foo\",arg2:2){name description}}";

            var expression = new RootQuery()
                             .Simple("foo", 2)
                             .Select(x => new { x.Name, x.Description });

            var query  = new QueryBuilder().Build(expression);
            var result = new QuerySerializer().Serialize(query.OperationDefinition);

            Assert.Equal(expected, result);
        }
示例#19
0
        public void Boolean_Paramter()
        {
            var expected = "{another(boolean:false){name}}";

            var expression = new RootQuery()
                             .Another(false)
                             .Select(x => x.Name);

            var query  = new QueryBuilder().Build(expression);
            var result = new QuerySerializer().Serialize(query.OperationDefinition);

            Assert.Equal(expected, result);
        }
示例#20
0
        public void SimpleQuery_Select_Append_Two_Identical_Members()
        {
            var expected = "{simple(arg1:\"foo\"){name}}";

            var expression = new RootQuery()
                             .Simple("foo")
                             .Select(x => x.Name + x.Name);

            var query  = new QueryBuilder().Build(expression);
            var result = new QuerySerializer().Serialize(query.OperationDefinition);

            Assert.Equal(expected, result);
        }
示例#21
0
        public void RepositoryOwner_Repositories_Query_Viewer()
        {
            var expected = @"{
  repositoryOwner(login: ""foo"") {
    repositories(first: 30) {
      edges {
        node {
          id
          name
          owner {
            login
            avatarUrl
          }
          isFork
          isPrivate
        }
      }
    }
  }
  viewer {
    login
    email
  }
}";

            var expression = new Query()
                             .Select(root => root
                                     .RepositoryOwner("foo")
                                     .Repositories(30, null, null, null, null, null, null, null, null)
                                     .Edges.Select(x => x.Node)
                                     .Select((Repository x) => new
            {
                x.Id,
                x.Name,
                Owner = x.Owner.Select(o => new
                {
                    o.Login,
                    AvatarUrl = o.AvatarUrl(null),
                }),
                x.IsFork,
                x.IsPrivate,
                Login = root.Viewer.Select(l => l.Login),
                root.Viewer.Email
            }));

            var serializer = new QuerySerializer(2);
            var result     = serializer.Serialize(new QueryBuilder().Build(expression).OperationDefinition);

            Assert.Equal(expected, result);
        }
示例#22
0
 public override string ToString()
 {
     if (Arguments.Any())
     {
         var    serializer = new QuerySerializer();
         string arguments  = string.Join(", ", Arguments.Select(t =>
         {
             serializer.Visit(t.Value);
             return(t.Name.Value + " = " + serializer.Value);
         }));
         return(Name + "(" + arguments + ")");
     }
     return(Name);
 }
示例#23
0
        public void Viewer_Login_Email()
        {
            var expected = @"{
  viewer {
    login
    email
  }
}";

            var expression = new Query().Viewer.Select(x => new { x.Login, x.Email });

            var serializer = new QuerySerializer(2);
            var result     = serializer.Serialize(new QueryBuilder().Build(expression).OperationDefinition);

            Assert.Equal(expected, result);
        }
示例#24
0
        public void TestQueryOperators_QueryMethods()
        {
            // test where
            EntityQuery <City> citiesQuery = new EntityQuery <City>(_testClient, "GetCities", null, false, true);

            citiesQuery = citiesQuery.Where(c => c.CountyName == "Lucas");
            List <ServiceQueryPart> parts = QuerySerializer.Serialize(citiesQuery.Query);

            Assert.AreEqual(1, parts.Count);
            Assert.AreEqual("where", parts[0].QueryOperator);
            Assert.AreEqual("(it.CountyName==\"Lucas\")", parts[0].Expression);

            // test orderby, thenby
            citiesQuery = new EntityQuery <City>(_testClient, "GetCities", null, false, true);
            citiesQuery = citiesQuery.OrderBy(c => c.Name).ThenBy(c => c.StateName);
            parts       = QuerySerializer.Serialize(citiesQuery.Query);
            Assert.AreEqual(1, parts.Count);
            Assert.AreEqual("orderby", parts[0].QueryOperator);
            Assert.AreEqual("it.Name, it.StateName", parts[0].Expression);

            // test orderby desc, thenby desc
            citiesQuery = new EntityQuery <City>(_testClient, "GetCities", null, false, true);
            citiesQuery = citiesQuery.OrderByDescending(c => c.Name).ThenByDescending(c => c.StateName);
            parts       = QuerySerializer.Serialize(citiesQuery.Query);
            Assert.AreEqual(1, parts.Count);
            Assert.AreEqual("orderby", parts[0].QueryOperator);
            Assert.AreEqual("it.Name desc, it.StateName desc", parts[0].Expression);

            // test skip and take
            citiesQuery = new EntityQuery <City>(_testClient, "GetCities", null, false, true);
            citiesQuery = citiesQuery.Skip(20).Take(10);
            parts       = QuerySerializer.Serialize(citiesQuery.Query);
            Assert.AreEqual(2, parts.Count);
            Assert.AreEqual("skip", parts[0].QueryOperator);
            Assert.AreEqual("20", parts[0].Expression);
            Assert.AreEqual("take", parts[1].QueryOperator);
            Assert.AreEqual("10", parts[1].Expression);

            // test all together
            citiesQuery = new EntityQuery <City>(_testClient, "GetCities", null, false, true)
                          .Where(c => c.CountyName == "Lucas")
                          .OrderBy(c => c.Name).ThenBy(c => c.StateName)
                          .Skip(20)
                          .Take(10);
            parts = QuerySerializer.Serialize(citiesQuery.Query);
            Assert.AreEqual(4, parts.Count);
        }
示例#25
0
        public void Nested_Selects()
        {
            var expected = "{data{id items{name}}}";

            var expression = new RootQuery()
                             .Data
                             .Select(x => new
            {
                x.Id,
                Items = x.Items.Select(i => i.Name),
            });

            var query  = new QueryBuilder().Build(expression);
            var result = new QuerySerializer().Serialize(query.OperationDefinition);

            Assert.Equal(expected, result);
        }
示例#26
0
        public void Inline_Fragment()
        {
            var expected = "{data{... on NestedData{__typename id items{name}}}}";

            var expression = new RootQuery()
                             .Data
                             .OfType <NestedData>()
                             .Select(x => new
            {
                x.Id,
                Items = x.Items.Select(i => i.Name),
            });

            var query  = new QueryBuilder().Build(expression);
            var result = new QuerySerializer().Serialize(query.OperationDefinition);

            Assert.Equal(expected, result);
        }
示例#27
0
        public void QuerySerialize()
        {
            //-- Arrange
            QueryType queryObject = new QueryType()
            {
                Property = "test_property_value",
                Array    = new string[] { "test_array_value_1", "test_array_value_2" },
                Enum     = EnumType.EnumValue2
            };
            string queryExpectedSerializedObject = "property_test=test_property_value&array_test=test_array_value_1&array_test=test_array_value_2&enum_test=Enum-Value-2";

            QuerySerializer <QueryType> querySerializer = new QuerySerializer <QueryType>();

            //-- Act
            string querySerializedObject = querySerializer.Serialize(queryObject);

            //-- Assert
            Assert.AreEqual(queryExpectedSerializedObject, querySerializedObject);
        }
示例#28
0
        public void RepositoryOwner_Repositories_Query()
        {
            var expected = @"{
  repositoryOwner(login: ""foo"") {
    repositories(first: 30) {
      edges {
        node {
          id
          name
          owner {
            login
          }
          isFork
          isPrivate
        }
      }
    }
  }
}";

            var expression = new Query()
                             .RepositoryOwner(login: "******")
                             .Repositories(first: 30)
                             .Edges
                             .Select(x => x.Node)
                             .Select(x => new
            {
                x.Id,
                x.Name,
                Owner = x.Owner.Select(o => new
                {
                    o.Login
                }),
                x.IsFork,
                x.IsPrivate,
            });

            var serializer = new QuerySerializer(2);
            var result     = serializer.Serialize(new QueryBuilder().Build(expression).OperationDefinition);

            Assert.Equal(expected, result);
        }
示例#29
0
        public void Serializes_Pdu()
        {
            var expectedResult = new byte[]
            {
                0x00, 0x00, 0x00, 0x24,                   // length
                0x00, 0x00, 0x00, 0x03,                   // command
                0x00, 0x00, 0x00, 0x00,                   // status
                0x00, 0x00, 0x00, 0x10,                   // sequence
                0x73, 0x6f, 0x6d, 0x65, 0x69, 0x64, 0x00, // message_id
                0x02,                                     // source_ton
                0x08,                                     // source_npi
                0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, // source_address
                0x38, 0x39, 0x30, 0x00
            };

            var pdu = new Query(16, "someid", new Address(TypeOfNumber.National, NumericPlanIndicator.Internet, "1234567890"));
            var serializer = new QuerySerializer();
            var result = serializer.Serialize(pdu);

            CollectionAssert.AreEqual(expectedResult, result);
        }
示例#30
0
        public void User_Email_Query()
        {
            var expected = @"{
  search(query: ""foo"", type: USER, first: 1) {
    userCount
    edges {
      node {
        ... on User {
          __typename
          id
          login
          avatarUrl
          websiteUrl
          name
        }
      }
    }
  }
}";

            var expression = new Query()
                             .Search(first: 1, type: SearchType.User, query: "foo")
                             .Select(x => new
            {
                x.UserCount,
                User = x.Edges.Select(e => e.Node).OfType <User>().Select((User u) => new
                {
                    u.Id,
                    u.Login,
                    AvatarUrl = u.AvatarUrl(null),
                    u.WebsiteUrl,
                    u.Name,
                })
            });

            var serializer = new QuerySerializer(2);
            var result     = serializer.Serialize(new QueryBuilder().Build(expression).OperationDefinition);

            Assert.Equal(expected, result);
        }
示例#31
0
        public void Field_Aliases()
        {
            var expected = @"{
    simple(arg1: ""foo"", arg2: 1) {
        foo: name
        bar: description
    }
}";

            var expression = new RootQuery()
                             .Simple("foo", 1)
                             .Select(x => new
            {
                Foo = x.Name,
                Bar = x.Description,
            });

            var query  = new QueryBuilder().Build(expression);
            var result = new QuerySerializer(4).Serialize(query.OperationDefinition);

            Assert.Equal(expected, result);
        }
示例#32
0
        public void Select_Schema_Enum_Types()
        {
            var expression = new IntrospectionQuery()
                             .Schema
                             .Select(x => new SchemaModel
            {
                Types = x.Types.Select(t => new TypeModel
                {
                    Fields = t.Fields(true).Select((Field f) => new FieldModel
                    {
                        Name = f.Name,
                    }).ToList(),
                    EnumValues = t.EnumValues(true).Select((EnumValue e) => new EnumValueModel
                    {
                        Name = e.Name,
                    }).ToList(),
                }).ToList()
            });

            var expectedQuery = @"{
  __schema {
    types {
      fields(includeDeprecated: true) {
        name
      }
      enumValues(includeDeprecated: true) {
        name
      }
    }
  }
}";
            var query         = new QueryBuilder().Build(expression);
            var queryResult   = new QuerySerializer(2).Serialize(query.OperationDefinition);

            Assert.Equal(expectedQuery, queryResult);
        }