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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }