Пример #1
0
        public void Parse_Json()
        {
            // arrange
            byte[] source = Encoding.UTF8.GetBytes(
                JsonConvert.SerializeObject(
                    new GraphQLRequestDto
            {
                Query = FileResource.Open("kitchen-sink.graphql")
                        .NormalizeLineBreaks(),
                NamedQuery    = "ABC",
                OperationName = "DEF",
                Variables     = new Dictionary <string, object>
                {
                    { "a", "b" },
                    { "b", new Dictionary <string, object>
                      {
                          { "a", "b" },
                          { "b", true },
                          { "c", 1 },
                          { "d", 1.1 },
                      } },
                    { "c", new List <object>
                      {
                          new Dictionary <string, object>
                          {
                              { "a", "b" },
                          }
                      } },
                },
                Extensions = new Dictionary <string, object>
                {
                    { "aa", "bb" },
                    { "bb", new Dictionary <string, object>
                      {
                          { "aa", "bb" },
                          { "bb", true },
                          { "cc", 1 },
                          { "df", 1.1 },
                      } },
                    { "cc", new List <object>
                      {
                          new Dictionary <string, object>
                          {
                              { "aa", "bb" },
                          }
                      } },
                }
            }).NormalizeLineBreaks());

            // act
            var parsed = Utf8GraphQLRequestParser.ParseJson(source);

            // assert
            parsed.MatchSnapshot();
        }
Пример #2
0
        public void Parse_Socket_Message()
        {
            // arrange
            byte[] source = Encoding.UTF8.GetBytes(
                JsonConvert.SerializeObject(
                    new Dictionary <string, object>
            {
                {
                    "payload",
                    new Dictionary <string, object>
                    {
                        { "a", "b" },
                        { "b", new Dictionary <string, object>
                          {
                              { "a", "b" },
                              { "b", true },
                              { "c", 1 },
                              { "d", 1.1 },
                              { "e", false },
                              { "f", null }
                          } },
                        { "c", new List <object>
                          {
                              new Dictionary <string, object>
                              {
                                  { "a", "b" },
                              }
                          } },
                    }
                },
                {
                    "type",
                    "foo"
                },
                {
                    "id",
                    "bar"
                }
            }).NormalizeLineBreaks());

            // act
            GraphQLSocketMessage message =
                Utf8GraphQLRequestParser.ParseMessage(source);

            // assert
            Assert.Equal("foo", message.Type);
            Assert.Equal("bar", message.Id);

            File.WriteAllBytes("Foo.json", message.Payload.ToArray());

            Utf8GraphQLRequestParser.ParseJson(message.Payload).MatchSnapshot();
        }