예제 #1
0
    public void Sort_NullableStringAscWithNull(params string[] data)
    {
        IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
            "{ bar: { baz: ASC}}");
        ExecutorBuilder tester = CreateProviderTester(new FooNullableSortType <string>());

        string?[] expected = data.Append(null).OrderBy(x => x).ToArray();

        // act
        Func <FooNullable <string>[], FooNullable <string>[]> func =
            tester.Build <FooNullable <string> >(value);

        // assert
        FooNullable <string>[] inputs =
            data
            .Select(
                x => new FooNullable <string> {
            Bar = new BarNullable <string> {
                Baz = x
            }
        })
            .Prepend(new FooNullable <string> {
            Bar = null
        })
            .ToArray();
        FooNullable <string>[] sorted = func(inputs);

        for (var i = 0; i < expected.Length; i++)
        {
            Assert.Equal(expected[i], sorted[i].Bar?.Baz);
        }
    }
예제 #2
0
    public void Create_ObjectStringEqual_Expression()
    {
        // arrange
        IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
            "{ foo: { barString: { eq:\"a\" }}}");
        ExecutorBuilder tester = CreateProviderTester(new BarFilterInput());

        // act
        Func <Bar, bool> func = tester.Build <Bar>(value);

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

        Assert.True(func(a));

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

        Assert.False(func(b));
    }
예제 #3
0
    protected void Test_Asc <T>(params T[] data)
    {
        // arrange
        IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
            "{ bar: { baz: ASC}}");
        ExecutorBuilder tester = CreateProviderTester(new FooSortType <T>());

        T[] expected = data.OrderBy(x => x).ToArray();

        // act
        Func <Foo <T>[], Foo <T>[]> func = tester.Build <Foo <T> >(value);

        // assert
        Foo <T>[] inputs = data.Select(x => new Foo <T> {
            Bar = new Bar <T> {
                Baz = x
            }
        }).ToArray();
        Foo <T>[] sorted = func(inputs);

        for (var i = 0; i < expected.Length; i++)
        {
            Assert.Equal(expected[i], sorted[i].Bar.Baz);
        }
    }
예제 #4
0
    public void Create_Interface_FilterExpression()
    {
        // arrange
        IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
            "{ test: {prop: { eq: \"a\"}}}");
        ExecutorBuilder tester = CreateProviderTester(new FilterInputType <BarInterface>());

        // act
        Func <BarInterface, bool> func = tester.Build <BarInterface>(value);

        // assert
        var a = new BarInterface
        {
            Test = new InterfaceImpl1
            {
                Prop = "a"
            }
        };

        Assert.True(func(a));

        var b = new BarInterface
        {
            Test = new InterfaceImpl1
            {
                Prop = "b"
            }
        };

        Assert.False(func(b));
    }
        /// <summary>
        ///
        /// </summary>
        /// <param name="options"></param>
        /// <param name="parser"></param>
        /// <param name="compileBuilder"></param>
        /// <param name="typeGuesser"></param>
        /// <param name="executorBuilder"></param>
        /// <param name="scopeProvider"></param>
        /// <param name="cache"></param>
        /// <param name="resourceLoader"></param>
        public DefaultHostEnvironment(IOptions options   = null
                                      , TagParser parser = null
                                      , CompileBuilder compileBuilder   = null
                                      , TypeGuesser typeGuesser         = null
                                      , ExecutorBuilder executorBuilder = null
                                      , IScopeProvider scopeProvider    = null
                                      , ICache cache = null
                                      , IResourceLoader resourceLoader = null)
        {
            this.Results             = new ResultCollection <IResult>();
            this.EnvironmentVariable = new Dictionary <string, string>(System.StringComparer.OrdinalIgnoreCase);
            this.Options             = options ?? new RuntimeOptions();
            this.RootPath            = System.IO.Directory.GetCurrentDirectory();
            this.Parser          = parser ?? new TagParser();
            this.Builder         = compileBuilder ?? new CompileBuilder();
            this.Guesser         = typeGuesser ?? new TypeGuesser();
            this.ExecutorBuilder = executorBuilder ?? new ExecutorBuilder();
            this.ScopeProvider   = scopeProvider ?? new DefaultScopeProvider();
            this.Cache           = cache ?? new MemoryCache();
            this.Loader          = resourceLoader ?? new FileLoader();
            this.ApplicationName = Guid.NewGuid().ToString("N");
            this.EnvironmentName =
#if DEBUG
                "DEBUG"
#else
                "RELEASE"
#endif
            ;
            if (Options.Data == null &&
                ScopeProvider != null)
            {
                Options.Data = ScopeProvider.CreateScope();
            }
        }
예제 #6
0
    public void Create_ObjectNullableShortEqual_Expression()
    {
        // arrange
        IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
            "{ foo: { barShort: { eq: 12 }}}");
        ExecutorBuilder tester = CreateProviderTester(new BarNullableFilterInput());

        // act
        Func <BarNullable, bool> func = tester.Build <BarNullable>(value);

        // assert
        var a = new BarNullable {
            Foo = new FooNullable {
                BarShort = 12
            }
        };

        Assert.True(func(a));

        var b = new BarNullable {
            Foo = new FooNullable {
                BarShort = 13
            }
        };

        Assert.False(func(b));

        var c = new BarNullable {
            Foo = new FooNullable {
                BarShort = null
            }
        };

        Assert.False(func(c));
    }
예제 #7
0
    public void Create_MethodSimple_Expression()
    {
        // arrange
        IValueNode      value  = Syntax.ParseValueLiteral("{ simple: { eq:\"a\" }}");
        ExecutorBuilder tester = CreateProviderTester(
            new FooFilterInput(),
            new FilterConvention(
                x =>
        {
            x.Operation(155).Name("simple");
            x.Operation(156).Name("complex");
            x.AddDefaults();
            x.Provider(
                new QueryableFilterProvider(
                    p => p.AddFieldHandler <QueryableSimpleMethodTest>()
                    .AddFieldHandler <QueryableComplexMethodTest>()
                    .AddDefaultFieldHandlers()));
        }));

        // act
        Func <Foo, bool> func = tester.Build <Foo>(value);

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

        Assert.True(func(a));

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

        Assert.False(func(b));
    }
예제 #8
0
    public void Create_ScalarArrayAnyStringEqual_Expression()
    {
        // arrange
        IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
            "{ foo: { scalarArray: {any: true}}}");
        ExecutorBuilder tester = CreateProviderTester(new BarFilterInput());

        // act
        Func <Bar, bool> func = tester.Build <Bar>(value);

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

        Assert.True(func(a));

        var b = new Bar {
            Foo = new Foo {
                ScalarArray = new string[0]
            }
        };

        Assert.False(func(b));

        var c = new Bar {
            Foo = new Foo {
                ScalarArray = null
            }
        };

        Assert.False(func(c));
    }
예제 #9
0
    public void Create_ObjectShortIn_Expression()
    {
        // arrange
        IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
            "{ foo: { barShort: { in: [13, 14] }}}");
        ExecutorBuilder tester = CreateProviderTester(new BarFilterInput());

        // act
        Func <Bar, bool> func = tester.Build <Bar>(value);

        // assert
        var a = new Bar {
            Foo = new Foo {
                BarShort = 13
            }
        };

        Assert.True(func(a));

        var b = new Bar {
            Foo = new Foo {
                BarShort = 12
            }
        };

        Assert.False(func(b));
    }
예제 #10
0
    public void Sort_Interface_BooleanAsc(params bool[] dataObject)
    {
        IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
            "{ test: { prop: ASC}}");
        ExecutorBuilder tester = CreateProviderTester(new SortInputType <BarInterface>());

        bool[] expected = dataObject.OrderBy(x => x).ToArray();

        // act
        Func <BarInterface[], BarInterface[]> func = tester.Build <BarInterface>(value);

        // assert
        BarInterface[] inputs = dataObject
                                .Select(x => new BarInterface {
            Test = new InterfaceImpl1 {
                Prop = x
            }
        })
                                .ToArray();
        BarInterface[] sorted = func(inputs);

        for (var i = 0; i < expected.Length; i++)
        {
            Assert.Equal(expected[i], sorted[i].Test.Prop);
        }
    }
예제 #11
0
    public void Create_ObjectNullableEnumIn_Expression()
    {
        // arrange
        IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
            "{ foo: { barEnum: { in: [BAZ, QUX] }}}");
        ExecutorBuilder tester = CreateProviderTester(new BarNullableFilterInput());

        // act
        Func <BarNullable, bool> func = tester.Build <BarNullable>(value);

        // assert
        var a = new BarNullable {
            Foo = new FooNullable {
                BarEnum = BarEnum.BAZ
            }
        };

        Assert.True(func(a));

        var b = new BarNullable {
            Foo = new FooNullable {
                BarEnum = BarEnum.BAR
            }
        };

        Assert.False(func(b));

        var c = new BarNullable {
            Foo = new FooNullable {
                BarEnum = null
            }
        };

        Assert.False(func(c));
    }
예제 #12
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));
    }
예제 #13
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));
        }
예제 #14
0
    public void Create_ArrayObjectNestedArraySomeStringEqual_Expression()
    {
        // arrange
        IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
            "{ foo: { objectArray: {some: { foo: {scalarArray: {some: { eq: \"a\" }}}}}}}");
        ExecutorBuilder tester = CreateProviderTester(new BarFilterInput());

        // act
        Func <Bar, bool> func = tester.Build <Bar>(value);

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

        Assert.True(func(a));

        var b = new Bar
        {
            Foo = new Foo
            {
                ObjectArray = new Bar[] {
                    new Bar {
                        Foo = new Foo {
                            ScalarArray = new[] { "c", "d", "b" }
                        }
                    }
                }
            }
        };

        Assert.False(func(b));
    }
    public void Create_ArraySomeStringEqual_Multiple()
    {
        // arrange
        IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
            "{ bar: {some: { eq: \"a\" }} otherProperty: {eq:null}}");
        ExecutorBuilder tester = CreateProviderTester(new FooSimpleFilterInput());

        // act
        Func <FooSimple, bool> func = tester.Build <FooSimple>(value);

        // assert
        var a = new FooSimple {
            Bar = new[] { "c", "d", "a" }
        };

        Assert.True(func(a));

        var b = new FooSimple {
            Bar = new[] { "c", "d", "b" }
        };

        Assert.False(func(b));
    }
예제 #16
0
    public void Create_MethodComplex_Expression()
    {
        // arrange
        ExecutorBuilder tester = CreateProviderTester(
            new FooFilterInput(),
            new FilterConvention(
                x =>
        {
            x.Operation(155).Name("simple");
            x.Operation(156).Name("complex");
            x.AddDefaults();
            x.Provider(
                new QueryableFilterProvider(
                    p => p.AddFieldHandler <QueryableSimpleMethodTest>()
                    .AddFieldHandler <QueryableComplexMethodTest>()
                    .AddDefaultFieldHandlers()));
        }));

        IValueNode valueTrue = Utf8GraphQLParser.Syntax.ParseValueLiteral(
            "{ complex: {parameter:\"a\", eq:\"a\" }}");

        IValueNode valueFalse = Utf8GraphQLParser.Syntax.ParseValueLiteral(
            "{ complex: {parameter:\"a\", eq:\"b\" }}");
        // act
        Func <Foo, bool> funcTrue  = tester.Build <Foo>(valueTrue);
        Func <Foo, bool> funcFalse = tester.Build <Foo>(valueFalse);

        // assert
        var a = new Foo();

        Assert.True(funcTrue(a));

        var b = new Foo();

        Assert.False(funcFalse(b));
    }
예제 #17
0
    public void Sort_NullableStringDesc(params string[] data)
    {
        IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
            "{ bar: DESC}");
        ExecutorBuilder tester = CreateProviderTester(new FooNullableSortType <string>());

        string[] expected = data.OrderByDescending(x => x).ToArray();

        // act
        Func <FooNullable <string>[], FooNullable <string>[]> func =
            tester.Build <FooNullable <string> >(value);

        // assert
        FooNullable <string>[] inputs =
            data.Select(x => new FooNullable <string> {
            Bar = x
        }).ToArray();
        FooNullable <string>[] sorted = func(inputs);

        for (var i = 0; i < expected.Length; i++)
        {
            Assert.Equal(expected[i], sorted[i].Bar);
        }
    }
    public void Create_ArraySomeObjectEqual_Multiple()
    {
        // arrange
        IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
            "{ fooNested: {some: {bar: { eq: \"a\" }}} otherProperty: {eq:null}}");
        ExecutorBuilder tester = CreateProviderTester(new FooFilterInput());

        // act
        Func <Foo, bool>?func = tester.Build <Foo>(value);

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

        Assert.True(func(a));

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

        Assert.True(func(b));

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

        Assert.True(func(c));

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

        Assert.False(func(d));

        var e = new Foo
        {
            FooNested = new[]
            {
                null,
                new FooNested {
                    Bar = null
                },
                new FooNested {
                    Bar = "d"
                },
                new FooNested {
                    Bar = "b"
                }
            }
        };

        Assert.False(func(e));

        var f = new Foo
        {
            OtherProperty = "ShouldBeNull",
            FooNested     = new[]
            {
                new FooNested {
                    Bar = "c"
                },
                new FooNested {
                    Bar = "a"
                },
                new FooNested {
                    Bar = "a"
                }
            }
        };

        Assert.False(func(f));
    }