public void Merge_Should_Merge_ProviderExtensions()
        {
            // arrange
            var provider1  = new MockProviderExtensions();
            var convention = new MockFilterConvention(x => x.AddProviderExtension(provider1));
            var provider2  = new MockProviderExtensions();
            var extension  = new FilterConventionExtension(x => x.AddProviderExtension(provider2));
            var context    = new ConventionContext(
                "Scope",
                new ServiceCollection().BuildServiceProvider(),
                DescriptorContext.Create());

            convention.Initialize(context);
            extension.Initialize(context);

            // act
            extension.Merge(context, convention);

            // assert
            Assert.NotNull(convention.DefinitionAccessor);
            Assert.Collection(
                convention.DefinitionAccessor !.ProviderExtensions,
                x => Assert.Equal(provider1, x),
                x => Assert.Equal(provider2, x));
        }
        public void Merge_Should_DeepMerge_Configurations()
        {
            // arrange
            var convention = new MockFilterConvention(
                x => x.Configure <ComparableOperationFilterInput <int> >(d => d.Name("Foo")));
            var extension = new FilterConventionExtension(
                x => x.Configure <ComparableOperationFilterInput <int> >(d => d.Name("Bar")));
            var context = new ConventionContext(
                "Scope",
                new ServiceCollection().BuildServiceProvider(),
                DescriptorContext.Create());

            convention.Initialize(context);
            extension.Initialize(context);

            // act
            extension.Merge(context, convention);

            // assert
            Assert.NotNull(convention.DefinitionAccessor);
            List <ConfigureFilterInputType> configuration =
                Assert.Single(convention.DefinitionAccessor !.Configurations.Values) !;

            Assert.Equal(2, configuration.Count);
        }
    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, TestOperationFilterInputType>();
            descriptor.Provider(provider);
        });

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

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

        //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 Merge_Should_Merge_Provider()
        {
            // arrange
            var convention = new MockFilterConvention(x => x.Provider <QueryableFilterProvider>());
            var extension  = new FilterConventionExtension(x => x.Provider <MockProvider>());
            var context    = new ConventionContext(
                "Scope",
                new ServiceCollection().BuildServiceProvider(),
                DescriptorContext.Create());

            convention.Initialize(context);
            extension.Initialize(context);

            // act
            extension.Merge(context, convention);

            // assert
            Assert.Equal(typeof(MockProvider), convention.DefinitionAccessor?.Provider);
        }
        public void Merge_Should_Merge_ArgumentName()
        {
            // arrange
            var convention = new MockFilterConvention(x => x.ArgumentName("Foo"));
            var extension  = new FilterConventionExtension(x => x.ArgumentName("Bar"));
            var context    = new ConventionContext(
                "Scope",
                new ServiceCollection().BuildServiceProvider(),
                DescriptorContext.Create());

            convention.Initialize(context);
            extension.Initialize(context);

            // act
            extension.Merge(context, convention);

            // assert
            Assert.Equal("Bar", convention.DefinitionAccessor?.ArgumentName);
        }
        public void Merge_Should_Merge_Bindings()
        {
            // arrange
            var convention = new MockFilterConvention(
                x => x.BindRuntimeType <int, ComparableOperationFilterInput <int> >());
            var extension = new FilterConventionExtension(
                x => x.BindRuntimeType <double, ComparableOperationFilterInput <double> >());
            var context = new ConventionContext(
                "Scope",
                new ServiceCollection().BuildServiceProvider(),
                DescriptorContext.Create());

            convention.Initialize(context);
            extension.Initialize(context);

            // act
            extension.Merge(context, convention);

            // assert
            Assert.NotNull(convention.DefinitionAccessor);
            Assert.Contains(typeof(int), convention.DefinitionAccessor !.Bindings);
            Assert.Contains(typeof(double), convention.DefinitionAccessor !.Bindings);
        }