Example #1
0
            public void Point_Within_Line()
            {
                // arrange
                IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
                    @"{
                        bar: {
                            within: {
                                geometry: {
                                    type: LineString
                                    coordinates: [[10, 20], [20, 20], [30, 20]]
                                }
                            }
                        }
                    }");
                ExecutorBuilder tester = CreateProviderTester(new FilterInputType <Foo>());

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

                // assert
                var a = new Foo
                {
                    Bar = new Point(20, 20)
                };

                Assert.True(func(a));

                var b = new Foo
                {
                    Bar = new Point(20, 30)
                };

                Assert.False(func(b));
            }
Example #2
0
            public void Line_to_Line()
            {
                // arrange
                IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
                    @"{
                        bar: {
                            distance: {
                                geometry: {
                                    type: LineString
                                    coordinates: [[0, 1], [1, 1], [2, 1]]
                                }
                                eq: 1
                            }
                        }
                    }");
                ExecutorBuilder tester = CreateProviderTester(new FilterInputType <Foo>());

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

                // assert
                var a = new Foo
                {
                    Bar = new LineString(new[]
                    {
                        new Coordinate(0, 0),
                        new Coordinate(1, 0)
                    })
                };

                Assert.True(func(a));
            }
            public void Polygon_Contains_Buffered_Point()
            {
                // arrange
                IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
                    @"{
                        bar: {
                            contains: {
                                geometry: {
                                    type: Point
                                    coordinates: [3, 3]
                                }
                                buffer: 2
                                eq: true
                            }
                        }
                    }");

                ExecutorBuilder tester = CreateProviderTester(new FilterInputType <Foo>());

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

                // assert
                var a = new Foo
                {
                    Bar = new Polygon(new LinearRing(new []
                    {
                        new Coordinate(0, 0),
                        new Coordinate(0, 6),
                        new Coordinate(6, 6),
                        new Coordinate(6, 0),
                        new Coordinate(0, 0)
                    }))
                };

                Assert.True(func(a), "polygon a does not contain the buffered point");

                var b = new Foo
                {
                    Bar = new Polygon(new LinearRing(new[]
                    {
                        new Coordinate(0, 0),
                        new Coordinate(0, 6),
                        new Coordinate(6, 6),
                        new Coordinate(4, 4),
                        new Coordinate(6, 0),
                        new Coordinate(0, 0)
                    }))
                };

                Assert.False(func(b), "polygon c contains the buffered point");
            }
            public void Polygon_Within_Buffered_Point()
            {
                // arrange
                IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
                    @"{
                        bar: {
                            within: {
                                geometry: {
                                    type: Point
                                    coordinates: [3, 3]
                                }
                                buffer: 5
                                eq: true
                            }
                        }
                    }");

                ExecutorBuilder tester = CreateProviderTester(new FilterInputType <Foo>());

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

                // assert
                var a = new Foo
                {
                    Bar = new Polygon(new LinearRing(new[]
                    {
                        new Coordinate(0, 0),
                        new Coordinate(0, 2),
                        new Coordinate(2, 2),
                        new Coordinate(2, 0),
                        new Coordinate(0, 0)
                    }))
                };

                Assert.True(func(a));

                var b = new Foo
                {
                    Bar = new Polygon(new LinearRing(new[]
                    {
                        new Coordinate(0, 0),
                        new Coordinate(0, 9),
                        new Coordinate(9, 9),
                        new Coordinate(3, 3),
                        new Coordinate(9, 0),
                        new Coordinate(0, 0)
                    }))
                };

                Assert.False(func(b));
            }
            public void Poly_and_Poly()
            {
                IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
                    @"{
                        bar: {
                            overlaps: {
                                geometry: {
                                    type: Polygon
                                    coordinates: [[1, 1], [3, 1], [2, 0], [1, 1]]
                                }
                                eq: true
                            }
                        }
                    }");
                ExecutorBuilder tester = CreateProviderTester(new FilterInputType <Foo>());

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

                // assert
                var a = new Foo
                {
                    Bar = new Polygon(new LinearRing(new[]
                    {
                        new Coordinate(0, 0),
                        new Coordinate(1, 2),
                        new Coordinate(2, 0),
                        new Coordinate(0, 0)
                    }))
                };

                Assert.True(func(a));

                var b = new Foo
                {
                    Bar = new Polygon(new LinearRing(new[]
                    {
                        new Coordinate(0, 0),
                        new Coordinate(1, -2),
                        new Coordinate(2, -1),
                        new Coordinate(0, 0)
                    }))
                };

                Assert.False(func(b));
            }
            public void Line_Contains_Point()
            {
                // arrange
                IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
                    @"{
                        bar: {
                            contains: {
                                geometry: {
                                    type: Point
                                    coordinates: [20, 20]
                                }
                                eq: true
                            }
                        }
                    }");
                ExecutorBuilder tester = CreateProviderTester(new FilterInputType <Foo>());

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

                // assert
                var a = new Foo
                {
                    Bar = new LineString(new[]
                    {
                        new Coordinate(10, 20),
                        new Coordinate(20, 20),
                        new Coordinate(30, 20)
                    })
                };

                Assert.True(func(a));

                var b = new Foo
                {
                    Bar = new LineString(new[]
                    {
                        new Coordinate(10, 10),
                        new Coordinate(20, 10),
                        new Coordinate(30, 10)
                    })
                };

                Assert.False(func(b));
            }