public async Task UseDelegateMiddleware()
        {
            // arrange
            var schema = Schema.Create(@"
                type Query { a: String }
                ", c =>
            {
                c.BindResolver(() => "hello world")
                .To("Query", "a");
            });

            var executor = QueryExecutionBuilder
                           .New()
                           .Use(next => context =>
            {
                var queryResult          = new QueryResult();
                queryResult.Data["done"] = true;

                context.Result = queryResult;

                return(next(context));
            })
                           .Build(schema);

            // act
            IExecutionResult result = await executor.ExecuteAsync("{ a }");

            // assert
            result.MatchSnapshot();
        }
Esempio n. 2
0
        public void SchemaIsNull_ShouldThrow()
        {
            // act
            Action a = () => QueryExecutionBuilder.New().Build(null);

            // assert
            Assert.Throws <ArgumentNullException>(a);
        }
        public void UseDefaultPipeline2_OptionsNull_ArgumentNullException()
        {
            // arrange
            // act
            Action action = () => QueryExecutionBuilderExtensions
                            .UseDefaultPipeline(QueryExecutionBuilder.New(), null);

            // assert
            Assert.Throws <ArgumentNullException>(action);
        }
        public void UseField2_T_FactoryNull_ArgumentNullException()
        {
            // arrange
            // act
            Action action = () => QueryExecutionBuilderExtensions
                            .UseField <object>(QueryExecutionBuilder.New(), null);

            // assert
            Assert.Throws <ArgumentNullException>(action);
        }
        public void MapField1_T_FieldReferenceNull_ArgumentNullException()
        {
            // arrange
            // act
            Action action = () => QueryExecutionBuilderExtensions
                            .MapField <object>(
                QueryExecutionBuilder.New(),
                null);

            // assert
            Assert.Throws <ArgumentNullException>(action);
        }
        public void MapField_MiddlewareNull_ArgumentNullException()
        {
            // arrange
            // act
            Action action = () => QueryExecutionBuilderExtensions
                            .MapField(
                QueryExecutionBuilder.New(),
                new FieldReference("a", "b"),
                null);

            // assert
            Assert.Throws <ArgumentNullException>(action);
        }
        public void MapField_FieldReferenceNull_ArgumentNullException()
        {
            // arrange
            // act
            Action action = () => QueryExecutionBuilderExtensions
                            .MapField(
                QueryExecutionBuilder.New(),
                null,
                next => context => default(ValueTask));

            // assert
            Assert.Throws <ArgumentNullException>(action);
        }
        public async Task ExecuteShortHandQuery()
        {
            // arrange
            Schema schema   = CreateSchema();
            var    executer = QueryExecutionBuilder.BuildDefault(schema);
            var    request  = new QueryRequest("{ a }");

            // act
            IExecutionResult result = await executer.ExecuteAsync(request);

            // assert
            Assert.Null(result.Errors);
            result.Snapshot();
        }
Esempio n. 9
0
        public async Task ExecuteQueryWith2OperationsAndInvalidOpName_Error()
        {
            // arrange
            Schema schema   = CreateSchema();
            var    executer = QueryExecutionBuilder.BuildDefault(schema);
            var    request  = new QueryRequest(
                "query a { a } query b { a }", "c");

            // act
            IExecutionResult result = await executer.ExecuteAsync(request);

            // assert
            Assert.NotNull(result.Errors);
            result.Snapshot();
        }
Esempio n. 10
0
        public async Task ExecuteQueryWith2OperationsAndOperationName_NoErrors()
        {
            // arrange
            Schema schema   = CreateSchema();
            var    executor = QueryExecutionBuilder.BuildDefault(schema);
            var    request  = new QueryRequest(
                "query a { a } query b { a }", "a");

            // act
            IExecutionResult result = await executor.ExecuteAsync(request);

            // assert
            Assert.Empty(result.Errors);
            result.MatchSnapshot();
        }
Esempio n. 11
0
        public async Task ExecuteFieldWithResolverResultError()
        {
            // arrange
            var variableValues =
                new Dictionary <string, IValueNode>();

            Schema schema   = CreateSchema();
            var    executer = QueryExecutionBuilder.BuildDefault(schema);
            var    request  = new QueryRequest("{ y yasync }");

            // act
            IExecutionResult result = await executer.ExecuteAsync(request);

            // assert
            Assert.NotNull(result.Errors);
            result.Snapshot();
        }
Esempio n. 12
0
        public async Task ExecuteShortHandQueryWithTracing()
        {
            // arrange
            Schema         schema   = CreateSchema();
            IQueryExecuter executer = QueryExecutionBuilder
                                      .BuildDefault(schema, new QueryExecutionOptions
            {
                EnableTracing = true
            });
            var request = new QueryRequest("{ a }");

            // act
            IExecutionResult result = await executer.ExecuteAsync(request);

            // assert
            Assert.NotEmpty(result.Extensions);
            Assert.True(result.Extensions.ContainsKey("tracing"));
        }
Esempio n. 13
0
        public async Task ExecuteShortHandQuery()
        {
            // arrange
            Schema         schema   = CreateSchema();
            IQueryExecutor executor = QueryExecutionBuilder
                                      .BuildDefault(schema);
            var request =
                QueryRequestBuilder.New()
                .SetQuery("{ a }")
                .Create();

            // act
            IExecutionResult result = await executor.ExecuteAsync(request);

            // assert
            Assert.Empty(result.Errors);
            result.MatchSnapshot();
        }
Esempio n. 14
0
        public async Task ExecuteWithMissingVariables_Error()
        {
            // arrange
            var variableValues =
                new Dictionary <string, object>();
            Schema         schema   = CreateSchema();
            IQueryExecuter executer = QueryExecutionBuilder
                                      .BuildDefault(schema);
            var request = new QueryRequest(
                "query x($a: String!) { b(a: $a) }")
            {
                VariableValues = variableValues
            };

            // act
            IExecutionResult result = await executer.ExecuteAsync(request);

            // assert
            Assert.NotNull(result.Errors);
            result.Snapshot();
        }
Esempio n. 15
0
        public async Task ExecuteFieldWithResolverResult()
        {
            // arrange
            var variableValues =
                new Dictionary <string, IValueNode>();

            Schema         schema   = CreateSchema();
            IQueryExecutor executor =
                QueryExecutionBuilder.BuildDefault(schema);
            var request =
                QueryRequestBuilder.New()
                .SetQuery("{ x xasync }")
                .Create();

            // act
            IExecutionResult result = await executor.ExecuteAsync(request);

            // assert
            Assert.Empty(result.Errors);
            result.MatchSnapshot();
        }
Esempio n. 16
0
        public async Task UseClassMiddleware()
        {
            // arrange
            var schema = Schema.Create(@"
                type Query { a: String }
                ", c =>
            {
                c.BindResolver(() => "hello world")
                .To("Query", "a");
            });

            IQueryExecutor executor = QueryExecutionBuilder
                                      .New()
                                      .Use <TestMiddleware>()
                                      .Build(schema);

            // act
            IExecutionResult result = await executor.ExecuteAsync("{ a }");

            // assert
            result.MatchSnapshot();
        }
        public async Task UseClassMiddlewareWithFactory()
        {
            // arrange
            var schema = Schema.Create(@"
                type Query { a: String }
                ", c =>
            {
                c.BindResolver(() => "hello world")
                .To("Query", "a");
            });

            var executer = QueryExecutionBuilder
                           .New()
                           .Use((services, next) => new TestMiddleware(next))
                           .Build(schema);

            // act
            IExecutionResult result = await executer.ExecuteAsync("{ a }");

            // assert
            result.Snapshot();
        }
Esempio n. 18
0
        public async Task ExecuteWithNonNullVariableInvalidType_Error()
        {
            // arrange
            var variableValues = new Dictionary <string, object>()
            {
                { "a", new IntValueNode(123) }
            };

            Schema schema   = CreateSchema();
            var    executor = QueryExecutionBuilder.BuildDefault(schema);
            var    request  = new QueryRequest(
                "query x($a: String!) { b(a: $a) }")
            {
                VariableValues = variableValues
            };

            // act
            IExecutionResult result = await executor.ExecuteAsync(request);

            // assert
            Assert.NotNull(result.Errors);
            result.MatchSnapshot();
        }
Esempio n. 19
0
        public async Task ExecuteWithNonNullVariableValidValue_NoErrors()
        {
            // arrange
            var variableValues =
                new Dictionary <string, object>()
            {
                { "a", new StringValueNode("123") }
            };

            Schema schema   = CreateSchema();
            var    executer = QueryExecutionBuilder.BuildDefault(schema);
            var    request  = new QueryRequest(
                "query x($a: String!) { b(a: $a) }")
            {
                VariableValues = variableValues
            };

            // act
            IExecutionResult result = await executer.ExecuteAsync(request);

            // assert
            Assert.Empty(result.Errors);
            result.Snapshot();
        }