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

            var executer = QueryExecutionBuilder
                           .New()
                           .Use(next => context =>
            {
                var dict     = new OrderedDictionary();
                dict["done"] = true;

                context.Result = new QueryResult(dict);

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

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

            // assert
            result.Snapshot();
        }
Ejemplo n.º 2
0
        public async Task UseDelegateMiddleware()
        {
            // arrange
            var schema = Schema.Create(@"
                type Query { a: String }
                ", c =>
            {
                c.BindResolver(() => "hello world")
                .To("Query", "a");
            });

            IQueryExecutor executor = QueryExecutionBuilder
                                      .New()
                                      .Use(next => context =>
            {
                var queryResult =
                    QueryResultBuilder.New()
                    .SetData(new Dictionary <string, object> {
                    { "done", true }
                })
                    .Create();
                context.Result = queryResult;

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

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

            // assert
            result.MatchSnapshot();
        }
Ejemplo n.º 3
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 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();
        }
Ejemplo n.º 10
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();
        }