Example #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();
        }
Example #2
0
    public void SortConvention_Should_Work_With_ProviderExtensionsType()
    {
        // arrange
        var provider = new QueryableSortProvider(
            descriptor =>
        {
            descriptor.AddFieldHandler <QueryableDefaultSortFieldHandler>();
        });

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

        var extension1 = new SortConventionExtension(
            descriptor =>
        {
            descriptor.Operation(DefaultSortOperations.Ascending).Name("ASC");
            descriptor.AddProviderExtension <MockSortProviderExtensionConvention>();
        });

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

        //act
        CreateSchemaWith(type, convention, extension1);
        var executor = new ExecutorBuilder(type);

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

        // assert
        Foo[]? 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));

        Foo[]? 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));
    }