@@ -92,6 +92,20 @@ public void Should_translate_a_single_top_level_field_with_an_operation()
9292 result . Value . Should ( ) . Be ( "jack" ) ;
9393 }
9494
95+ [ Fact ]
96+ public void Should_translate_a_new_expression_where_one_field_starts_with_another_field ( )
97+ {
98+ var result = Project ( p => new { p . C . E , p . C . E1 } , "{ C : { E : { F : 2, H : 3 }, E1 : { F : 4, H : 5 } } }" ) ;
99+
100+ result . Projection . Should ( ) . Be ( "{ \" C.E\" : 1, \" C.E1\" : 1, _id : 0 }" ) ;
101+
102+ result . Value . E . F . Should ( ) . Be ( 2 ) ;
103+ result . Value . E . H . Should ( ) . Be ( 3 ) ;
104+
105+ result . Value . E1 . F . Should ( ) . Be ( 4 ) ;
106+ result . Value . E1 . H . Should ( ) . Be ( 5 ) ;
107+ }
108+
95109 [ Fact ]
96110 public void Should_translate_a_new_expression_with_a_single_top_level_field ( )
97111 {
@@ -112,6 +126,17 @@ public void Should_translate_a_new_expression_with_a_single_top_level_computed_f
112126 result . Value . FullName . Should ( ) . Be ( "Jack Awesome" ) ;
113127 }
114128
129+ [ Fact ]
130+ public void Should_translate_a_new_expression_with_top_level_fields_when_one_field_starts_with_another ( )
131+ {
132+ var result = Project ( p => new { p . A , p . A1 } , "{ A : \" Jack\" , A1 : \" Peter\" }" ) ;
133+
134+ result . Projection . Should ( ) . Be ( "{ A : 1, A1 : 1 _id: 0 }" ) ;
135+
136+ result . Value . A . Should ( ) . Be ( "Jack" ) ;
137+ result . Value . A1 . Should ( ) . Be ( "Peter" ) ;
138+ }
139+
115140 [ Fact ]
116141 public void Should_translate_when_a_top_level_field_is_repeated ( )
117142 {
@@ -144,7 +169,19 @@ public void Should_translate_with_a_single_computed_nested_field()
144169 }
145170
146171 [ Fact ]
147- public void Should_translate_with_a_hierarchical_redundancy ( )
172+ public void Should_translate_with_a_hierarchical_redundancy_and_a_non_top_level_projection ( )
173+ {
174+ var result = Project ( p => new { p . C . E , F = p . C . E . F } , "{ C : { E : { F : 2, H : 3 } } }" ) ;
175+
176+ result . Projection . Should ( ) . Be ( "{ \" C.E\" : 1, _id : 0 }" ) ;
177+
178+ result . Value . E . H . Should ( ) . Be ( 3 ) ;
179+ result . Value . F . Should ( ) . Be ( 2 ) ;
180+ result . Value . E . F . Should ( ) . Be ( 2 ) ;
181+ }
182+
183+ [ Fact ]
184+ public void Should_translate_with_a_hierarchical_redundancy_and_a_top_level_projection ( )
148185 {
149186 var result = Project ( p => new { p . C , F = p . C . E . F } , "{ C: { D: \" CEO\" , E: { F: 2 } } }" ) ;
150187
@@ -155,6 +192,18 @@ public void Should_translate_with_a_hierarchical_redundancy()
155192 result . Value . F . Should ( ) . Be ( 2 ) ;
156193 }
157194
195+ [ Fact ]
196+ public void Should_translate_with_a_hierarchical_redundancy_and_when_one_field_starts_with_another ( )
197+ {
198+ var result = Project ( p => new { p . C . E , F = p . C . E . E1 . F } , "{ C : { E : { E1 : { F : 2, H : 3 } } } }" ) ;
199+
200+ result . Projection . Should ( ) . Be ( "{ \" C.E\" : 1, _id : 0 }" ) ;
201+
202+ result . Value . E . E1 . H . Should ( ) . Be ( 3 ) ;
203+ result . Value . E . E1 . F . Should ( ) . Be ( 2 ) ;
204+ result . Value . F . Should ( ) . Be ( 2 ) ;
205+ }
206+
158207 [ Fact ]
159208 public void Should_translate_a_single_top_level_array ( )
160209 {
@@ -259,6 +308,8 @@ private class Root
259308
260309 public string A { get ; set ; }
261310
311+ public string A1 { get ; set ; }
312+
262313 public string B { get ; set ; }
263314
264315 public C C { get ; set ; }
@@ -271,6 +322,8 @@ public class C
271322 public string D { get ; set ; }
272323
273324 public E E { get ; set ; }
325+
326+ public E E1 { get ; set ; }
274327 }
275328
276329 public class E
@@ -280,6 +333,8 @@ public class E
280333 public int H { get ; set ; }
281334
282335 public IEnumerable < string > I { get ; set ; }
336+
337+ public E E1 { get ; set ; }
283338 }
284339 }
285340}
0 commit comments