@@ -153,7 +153,7 @@ public void Setup()
153
153
_collection . Insert ( new C { Id = _id1 , X = 1 , Y = 11 , D = new D { Z = 11 } , S = "abc" , SA = new string [ ] { "Tom" , "Dick" , "Harry" } } ) ;
154
154
_collection . Insert ( new C { Id = _id3 , X = 3 , Y = 33 , D = new D { Z = 33 } , B = true , BA = new bool [ ] { true } , E = E . A , EA = new E [ ] { E . A , E . B } } ) ;
155
155
_collection . Insert ( new C { Id = _id5 , X = 5 , Y = 44 , D = new D { Z = 55 } , DBRef = new MongoDBRef ( "db" , "c" , 1 ) } ) ;
156
- _collection . Insert ( new C { Id = _id4 , X = 4 , Y = 44 , D = new D { Z = 44 } } ) ;
156
+ _collection . Insert ( new C { Id = _id4 , X = 4 , Y = 44 , D = new D { Z = 44 } , S = " xyz " } ) ;
157
157
}
158
158
159
159
[ Test ]
@@ -517,8 +517,9 @@ public void TestDistinctS()
517
517
var query = ( from c in _collection . AsQueryable < C > ( )
518
518
select c . S ) . Distinct ( ) ;
519
519
var results = query . ToList ( ) ;
520
- Assert . AreEqual ( 1 , results . Count ) ;
520
+ Assert . AreEqual ( 2 , results . Count ) ;
521
521
Assert . IsTrue ( results . Contains ( "abc" ) ) ;
522
+ Assert . IsTrue ( results . Contains ( " xyz " ) ) ;
522
523
}
523
524
524
525
[ Test ]
@@ -4421,6 +4422,121 @@ where Regex.IsMatch(c.S, "^abc", RegexOptions.IgnoreCase)
4421
4422
Assert . AreEqual ( 1 , Consume ( query ) ) ;
4422
4423
}
4423
4424
4425
+ [ Test ]
4426
+ public void TestWhereSLengthEquals3 ( )
4427
+ {
4428
+ var query = from c in _collection . AsQueryable < C > ( )
4429
+ where c . S . Length == 3
4430
+ select c ;
4431
+
4432
+ var translatedQuery = MongoQueryTranslator . Translate ( query ) ;
4433
+ Assert . IsInstanceOf < SelectQuery > ( translatedQuery ) ;
4434
+ Assert . AreSame ( _collection , translatedQuery . Collection ) ;
4435
+ Assert . AreSame ( typeof ( C ) , translatedQuery . DocumentType ) ;
4436
+
4437
+ var selectQuery = ( SelectQuery ) translatedQuery ;
4438
+ Assert . AreEqual ( "(C c) => (c.S.Length == 3)" , ExpressionFormatter . ToString ( selectQuery . Where ) ) ;
4439
+ Assert . IsNull ( selectQuery . OrderBy ) ;
4440
+ Assert . IsNull ( selectQuery . Projection ) ;
4441
+ Assert . IsNull ( selectQuery . Skip ) ;
4442
+ Assert . IsNull ( selectQuery . Take ) ;
4443
+
4444
+ Assert . AreEqual ( "{ \" s\" : /^.{3}$/s }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
4445
+ Assert . AreEqual ( 1 , Consume ( query ) ) ;
4446
+ }
4447
+
4448
+ [ Test ]
4449
+ public void TestWhereSLengthGreaterThan3 ( )
4450
+ {
4451
+ var query = from c in _collection . AsQueryable < C > ( )
4452
+ where c . S . Length > 3
4453
+ select c ;
4454
+
4455
+ var translatedQuery = MongoQueryTranslator . Translate ( query ) ;
4456
+ Assert . IsInstanceOf < SelectQuery > ( translatedQuery ) ;
4457
+ Assert . AreSame ( _collection , translatedQuery . Collection ) ;
4458
+ Assert . AreSame ( typeof ( C ) , translatedQuery . DocumentType ) ;
4459
+
4460
+ var selectQuery = ( SelectQuery ) translatedQuery ;
4461
+ Assert . AreEqual ( "(C c) => (c.S.Length > 3)" , ExpressionFormatter . ToString ( selectQuery . Where ) ) ;
4462
+ Assert . IsNull ( selectQuery . OrderBy ) ;
4463
+ Assert . IsNull ( selectQuery . Projection ) ;
4464
+ Assert . IsNull ( selectQuery . Skip ) ;
4465
+ Assert . IsNull ( selectQuery . Take ) ;
4466
+
4467
+ Assert . AreEqual ( "{ \" s\" : /^.{4,}$/s }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
4468
+ Assert . AreEqual ( 1 , Consume ( query ) ) ;
4469
+ }
4470
+
4471
+ [ Test ]
4472
+ public void TestWhereSLengthGreaterThanOrEquals3 ( )
4473
+ {
4474
+ var query = from c in _collection . AsQueryable < C > ( )
4475
+ where c . S . Length >= 3
4476
+ select c ;
4477
+
4478
+ var translatedQuery = MongoQueryTranslator . Translate ( query ) ;
4479
+ Assert . IsInstanceOf < SelectQuery > ( translatedQuery ) ;
4480
+ Assert . AreSame ( _collection , translatedQuery . Collection ) ;
4481
+ Assert . AreSame ( typeof ( C ) , translatedQuery . DocumentType ) ;
4482
+
4483
+ var selectQuery = ( SelectQuery ) translatedQuery ;
4484
+ Assert . AreEqual ( "(C c) => (c.S.Length >= 3)" , ExpressionFormatter . ToString ( selectQuery . Where ) ) ;
4485
+ Assert . IsNull ( selectQuery . OrderBy ) ;
4486
+ Assert . IsNull ( selectQuery . Projection ) ;
4487
+ Assert . IsNull ( selectQuery . Skip ) ;
4488
+ Assert . IsNull ( selectQuery . Take ) ;
4489
+
4490
+ Assert . AreEqual ( "{ \" s\" : /^.{3,}$/s }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
4491
+ Assert . AreEqual ( 2 , Consume ( query ) ) ;
4492
+ }
4493
+
4494
+ [ Test ]
4495
+ public void TestWhereSLengthLessThan3 ( )
4496
+ {
4497
+ var query = from c in _collection . AsQueryable < C > ( )
4498
+ where c . S . Length < 3
4499
+ select c ;
4500
+
4501
+ var translatedQuery = MongoQueryTranslator . Translate ( query ) ;
4502
+ Assert . IsInstanceOf < SelectQuery > ( translatedQuery ) ;
4503
+ Assert . AreSame ( _collection , translatedQuery . Collection ) ;
4504
+ Assert . AreSame ( typeof ( C ) , translatedQuery . DocumentType ) ;
4505
+
4506
+ var selectQuery = ( SelectQuery ) translatedQuery ;
4507
+ Assert . AreEqual ( "(C c) => (c.S.Length < 3)" , ExpressionFormatter . ToString ( selectQuery . Where ) ) ;
4508
+ Assert . IsNull ( selectQuery . OrderBy ) ;
4509
+ Assert . IsNull ( selectQuery . Projection ) ;
4510
+ Assert . IsNull ( selectQuery . Skip ) ;
4511
+ Assert . IsNull ( selectQuery . Take ) ;
4512
+
4513
+ Assert . AreEqual ( "{ \" s\" : /^.{0,2}$/s }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
4514
+ Assert . AreEqual ( 0 , Consume ( query ) ) ;
4515
+ }
4516
+
4517
+ [ Test ]
4518
+ public void TestWhereSLengthLessThanOrEquals3 ( )
4519
+ {
4520
+ var query = from c in _collection . AsQueryable < C > ( )
4521
+ where c . S . Length <= 3
4522
+ select c ;
4523
+
4524
+ var translatedQuery = MongoQueryTranslator . Translate ( query ) ;
4525
+ Assert . IsInstanceOf < SelectQuery > ( translatedQuery ) ;
4526
+ Assert . AreSame ( _collection , translatedQuery . Collection ) ;
4527
+ Assert . AreSame ( typeof ( C ) , translatedQuery . DocumentType ) ;
4528
+
4529
+ var selectQuery = ( SelectQuery ) translatedQuery ;
4530
+ Assert . AreEqual ( "(C c) => (c.S.Length <= 3)" , ExpressionFormatter . ToString ( selectQuery . Where ) ) ;
4531
+ Assert . IsNull ( selectQuery . OrderBy ) ;
4532
+ Assert . IsNull ( selectQuery . Projection ) ;
4533
+ Assert . IsNull ( selectQuery . Skip ) ;
4534
+ Assert . IsNull ( selectQuery . Take ) ;
4535
+
4536
+ Assert . AreEqual ( "{ \" s\" : /^.{0,3}$/s }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
4537
+ Assert . AreEqual ( 1 , Consume ( query ) ) ;
4538
+ }
4539
+
4424
4540
[ Test ]
4425
4541
public void TestWhereSStartsWithAbc ( )
4426
4542
{
0 commit comments