18
18
using System . Linq ;
19
19
using System . Linq . Expressions ;
20
20
using System . Text . RegularExpressions ;
21
- using System . Threading . Tasks ;
22
21
using FluentAssertions ;
23
22
using MongoDB . Bson ;
24
23
using MongoDB . Bson . Serialization ;
25
- using MongoDB . Bson . TestHelpers . XunitExtensions ;
26
- using MongoDB . Driver . Core ;
27
24
using MongoDB . Driver . Core . TestHelpers . XunitExtensions ;
28
25
using MongoDB . Driver . Linq ;
29
26
using MongoDB . Driver . Linq . Translators ;
@@ -115,12 +112,81 @@ public void Any_with_a_predicate_on_documents()
115
112
Assert (
116
113
x => x . G . Any ( g => g . D == "Don't" ) ,
117
114
1 ,
118
- "{\" G.D \" : \" Don't\" }" ) ;
115
+ "{ G : { $elemMatch : { D : \" Don't\" } } }" ) ;
119
116
120
117
Assert (
121
118
x => x . G . Any ( g => g . D == "Don't" && g . E . F == 33 ) ,
122
119
1 ,
123
- "{G: {$elemMatch: {D: \" Don't\" , 'E.F': 33}}}" ) ;
120
+ "{ G : { $elemMatch : { D : \" Don't\" , 'E.F' : 33 } } }" ) ;
121
+ }
122
+
123
+ [ Fact ]
124
+ public void Any_with_a_gte_predicate_on_documents ( )
125
+ {
126
+ Assert (
127
+ x => x . G . Any ( g => g . E . F >= 100 ) ,
128
+ 1 ,
129
+ "{ \" G\" : { \" $elemMatch\" : { \" E.F\" : { \" $gte\" : 100 } } } }" ) ;
130
+ }
131
+
132
+ [ Fact ]
133
+ public void Any_with_a_ne_and_Equal_predicate_on_documents ( )
134
+ {
135
+ Assert (
136
+ x => x . G . Any ( g => ! g . D . Equals ( "Don't" ) ) ,
137
+ 2 ,
138
+ "{ \" G\" : { \" $elemMatch\" : { \" D\" : { \" $ne\" : \" Don't\" } } } }" ) ;
139
+ }
140
+
141
+ [ Fact ]
142
+ public void Any_with_a_ne_predicate_on_documents ( )
143
+ {
144
+ Assert (
145
+ x => x . G . Any ( g => g . S != null ) ,
146
+ 1 ,
147
+ "{ \" G\" : { \" $elemMatch\" : { \" S\" : { \" $ne\" : null } } } }" ) ;
148
+ Assert (
149
+ x => x . G . Any ( g => ! ( g . S == null ) ) ,
150
+ 1 ,
151
+ "{ \" G\" : { \" $elemMatch\" : { \" S\" : { \" $ne\" : null } } } }" ) ;
152
+ }
153
+
154
+ [ Fact ]
155
+ public void Any_with_a_multi_not_brackets_predicate_on_documents ( )
156
+ {
157
+ Assert (
158
+ x => x . G . Any ( g => ! ( ! ( g . D == "Don't" ) ) ) ,
159
+ 1 ,
160
+ "{ \" G\" : { \" $elemMatch\" : { \" D\" : \" Don't\" } } }" ) ;
161
+
162
+ Assert (
163
+ x => x . G . Any ( g => ! ( ! ( ! ( ! ( g . D == "Don't" ) ) ) ) ) ,
164
+ 1 ,
165
+ "{ \" G\" : { \" $elemMatch\" : { \" D\" : \" Don't\" } } }" ) ;
166
+
167
+ Assert (
168
+ x => x . G . Any ( g => ! ( g . S == null ) ) ,
169
+ 1 ,
170
+ "{ \" G\" : { \" $elemMatch\" : { \" S\" : { \" $ne\" : null } } } }" ) ;
171
+
172
+ Assert (
173
+ x => x . G . Any ( g => ! ( ! ( ! ( g . S == null ) ) ) ) ,
174
+ 1 ,
175
+ "{ \" G\" : { \" $elemMatch\" : { \" S\" : { \" $ne\" : null } } } }" ) ;
176
+ }
177
+
178
+ [ Fact ]
179
+ public void Any_with_a_multi_conditions_predicate_on_documents ( )
180
+ {
181
+ Assert (
182
+ x => x . G . Any ( g => g . D != "Don't" && g . E . F == 333 ) ,
183
+ 1 ,
184
+ "{ \" G\" : { \" $elemMatch\" : { \" D\" : { \" $ne\" : \" Don't\" }, \" E.F\" : 333 } } }" ) ;
185
+
186
+ Assert (
187
+ x => x . G . Any ( g => g . D == "Don't" || g . E . F != 32 ) ,
188
+ 2 ,
189
+ "{ \" G\" : { \" $elemMatch\" : { \" $or\" : [{ \" D\" : \" Don't\" }, { \" E.F\" : { \" $ne\" : 32 } }] } } }" ) ;
124
190
}
125
191
126
192
[ Fact ]
@@ -129,22 +195,22 @@ public void Any_with_a_nested_Any()
129
195
Assert (
130
196
x => x . G . Any ( g => g . S . Any ( ) ) ,
131
197
1 ,
132
- "{G : {$elemMatch: {S : {$ne: null, $not: {$size: 0}}}} }" ) ;
198
+ "{ G : { $elemMatch : { S : { $ne : null, $not : { $size : 0 } } } } }" ) ;
133
199
134
200
Assert (
135
201
x => x . G . Any ( g => g . S . Any ( s => s . D == "Delilah" ) ) ,
136
202
1 ,
137
- "{\" G.S. D\" : \" Delilah\" }" ) ;
203
+ "{ \" G.S\" : { $elemMatch : { \" D\" : \" Delilah\" } } }" ) ;
138
204
139
205
Assert (
140
206
x => x . G . Any ( g => g . D == "Don't" && g . S . Any ( s => s . D == "Delilah" ) ) ,
141
207
1 ,
142
- "{G : {$elemMatch: {D : \" Don't\" , \" S. D\" : \" Delilah\" }} }" ) ;
208
+ "{ \" G \" : { \" $elemMatch\" : { \" D \" : \" Don't\" , \" S\" : { \" $elemMatch \" : { \" D\" : \" Delilah\" } } } } }" ) ;
143
209
144
210
Assert (
145
211
x => x . G . Any ( g => g . D == "Don't" && g . S . Any ( s => s . E == null && s . D == "Delilah" ) ) ,
146
212
1 ,
147
- "{G : {$elemMatch: {D : \" Don't\" , \" S\" : {$elemMatch: {E : null, D: \" Delilah\" }}}} }" ) ;
213
+ "{ G : { $elemMatch : { D : \" Don't\" , \" S\" : { $elemMatch : { E : null, D : \" Delilah\" } } } } }" ) ;
148
214
}
149
215
150
216
[ Fact ]
@@ -153,12 +219,12 @@ public void Any_with_a_not()
153
219
Assert (
154
220
x => x . G . Any ( g => ! g . S . Any ( ) ) ,
155
221
2 ,
156
- "{G : {$elemMatch: {$nor: [{S : {$ne: null, $not: {$size: 0}}}]}} }" ) ;
222
+ "{ G : { $elemMatch : { $nor : [{ S : { $ne : null, $not : { $size : 0 } } }] } } }" ) ;
157
223
158
224
Assert (
159
225
x => x . G . Any ( g => ! g . S . Any ( s => s . D == "Delilah" ) ) ,
160
226
1 ,
161
- "{\" G.S.D \" : {$ne: \" Delilah\" } }" ) ;
227
+ "{\" G.S\" : { $not : { $elemMatch : { \" D \" : \" Delilah\" } } } }" ) ;
162
228
}
163
229
164
230
[ Fact ]
@@ -167,12 +233,12 @@ public void Any_with_a_predicate_on_scalars_legacy()
167
233
Assert (
168
234
x => x . M . Any ( m => m > 5 ) ,
169
235
1 ,
170
- "{M : {$gt : 5} }" ) ;
236
+ "{ M : { $elemMatch : { $gt : 5 } } }" ) ;
171
237
172
238
Assert (
173
239
x => x . M . Any ( m => m > 2 && m < 6 ) ,
174
240
2 ,
175
- "{M : {$elemMatch: {$gt: 2, $lt: 6}} }" ) ;
241
+ "{ M : { $elemMatch : { $gt : 2, $lt : 6 } } }" ) ;
176
242
}
177
243
178
244
[ SkippableFact ]
@@ -240,7 +306,7 @@ public void AsQueryable()
240
306
Assert (
241
307
x => x . G . AsQueryable ( ) . Any ( filter ) ,
242
308
1 ,
243
- "{ 'G.D' : \" Don't\" }" ) ;
309
+ "{ 'G' : { '$elemMatch' : { 'D' : \" Don't\" } } }" ) ;
244
310
}
245
311
246
312
[ SkippableFact ]
@@ -865,4 +931,4 @@ public void Assert(Expression<Func<Root, bool>> filter, int expectedCount, BsonD
865
931
Assert ( __collection , filter , expectedCount , expectedFilter ) ;
866
932
}
867
933
}
868
- }
934
+ }
0 commit comments