Example #1
0
        public async Task Serialize_OutputStream_Is_Null()
        {
            // arrange
            var serializer = new JsonArrayResponseStreamSerializer();
            var stream     = new Mock <IResponseStream>();

            // act
            Task Action() =>
            serializer.SerializeAsync(stream.Object, null !, CancellationToken.None);

            // assert
            await Assert.ThrowsAsync <ArgumentNullException>(Action);
        }
Example #2
0
        public async Task Serialize_Response_Stream()
        {
            // arrange
            IExecutionResult result =
                await new ServiceCollection()
                .AddStarWarsRepositories()
                .AddGraphQL()
                .AddStarWarsTypes()
                .ExecuteRequestAsync(
                    @"{
                            hero(episode: NEW_HOPE) {
                                id
                                ... @defer(label: ""friends"") {
                                    friends {
                                        nodes {
                                            id
                                            ... @defer {
                                                name
                                            }
                                        }
                                    }
                                }
                            }
                        }");

            IResponseStream stream = Assert.IsType <DeferredQueryResult>(result);

            var memoryStream = new MemoryStream();
            var serializer   = new JsonArrayResponseStreamSerializer();

            // act
            await serializer.SerializeAsync(stream, memoryStream, CancellationToken.None);

            // assert
            memoryStream.Seek(0, SeekOrigin.Begin);
            new StreamReader(memoryStream).ReadToEnd().MatchSnapshot();
        }