11using FluentAssertions ;
22using NUnit . Framework ;
33using System . Collections . Generic ;
4+ using System . Linq ;
45
56namespace Nest . Tests . Unit . QueryParsers . Filter
67{
@@ -9,7 +10,7 @@ public class GeoShapeFilterTests : ParseFilterTestsBase
910 {
1011 [ Test ]
1112 [ TestCase ( "cacheName" , "cacheKey" , true ) ]
12- public void GeoShape_Deserializes ( string cacheName , string cacheKey , bool cache )
13+ public void GeoShapeEnvelope_Deserializes ( string cacheName , string cacheKey , bool cache )
1314 {
1415 var geoBaseShapeFilter = this . SerializeThenDeserialize ( cacheName , cacheKey , cache ,
1516 f => f . GeoShape ,
@@ -18,12 +19,195 @@ public void GeoShape_Deserializes(string cacheName, string cacheKey, bool cache)
1819 )
1920 ) ;
2021
21- geoBaseShapeFilter . Field . Should ( ) . Be ( "origin" ) ;
22- var geoShapeFilter = geoBaseShapeFilter as IGeoShapeEnvelopeFilter ;
23- geoShapeFilter . Should ( ) . NotBeNull ( ) ;
24- geoShapeFilter . Shape . Should ( ) . NotBeNull ( ) ;
25- geoShapeFilter . Shape . Type . Should ( ) . Be ( "envelope" ) ;
22+ var filter = geoBaseShapeFilter as IGeoShapeEnvelopeFilter ;
23+ filter . Should ( ) . NotBeNull ( ) ;
24+ filter . Field . Should ( ) . Be ( "origin" ) ;
25+ filter . Should ( ) . NotBeNull ( ) ;
26+ filter . Shape . Should ( ) . NotBeNull ( ) ;
27+ filter . Shape . Type . Should ( ) . Be ( "envelope" ) ;
28+ }
29+
30+ [ Test ]
31+ [ TestCase ( "cacheName" , "cacheKey" , true ) ]
32+ public void GeoShapeCircle_Deserializes ( string cacheName , string cacheKey , bool cache )
33+ {
34+ var coordinates = new [ ] { - 45.0 , 45.0 } ;
35+
36+ var geoBaseShapeFilter = this . SerializeThenDeserialize ( cacheName , cacheKey , cache ,
37+ f => f . GeoShape ,
38+ f => f . GeoShapeCircle ( p => p . Origin , d => d
39+ . Coordinates ( coordinates )
40+ . Radius ( "100m" )
41+ )
42+ ) ;
43+
44+ var filter = geoBaseShapeFilter as IGeoShapeCircleFilter ;
45+ filter . Should ( ) . NotBeNull ( ) ;
46+ filter . Field . Should ( ) . Be ( "origin" ) ;
47+ filter . Should ( ) . NotBeNull ( ) ;
48+ filter . Shape . Should ( ) . NotBeNull ( ) ;
49+ filter . Shape . Type . Should ( ) . Be ( "circle" ) ;
50+ filter . Shape . Radius . Should ( ) . Be ( "100m" ) ;
51+ filter . Shape . Coordinates . Should ( ) . BeEquivalentTo ( coordinates ) ;
52+ }
53+
54+ [ Test ]
55+ [ TestCase ( "cacheName" , "cacheKey" , true ) ]
56+ public void GeoShapeLineString_Deserializes ( string cacheName , string cacheKey , bool cache )
57+ {
58+ var coordinates = new [ ] { new [ ] { 13.0 , 53.0 } , new [ ] { 14.0 , 52.0 } } ;
59+
60+ var geoBaseShapeFilter = this . SerializeThenDeserialize ( cacheName , cacheKey , cache ,
61+ f => f . GeoShape ,
62+ f => f . GeoShapeLineString ( p => p . Origin , d => d
63+ . Coordinates ( coordinates )
64+ )
65+ ) ;
66+
67+ var filter = geoBaseShapeFilter as IGeoShapeLineStringFilter ;
68+ filter . Should ( ) . NotBeNull ( ) ;
69+ filter . Field . Should ( ) . Be ( "origin" ) ;
70+ filter . Should ( ) . NotBeNull ( ) ;
71+ filter . Shape . Should ( ) . NotBeNull ( ) ;
72+ filter . Shape . Type . Should ( ) . Be ( "linestring" ) ;
73+ filter . Shape . Coordinates . SelectMany ( c => c ) . Should ( )
74+ . BeEquivalentTo ( coordinates . SelectMany ( c => c ) ) ;
75+ }
76+
77+ [ Test ]
78+ [ TestCase ( "cacheName" , "cacheKey" , true ) ]
79+ public void GeoShapeMultiLineString_Deserializes ( string cacheName , string cacheKey , bool cache )
80+ {
81+ var coordinates = new [ ]
82+ {
83+ new [ ] { new [ ] { 102.0 , 2.0 } , new [ ] { 103.0 , 2.0 } , new [ ] { 103.0 , 3.0 } , new [ ] { 102.0 , 3.0 } } ,
84+ new [ ] { new [ ] { 100.0 , 0.0 } , new [ ] { 101.0 , 0.0 } , new [ ] { 101.0 , 1.0 } , new [ ] { 100.0 , 1.0 } } ,
85+ new [ ] { new [ ] { 100.2 , 0.2 } , new [ ] { 100.8 , 0.2 } , new [ ] { 100.8 , 0.8 } , new [ ] { 100.2 , 0.8 } }
86+ } ;
87+
88+ var geoBaseShapeFilter = this . SerializeThenDeserialize ( cacheName , cacheKey , cache ,
89+ f => f . GeoShape ,
90+ f => f . GeoShapeMultiLineString ( p => p . Origin , d => d
91+ . Coordinates ( coordinates )
92+ )
93+ ) ;
94+
95+ var filter = geoBaseShapeFilter as IGeoShapeMultiLineStringFilter ;
96+ filter . Should ( ) . NotBeNull ( ) ;
97+ filter . Field . Should ( ) . Be ( "origin" ) ;
98+ filter . Should ( ) . NotBeNull ( ) ;
99+ filter . Shape . Should ( ) . NotBeNull ( ) ;
100+ filter . Shape . Type . Should ( ) . Be ( "multilinestring" ) ;
101+ filter . Shape . Coordinates . SelectMany ( c => c . SelectMany ( cc => cc ) ) . Should ( )
102+ . BeEquivalentTo ( coordinates . SelectMany ( c => c . SelectMany ( cc => cc ) ) ) ;
103+ }
104+
105+ [ Test ]
106+ [ TestCase ( "cacheName" , "cacheKey" , true ) ]
107+ public void GeoShapePoint_Deserializes ( string cacheName , string cacheKey , bool cache )
108+ {
109+ var coordinates = new [ ] { 1.0 , 2.0 } ;
110+
111+ var geoBaseShapeFilter = this . SerializeThenDeserialize ( cacheName , cacheKey , cache ,
112+ f => f . GeoShape ,
113+ f => f . GeoShapePoint ( p => p . Origin , d => d
114+ . Coordinates ( coordinates )
115+ )
116+ ) ;
117+
118+ var filter = geoBaseShapeFilter as IGeoShapePointFilter ;
119+ filter . Should ( ) . NotBeNull ( ) ;
120+ filter . Field . Should ( ) . Be ( "origin" ) ;
121+ filter . Should ( ) . NotBeNull ( ) ;
122+ filter . Shape . Should ( ) . NotBeNull ( ) ;
123+ filter . Shape . Type . Should ( ) . Be ( "point" ) ;
124+ filter . Shape . Coordinates . Should ( ) . BeEquivalentTo ( coordinates ) ;
125+ }
126+
127+ [ Test ]
128+ [ TestCase ( "cacheName" , "cacheKey" , true ) ]
129+ public void GeoShapeMultiPoint_Deserializes ( string cacheName , string cacheKey , bool cache )
130+ {
131+ var coordinates = new [ ] { new [ ] { 13.0 , 53.0 } , new [ ] { 14.0 , 52.0 } } ;
132+
133+ var geoBaseShapeFilter = this . SerializeThenDeserialize ( cacheName , cacheKey , cache ,
134+ f => f . GeoShape ,
135+ f => f . GeoShapeMultiPoint ( p => p . Origin , d => d
136+ . Coordinates ( coordinates )
137+ )
138+ ) ;
139+
140+ var filter = geoBaseShapeFilter as IGeoShapeMultiPointFilter ;
141+ filter . Should ( ) . NotBeNull ( ) ;
142+ filter . Field . Should ( ) . Be ( "origin" ) ;
143+ filter . Should ( ) . NotBeNull ( ) ;
144+ filter . Shape . Should ( ) . NotBeNull ( ) ;
145+ filter . Shape . Type . Should ( ) . Be ( "multipoint" ) ;
146+ filter . Shape . Coordinates . SelectMany ( c => c ) . Should ( )
147+ . BeEquivalentTo ( coordinates . SelectMany ( c => c ) ) ;
148+ }
149+
150+ [ Test ]
151+ [ TestCase ( "cacheName" , "cacheKey" , true ) ]
152+ public void GeoShapePolygon_Deserializes ( string cacheName , string cacheKey , bool cache )
153+ {
154+ var coordinates = new [ ]
155+ {
156+ new [ ] { new [ ] { 100.0 , 0.0 } , new [ ] { 101.0 , 0.0 } , new [ ] { 101.0 , 1.0 } , new [ ] { 100.0 , 1.0 } , new [ ] { 100.0 , 0.0 } } ,
157+ new [ ] { new [ ] { 100.2 , 0.2 } , new [ ] { 100.8 , 0.2 } , new [ ] { 100.8 , 0.8 } , new [ ] { 100.2 , 0.8 } , new [ ] { 100.2 , 0.2 } }
158+ } ;
159+
160+ var geoBaseShapeFilter = this . SerializeThenDeserialize ( cacheName , cacheKey , cache ,
161+ f => f . GeoShape ,
162+ f => f . GeoShapePolygon ( p => p . Origin , d => d
163+ . Coordinates ( coordinates )
164+ )
165+ ) ;
166+
167+ var filter = geoBaseShapeFilter as IGeoShapePolygonFilter ;
168+ filter . Should ( ) . NotBeNull ( ) ;
169+ filter . Field . Should ( ) . Be ( "origin" ) ;
170+ filter . Should ( ) . NotBeNull ( ) ;
171+ filter . Shape . Should ( ) . NotBeNull ( ) ;
172+ filter . Shape . Type . Should ( ) . Be ( "polygon" ) ;
173+ filter . Shape . Coordinates . SelectMany ( c => c . SelectMany ( cc => cc ) ) . Should ( )
174+ . BeEquivalentTo ( coordinates . SelectMany ( c => c . SelectMany ( cc => cc ) ) ) ;
175+ }
176+
177+ [ Test ]
178+ [ TestCase ( "cacheName" , "cacheKey" , true ) ]
179+ public void GeoShapeMultiPolygon_Deserializes ( string cacheName , string cacheKey , bool cache )
180+ {
181+ var coordinates = new [ ]
182+ {
183+ new [ ] {
184+ new [ ] {
185+ new [ ] { 102.0 , 2.0 } , new [ ] { 103.0 , 2.0 } , new [ ] { 103.0 , 3.0 } , new [ ] { 102.0 , 3.0 } , new [ ] { 102.0 , 2.0 }
186+ }
187+ } ,
188+ new [ ] {
189+ new [ ] {
190+ new [ ] { 100.0 , 0.0 } , new [ ] { 101.0 , 0.0 } , new [ ] { 101.0 , 1.0 } , new [ ] { 100.0 , 1.0 } , new [ ] { 100.0 , 0.0 }
191+ } ,
192+ new [ ] {
193+ new [ ] { 100.2 , 0.2 } , new [ ] { 100.8 , 0.2 } , new [ ] { 100.8 , 0.8 } , new [ ] { 100.2 , 0.8 } , new [ ] { 100.2 , 0.2 }
194+ }
195+ }
196+ } ;
197+
198+ var geoBaseShapeFilter = this . SerializeThenDeserialize ( cacheName , cacheKey , cache ,
199+ f => f . GeoShape ,
200+ f => f . GeoShapeMultiPolygon ( p => p . Origin , d => d
201+ . Coordinates ( coordinates )
202+ )
203+ ) ;
204+
205+ var filter = geoBaseShapeFilter as IGeoShapeMultiPolygonFilter ;
206+ filter . Should ( ) . NotBeNull ( ) ;
207+ filter . Field . Should ( ) . Be ( "origin" ) ;
208+ filter . Should ( ) . NotBeNull ( ) ;
209+ filter . Shape . Should ( ) . NotBeNull ( ) ;
210+ filter . Shape . Type . Should ( ) . Be ( "multipolygon" ) ;
26211 }
27-
28212 }
29213}
0 commit comments