17
17
using System . Collections . Generic ;
18
18
using System . Linq ;
19
19
using System . Linq . Expressions ;
20
- using System . Threading . Tasks ;
21
20
using FluentAssertions ;
22
21
using MongoDB . Bson ;
23
22
using MongoDB . Bson . Serialization ;
24
- using MongoDB . Bson . TestHelpers . XunitExtensions ;
25
- using MongoDB . Driver ;
26
- using MongoDB . Driver . Core ;
27
23
using MongoDB . Driver . Core . TestHelpers . XunitExtensions ;
28
24
using MongoDB . Driver . Linq ;
29
25
using MongoDB . Driver . Linq . Translators ;
@@ -125,6 +121,46 @@ public void Should_translate_count()
125
121
result . Value . Result . Should ( ) . Be ( 1 ) ;
126
122
}
127
123
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
+
128
164
[ Fact ]
129
165
public void Should_translate_long_count ( )
130
166
{
@@ -394,4 +430,4 @@ private class ProjectedResult<T>
394
430
public T Value ;
395
431
}
396
432
}
397
- }
433
+ }
0 commit comments