Ejemplo n.º 1
0
        public async Task ExecuteAsync_Default_CallInterceptor()
        {
            // arrange
            var interceptorMock  = new Mock <IInMemoryRequestInterceptor>();
            var client           = new InMemoryClient("Foo");
            var variables        = new Dictionary <string, object?>();
            var operationRequest = new OperationRequest("foo", new StubDocument(), variables);
            var executor         = new StubExecutor();

            client.Executor = executor;
            client.RequestInterceptors.Add(interceptorMock.Object);
            client.RequestInterceptors.Add(interceptorMock.Object);
            interceptorMock
            .Setup(x => x
                   .OnCreateAsync(
                       StubExecutor.ApplicationServiceProvider,
                       operationRequest,
                       It.IsAny <IQueryRequestBuilder>(),
                       It.IsAny <CancellationToken>()));

            // act
            await client.ExecuteAsync(operationRequest);

            // assert
            interceptorMock
            .Verify(x => x
                    .OnCreateAsync(
                        StubExecutor.ApplicationServiceProvider,
                        operationRequest,
                        It.IsAny <IQueryRequestBuilder>(),
                        It.IsAny <CancellationToken>()),
                    Times.Exactly(2));
        }
Ejemplo n.º 2
0
        public async Task ExecuteAsync_NoExecutor_ThrowException()
        {
            // arrange
            var client           = new InMemoryClient("Foo");
            var operationRequest =
                new OperationRequest("foo", new StubDocument());

            // act
            Exception?ex =
                await Record.ExceptionAsync(async() =>
                                            await client.ExecuteAsync(operationRequest));

            // assert
            Assert.IsType <GraphQLClientException>(ex);
        }
Ejemplo n.º 3
0
        public async Task ExecuteAsync_Default_ExecuteQuery()
        {
            // arrange
            var client           = new InMemoryClient("Foo");
            var variables        = new Dictionary <string, object?>();
            var operationRequest = new OperationRequest("foo", new StubDocument(), variables);
            var executor         = new StubExecutor();

            client.Executor = executor;

            // act
            await client.ExecuteAsync(operationRequest);

            // assert
            Assert.Equal(operationRequest.Name, executor.Request.OperationName);
            Assert.Equal(variables, executor.Request.VariableValues);
            Assert.Equal("{ foo }", Encoding.UTF8.GetString(executor.Request.Query !.AsSpan()));
        }