Пример #1
0
        public void SortConvention_Should_Fail_When_FieldHandlerIsNotRegistered()
        {
            // arrange
            var provider = new QueryableSortProvider(
                descriptor =>
            {
                descriptor.AddOperationHandler <QueryableAscendingSortOperationHandler>();
            });

            var convention = new SortConvention(
                descriptor =>
            {
                descriptor.Operation(DefaultSortOperations.Ascending).Name("asc");
                descriptor.BindRuntimeType <string, TestEnumType>();
                descriptor.Provider(provider);
            });

            var type = new FooSortType();

            //act
            SchemaException?error =
                Assert.Throws <SchemaException>(() => CreateSchemaWith(type, convention));

            Assert.Single(error.Errors);
            error.Errors[0].Message.MatchSnapshot();
        }
Пример #2
0
        public void SortConvention_Should_Work_With_ExtensionsType()
        {
            // arrange
            var provider = new QueryableSortProvider(
                descriptor =>
            {
                descriptor.AddOperationHandler <QueryableAscendingSortOperationHandler>();
                descriptor.AddFieldHandler <QueryableDefaultSortFieldHandler>();
            });

            var convention = new SortConvention(
                descriptor =>
            {
                descriptor.BindRuntimeType <string, TestEnumType>();
                descriptor.Provider(provider);
            });

            IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral("{ bar: ASC}");
            var        type  = new FooSortType();

            //act
            CreateSchemaWithTypes(
                type,
                convention,
                typeof(MockSortExtensionConvention));
            var executor = new ExecutorBuilder(type);

            Func <Foo[], Foo[]> func = executor.Build <Foo>(value);

            // assert
            var a = new[] { new Foo {
                                Bar = "a"
                            }, new Foo {
                                Bar = "b"
                            }, new Foo {
                                Bar = "c"
                            } };

            Assert.Collection(
                func(a),
                x => Assert.Equal("a", x.Bar),
                x => Assert.Equal("b", x.Bar),
                x => Assert.Equal("c", x.Bar));

            var b = new[] { new Foo {
                                Bar = "c"
                            }, new Foo {
                                Bar = "b"
                            }, new Foo {
                                Bar = "a"
                            } };

            Assert.Collection(
                func(b),
                x => Assert.Equal("a", x.Bar),
                x => Assert.Equal("b", x.Bar),
                x => Assert.Equal("c", x.Bar));
        }
        protected ISchema CreateSchemaWith(ISortInputType type, SortConvention convention)
        {
            ISchemaBuilder builder = SchemaBuilder.New()
                                     .AddConvention <ISortConvention>(convention)
                                     .AddSorting()
                                     .AddQueryType(
                c =>
                c.Name("Query")
                .Field("foo")
                .Type <StringType>()
                .Resolver("bar"))
                                     .AddType(type);

            return(builder.Create());
        }
Пример #4
0
        protected ISchema CreateSchemaWith(
            ISortInputType type,
            SortConvention convention,
            params SortConventionExtension[] extensions)
        {
            ISchemaBuilder builder = SchemaBuilder.New()
                                     .AddConvention <ISortConvention>(convention)
                                     .AddSorting()
                                     .AddQueryType(
                c =>
                c.Name("Query")
                .Field("foo")
                .Type <StringType>()
                .Resolve("bar"))
                                     .AddType(type);

            foreach (var extension in extensions)
            {
                builder.AddConvention <ISortConvention>(extension);
            }

            return(builder.Create());
        }