@@ -213,6 +213,48 @@ public void Any_with_a_nested_Any()
213
213
"{ G : { $elemMatch : { D : \" Don't\" , \" S\" : { $elemMatch : { E : null, D : \" Delilah\" } } } } }" ) ;
214
214
}
215
215
216
+ [ Fact ]
217
+ public void Any_with_a_not_and_a_predicate_with_not_contains ( )
218
+ {
219
+ var x = new [ ] { 1 , 2 } ;
220
+
221
+ AssertUsingCustomCollection (
222
+ c => ! c . M . Any ( a => ! x . Contains ( a ) ) ,
223
+ "{ M : { '$not' : { '$elemMatch' : { '$not' : { '$in' : [1, 2] } } } } }" ) ;
224
+ }
225
+
226
+ [ Fact ]
227
+ public void Any_with_a_not_and_a_predicate_with_contains ( )
228
+ {
229
+ var x = new [ ] { 1 , 2 } ;
230
+
231
+ AssertUsingCustomCollection (
232
+ c => ! c . M . Any ( a => x . Contains ( a ) ) ,
233
+ "{ M : { '$not' : { '$elemMatch' : { '$in' : [1, 2] } } } }" ) ;
234
+ }
235
+
236
+ [ Fact ]
237
+ public void Any_with_a_predicate_with_contains ( )
238
+ {
239
+ var x = new [ ] { 1 , 2 } ;
240
+
241
+ AssertUsingCustomCollection (
242
+ c => c . M . Any ( a => x . Contains ( a ) ) ,
243
+ "{ M : { '$elemMatch' : { '$in' : [1, 2] } } }"
244
+ ) ;
245
+ }
246
+
247
+ [ Fact ]
248
+ public void Any_with_a_predicate_with_not_contains ( )
249
+ {
250
+ var x = new [ ] { 1 , 2 } ;
251
+
252
+ AssertUsingCustomCollection (
253
+ c => c . M . Any ( a => ! x . Contains ( a ) ) ,
254
+ "{ M : { '$elemMatch' : { '$not' : { '$in' : [1, 2] } } } }"
255
+ ) ;
256
+ }
257
+
216
258
[ Fact ]
217
259
public void Any_with_a_not ( )
218
260
{
@@ -251,7 +293,7 @@ public void Any_with_a_predicate_on_scalars()
251
293
1 ,
252
294
"{\" C.E.I\" : /^ick/s}" ) ;
253
295
254
- // this isn't a legal query, as in, there isn't any
296
+ // this isn't a legal query, as in, there isn't any
255
297
// way to render this legally for the server...
256
298
//Assert(
257
299
// x => x.C.E.I.Any(i => i.StartsWith("ick") && i == "Jack"),
@@ -284,7 +326,7 @@ public void Any_with_local_contains_on_an_embedded_document()
284
326
Assert (
285
327
x => x . G . Any ( g => local . Contains ( g . D ) ) ,
286
328
1 ,
287
- "{\" G.D \" : { $in: [\" Delilah\" , \" Dolphin\" ] } }" ) ;
329
+ "{ 'G' : { '$elemMatch' : { 'D' : { $in : [' Delilah', ' Dolphin'] } } } }" ) ;
288
330
}
289
331
290
332
[ Fact ]
@@ -910,7 +952,7 @@ public void Assert<T>(IMongoCollection<T> collection, Expression<Func<T, bool>>
910
952
Assert ( collection , filter , expectedCount , BsonDocument . Parse ( expectedFilter ) ) ;
911
953
}
912
954
913
- public void Assert < T > ( IMongoCollection < T > collection , Expression < Func < T , bool > > filter , int expectedCount , BsonDocument expectedFilter )
955
+ public List < T > Assert < T > ( IMongoCollection < T > collection , Expression < Func < T , bool > > filter , int expectedCount , BsonDocument expectedFilter )
914
956
{
915
957
var serializer = BsonSerializer . SerializerRegistry . GetSerializer < T > ( ) ;
916
958
var filterDocument = PredicateTranslator . Translate ( filter , serializer , BsonSerializer . SerializerRegistry ) ;
@@ -919,6 +961,7 @@ public void Assert<T>(IMongoCollection<T> collection, Expression<Func<T, bool>>
919
961
920
962
filterDocument . Should ( ) . Be ( expectedFilter ) ;
921
963
list . Count . Should ( ) . Be ( expectedCount ) ;
964
+ return list ;
922
965
}
923
966
924
967
public void Assert ( Expression < Func < Root , bool > > filter , int expectedCount , string expectedFilter )
@@ -930,5 +973,41 @@ public void Assert(Expression<Func<Root, bool>> filter, int expectedCount, BsonD
930
973
{
931
974
Assert ( __collection , filter , expectedCount , expectedFilter ) ;
932
975
}
976
+
977
+ protected override void FillCustomDocuments ( List < Root > customDocuments )
978
+ {
979
+ customDocuments . AddRange (
980
+ new [ ]
981
+ {
982
+ new Root { Id = 1 , M = new int [ 0 ] } ,
983
+ new Root { Id = 2 , M = new [ ] { 1 } } ,
984
+ new Root { Id = 3 , M = new [ ] { 2 } } ,
985
+ new Root { Id = 4 , M = new [ ] { 3 } } ,
986
+ new Root { Id = 5 , M = new [ ] { 4 } } ,
987
+ new Root { Id = 6 , M = new [ ] { 1 , 2 } } ,
988
+ new Root { Id = 7 , M = new [ ] { 1 , 3 } } ,
989
+ new Root { Id = 8 , M = new [ ] { 1 , 4 } } ,
990
+ new Root { Id = 9 , M = new [ ] { 2 , 3 } } ,
991
+ new Root { Id = 10 , M = new [ ] { 3 , 4 } } ,
992
+ new Root { Id = 11 , M = new [ ] { 1 , 2 , 3 } } ,
993
+ new Root { Id = 12 , M = new [ ] { 1 , 2 , 4 } } ,
994
+ new Root { Id = 13 , M = new [ ] { 1 , 3 , 4 } } ,
995
+ new Root { Id = 14 , M = new [ ] { 1 , 2 , 3 , 4 } }
996
+ } ) ;
997
+ }
998
+
999
+ public void AssertUsingCustomCollection ( Expression < Func < Root , bool > > filter , string expectedFilter )
1000
+ {
1001
+ AssertUsingCustomCollection ( filter , BsonDocument . Parse ( expectedFilter ) ) ;
1002
+ }
1003
+
1004
+ public void AssertUsingCustomCollection ( Expression < Func < Root , bool > > filter , BsonDocument expectedFilter )
1005
+ {
1006
+ var expectedResult = __customDocuments . Where ( filter . Compile ( ) ) . ToList ( ) ;
1007
+
1008
+ var queryResult = Assert ( __customCollection , filter , expectedResult . Count , expectedFilter ) ;
1009
+
1010
+ queryResult . Select ( r => r . Id ) . Should ( ) . Equal ( expectedResult . Select ( r => r . Id ) ) ;
1011
+ }
933
1012
}
934
1013
}
0 commit comments