public async Task SubscribeToReview()
        {
            // arrange
            IQueryExecutor executor = CreateSchema().MakeExecutable();

            // act
            var responseStream =
                (IResponseStream)await executor.ExecuteAsync(
                    "subscription { onCreateReview(episode: NEWHOPE) " +
                    "{ stars } }");

            // assert
            IExecutionResult result = await executor.ExecuteAsync(@"
                mutation {
                    createReview(episode: NEWHOPE,
                        review: { stars: 5 commentary: ""foo"" }) {
                        stars
                        commentary
                    }
                }");

            IReadOnlyQueryResult eventResult = null;

            using (var cts = new CancellationTokenSource(2000))
            {
                await foreach (IReadOnlyQueryResult item in
                               responseStream.WithCancellation(cts.Token))
                {
                    eventResult = item;
                    break;
                }
            }

            eventResult.MatchSnapshot();
        }
        public async Task DeserializeQueryResultWithExtensions()
        {
            // arrange
            var qux = new OrderedDictionary {
                { "quux", 123 }
            };
            var baz = new OrderedDictionary {
                { "qux", qux }
            };
            var objectList = new List <object> {
                baz
            };
            var scalarList = new List <object> {
                123
            };

            var result = QueryResultBuilder.New();

            var data = new OrderedDictionary();

            data["foo"] = objectList;
            data["bar"] = scalarList;
            data["baz"] = baz;
            result.SetData(data);

            var extensionData = new ExtensionData();

            extensionData["foo"] = objectList;
            extensionData["bar"] = scalarList;
            extensionData["baz"] = baz;
            result.SetExtensions(extensionData);

            var stream     = new MemoryStream();
            var serializer = new JsonQueryResultSerializer();
            await serializer.SerializeAsync(result.Create(), stream);

            byte[] buffer = stream.ToArray();

            var serializedResult = Utf8GraphQLRequestParser.ParseJson(buffer);

            // act
            IReadOnlyQueryResult deserializedResult =
                HttpResponseDeserializer.Deserialize(
                    (IReadOnlyDictionary <string, object>)serializedResult);

            // assert
            deserializedResult.MatchSnapshot(m => m.Ignore(c => c.Field <JObject>("Extensions")));
            deserializedResult.Extensions.OrderBy(t => t.Key)
            .MatchSnapshot(new SnapshotNameExtension("extensions"));
        }
        public async Task SubscribeToReview_With_Variables()
        {
            // arrange
            IRequestExecutor executor = await CreateExecutorAsync();

            // act
            var subscriptionResult =
                (ISubscriptionResult)await executor.ExecuteAsync(
                    @"subscription ($ep: Episode!) {
                        onReview(episode: $ep) {
                            stars
                        }
                    }",
                    new Dictionary <string, object> {
                { "ep", "NEW_HOPE" }
            },
                    CancellationToken.None);

            // assert
            IExecutionResult result =
                await executor.ExecuteAsync(@"
                    mutation {
                        createReview(episode: NEW_HOPE,
                            review: { stars: 5 commentary: ""foo"" }) {
                            stars
                            commentary
                        }
                    }");

            IReadOnlyQueryResult eventResult = null;

            using (var cts = new CancellationTokenSource(2000))
            {
                await foreach (IQueryResult queryResult in
                               subscriptionResult.ReadResultsAsync().WithCancellation(cts.Token))
                {
                    var item = (IReadOnlyQueryResult)queryResult;
                    eventResult = item;
                    break;
                }
            }

            eventResult?.MatchSnapshot();
        }
        public async Task SubscribeToReview_FragmentDefinition()
        {
            // arrange
            IRequestExecutor executor = await CreateExecutorAsync();

            // act
            var subscriptionResult =
                (ISubscriptionResult)await executor.ExecuteAsync(
                    @"subscription {
                        onReview(episode: NEW_HOPE) {
                            ... SomeFrag
                        }
                    }

                    fragment SomeFrag on Review {
                        stars
                    }");

            // assert
            IExecutionResult result =
                await executor.ExecuteAsync(@"
                    mutation {
                        createReview(episode: NEW_HOPE,
                            review: { stars: 5 commentary: ""foo"" }) {
                            stars
                            commentary
                        }
                    }");

            IReadOnlyQueryResult eventResult = null;

            using (var cts = new CancellationTokenSource(2000))
            {
                await foreach (IQueryResult queryResult in
                               subscriptionResult.ReadResultsAsync().WithCancellation(cts.Token))
                {
                    var item = (IReadOnlyQueryResult)queryResult;
                    eventResult = item;
                    break;
                }
            }

            eventResult?.MatchSnapshot();
        }