1717using System . Collections . Generic ;
1818using System . Linq ;
1919using System . Linq . Expressions ;
20- using System . Threading . Tasks ;
2120using FluentAssertions ;
2221using MongoDB . Bson ;
2322using MongoDB . Bson . Serialization ;
24- using MongoDB . Bson . TestHelpers . XunitExtensions ;
25- using MongoDB . Driver ;
26- using MongoDB . Driver . Core ;
2723using MongoDB . Driver . Core . TestHelpers . XunitExtensions ;
2824using MongoDB . Driver . Linq ;
2925using MongoDB . Driver . Linq . Translators ;
@@ -125,6 +121,46 @@ public void Should_translate_count()
125121 result . Value . Result . Should ( ) . Be ( 1 ) ;
126122 }
127123
124+ [ Fact ]
125+ public void Should_translate_count_with_a_predicate ( )
126+ {
127+ var result = Group ( x => x . A , g => new { Result = g . Count ( x => x . A != "Awesome" ) } ) ;
128+
129+ result . Projection . Should ( ) . Be ( "{ \" _id\" : \" $A\" , \" Result\" : { \" $sum\" : { \" $cond\" : [{ \" $ne\" : [\" $A\" , \" Awesome\" ] }, 1, 0] } } }" ) ;
130+
131+ result . Value . Result . Should ( ) . Be ( 1 ) ;
132+ }
133+
134+ [ Fact ]
135+ public void Should_translate_where_with_a_predicate_and_count ( )
136+ {
137+ var result = Group ( x => x . A , g => new { Result = g . Where ( x => x . A != "Awesome" ) . Count ( ) } ) ;
138+
139+ result . Projection . Should ( ) . Be ( "{ \" _id\" : \" $A\" , \" Result\" : { \" $sum\" : { \" $cond\" : [{ \" $ne\" : [\" $A\" , \" Awesome\" ] }, 1, 0] } } }" ) ;
140+
141+ result . Value . Result . Should ( ) . Be ( 1 ) ;
142+ }
143+
144+ [ Fact ]
145+ public void Should_translate_where_select_and_count_with_predicates ( )
146+ {
147+ var result = Group ( x => x . A , g => new { Result = g . Select ( x => new { A = x . A } ) . Count ( x => x . A != "Awesome" ) } ) ;
148+
149+ result . Projection . Should ( ) . Be ( "{ \" _id\" : \" $A\" , \" Result\" : { \" $sum\" : { \" $cond\" : [{ \" $ne\" : [\" $A\" , \" Awesome\" ] }, 1, 0] } } }" ) ;
150+
151+ result . Value . Result . Should ( ) . Be ( 1 ) ;
152+ }
153+
154+ [ Fact ]
155+ public void Should_translate_where_select_with_predicate_and_count ( )
156+ {
157+ var result = Group ( x => x . A , g => new { Result = g . Select ( x => new { A = x . A } ) . Count ( ) } ) ;
158+
159+ result . Projection . Should ( ) . Be ( "{ \" _id\" : \" $A\" , \" Result\" : { \" $sum\" : 1 } }" ) ;
160+
161+ result . Value . Result . Should ( ) . Be ( 1 ) ;
162+ }
163+
128164 [ Fact ]
129165 public void Should_translate_long_count ( )
130166 {
@@ -394,4 +430,4 @@ private class ProjectedResult<T>
394430 public T Value ;
395431 }
396432 }
397- }
433+ }
0 commit comments