예제 #1
0
        public void FilterConvention_Should_Fail_When_NoMatchingBindingWasFound()
        {
            // arrange
            var provider = new QueryableFilterProvider(
                descriptor =>
            {
                descriptor.AddFieldHandler <QueryableStringEqualsHandler>();
                descriptor.AddFieldHandler <QueryableDefaultFieldHandler>();
            });

            var convention = new FilterConvention(
                descriptor =>
            {
                descriptor.Operation(DefaultOperations.Equals).Name("eq");
                descriptor.Provider(provider);
            });

            var type = new FooFilterType();

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

            Assert.Single(error.Errors);
#if NETCOREAPP2_1
            error.Errors[0].Message.MatchSnapshot(new SnapshotNameExtension("NETCOREAPP2_1"));
#else
            error.Errors[0].Message.MatchSnapshot();
#endif
        }
예제 #2
0
        public void FilterConvention_Should_Fail_When_FieldHandlerIsNotRegistered()
        {
            // arrange
            var provider = new QueryableFilterProvider(
                descriptor =>
            {
                descriptor.AddFieldHandler <QueryableStringEqualsHandler>();
            });

            var convention = new FilterConvention(
                descriptor =>
            {
                descriptor.Operation(DefaultOperations.Equals).Name("eq");
                descriptor.BindRuntimeType <string, TestOperationFilterType>();
                descriptor.Provider(provider);
            });

            var type = new FooFilterType();

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

            Assert.Single(error.Errors);
            error.Errors[0].Message.MatchSnapshot();
        }
예제 #3
0
        public void FilterConvention_Should_Fail_When_OperationsIsNotNamed()
        {
            // arrange
            var provider = new QueryableFilterProvider(
                descriptor =>
            {
                descriptor.AddFieldHandler <QueryableStringEqualsHandler>();
                descriptor.AddFieldHandler <QueryableDefaultFieldHandler>();
            });

            var convention = new FilterConvention(
                descriptor =>
            {
                descriptor.Operation(DefaultFilterOperations.Equals).Description("eq");
                descriptor.BindRuntimeType <string, TestOperationFilterInputType>();
                descriptor.Provider(provider);
            });

            var type = new FooFilterInput();

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

            Assert.Equal("Name", error.ParamName);
        }
예제 #4
0
        public void FilterConvention_Should_Fail_When_OperationsIsNotNamed()
        {
            // arrange
            var provider = new QueryableFilterProvider(
                descriptor =>
            {
                descriptor.AddFieldHandler <QueryableStringEqualsHandler>();
                descriptor.AddFieldHandler <QueryableDefaultFieldHandler>();
            });

            var convention = new FilterConvention(
                descriptor =>
            {
                descriptor.Operation(DefaultOperations.Equals).Description("eq");
                descriptor.BindRuntimeType <string, TestOperationFilterType>();
                descriptor.Provider(provider);
            });

            var type = new FooFilterType();

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

#if NETCOREAPP2_1
            error.Message.MatchSnapshot(new SnapshotNameExtension("NETCOREAPP2_1"));
#else
            error.Message.MatchSnapshot();
#endif
        }
예제 #5
0
        //TODO: Replace with named conventions!
        internal static IFilterConvention TemporaryInitializer()
        {
            var convention = new FilterConvention(x => x.UseDefault());

            convention.Initialize(new ConventionContext(null, null));
            return(convention);
        }
예제 #6
0
        public void FilterConvention_Should_Work_With_Extensions()
        {
            // arrange
            var provider = new QueryableFilterProvider(
                descriptor =>
            {
                descriptor.AddFieldHandler <QueryableStringEqualsHandler>();
                descriptor.AddFieldHandler <QueryableDefaultFieldHandler>();
            });

            var convention = new FilterConvention(
                descriptor =>
            {
            });

            var extension1 = new FilterConventionExtension(
                descriptor =>
            {
                descriptor.BindRuntimeType <string, TestOperationFilterType>();
                descriptor.Provider(provider);
            });

            var extension2 = new FilterConventionExtension(
                descriptor =>
            {
                descriptor.Operation(DefaultOperations.Equals).Name("eq");
            });

            IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral("{ bar: { eq:\"a\" }}");
            var        type  = new FooFilterType();

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

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

            // assert
            var a = new Foo {
                Bar = "a"
            };

            Assert.True(func(a));

            var b = new Foo {
                Bar = "b"
            };

            Assert.False(func(b));
        }
        public void Create_Implicit_Operation()
        {
            // arrange
            var convention = new FilterConvention(x => x.UseMock().Operation(155).Name("Method155"));

            // act
            ISchema schema = SchemaBuilder.New()
                             .AddQueryType <Query>()
                             .AddConvention <IFilterConvention>(convention)
                             .AddFiltering()
                             .Create();

            // assert
            schema.ToString().MatchSnapshot();
        }
예제 #8
0
        protected ISchema CreateSchemaWith(IFilterInputType type, FilterConvention convention)
        {
            ISchemaBuilder builder = SchemaBuilder.New()
                                     .AddConvention <IFilterConvention>(convention)
                                     .AddFiltering()
                                     .AddQueryType(
                c =>
                c.Name("Query")
                .Field("foo")
                .Type <StringType>()
                .Resolver("bar"))
                                     .AddType(type);

            return(builder.Create());
        }
예제 #9
0
        public void FilterConvention_Should_Fail_When_NoProviderWasRegistered()
        {
            // arrange
            var convention = new FilterConvention(
                descriptor =>
            {
                descriptor.Operation(DefaultFilterOperations.Equals).Name("eq");
                descriptor.BindRuntimeType <string, TestOperationFilterInputType>();
            });

            var type = new FooFilterInput();

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

            Assert.Single(error.Errors);
            error.Errors[0].Message.MatchSnapshot();
        }
        public void Create_Explicit_Operation()
        {
            // arrange
            var convention = new FilterConvention(
                x =>
            {
                x.UseMock();
                x.Operation(155).Name("SimpleMethod");
                x.Operation(156).Name("ComplexMethod");
            });

            // act
            ISchema schema = SchemaBuilder.New()
                             .AddQueryType <QueryExplicit>()
                             .AddConvention <IFilterConvention>(convention)
                             .AddFiltering()
                             .Create();

            // assert
            schema.ToString().MatchSnapshot();
        }
예제 #11
0
        protected ISchema CreateSchemaWith(
            IFilterInputType type,
            FilterConvention convention,
            params FilterConventionExtension[] extensions)
        {
            ISchemaBuilder builder = SchemaBuilder.New()
                                     .AddConvention <IFilterConvention>(convention)
                                     .AddFiltering()
                                     .AddQueryType(
                c =>
                c.Name("Query")
                .Field("foo")
                .Type <StringType>()
                .Resolver("bar"))
                                     .AddType(type);

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

            return(builder.Create());
        }
예제 #12
0
        public async Task FilterConvention_Should_NotAddOr()
        {
            // arrange
            var convention = new FilterConvention(
                descriptor =>
            {
                descriptor.AddDefaults();
                descriptor.AllowOr(false);
            });

            IRequestExecutorBuilder builder = new ServiceCollection()
                                              .AddGraphQL()
                                              .AddConvention <IFilterConvention>(convention)
                                              .AddFiltering()
                                              .AddQueryType(
                x => x.Name("Query").Field("foos").UseFiltering().Resolve(new List <Foo>()));

            //act
            ISchema schema = await builder.BuildSchemaAsync();

            // assert
            schema.ToString().MatchSnapshot();
        }
예제 #13
0
        public async Task FilterConvention_Should_UseBoundFilterType()
        {
            // arrange
            var convention = new FilterConvention(
                descriptor =>
            {
                descriptor.AddDefaults();
                descriptor.BindRuntimeType <string, TestOperationFilterInputType>();
                descriptor.BindRuntimeType <Foo, CustomFooFilterInput>();
            });

            IRequestExecutorBuilder builder = new ServiceCollection()
                                              .AddGraphQL()
                                              .AddConvention <IFilterConvention>(convention)
                                              .AddFiltering()
                                              .AddQueryType(
                x => x.Name("Query").Field("foos").UseFiltering().Resolve(new List <Foo>()));

            //act
            ISchema schema = await builder.BuildSchemaAsync();

            // assert
            schema.ToString().MatchSnapshot();
        }