@@ -43,6 +43,8 @@ public class C
4343 public ObjectId Id { get ; set ; }
4444 [ BsonElement ( "x" ) ]
4545 public int X { get ; set ; }
46+ [ BsonElement ( "lx" ) ]
47+ public long LX { get ; set ; }
4648 [ BsonElement ( "y" ) ]
4749 public int Y { get ; set ; }
4850 [ BsonElement ( "d" ) ]
@@ -150,11 +152,11 @@ public void Setup()
150152
151153 // documents inserted deliberately out of order to test sorting
152154 _collection . Drop ( ) ;
153- _collection . Insert ( new C { Id = _id2 , X = 2 , Y = 11 , D = new D { Z = 22 } , A = new [ ] { 2 , 3 , 4 } , DA = new List < D > { new D { Z = 111 } , new D { Z = 222 } } , L = new List < int > { 2 , 3 , 4 } } ) ;
154- _collection . Insert ( new C { Id = _id1 , X = 1 , Y = 11 , D = new D { Z = 11 } , S = "abc" , SA = new string [ ] { "Tom" , "Dick" , "Harry" } } ) ;
155- _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 } } ) ;
156- _collection . Insert ( new C { Id = _id5 , X = 5 , Y = 44 , D = new D { Z = 55 } , DBRef = new MongoDBRef ( "db" , "c" , 1 ) } ) ;
157- _collection . Insert ( new C { Id = _id4 , X = 4 , Y = 44 , D = new D { Z = 44 } , S = " xyz " , DA = new List < D > { new D { Z = 333 } , new D { Z = 444 } } } ) ;
155+ _collection . Insert ( new C { Id = _id2 , X = 2 , LX = 2 , Y = 11 , D = new D { Z = 22 } , A = new [ ] { 2 , 3 , 4 } , DA = new List < D > { new D { Z = 111 } , new D { Z = 222 } } , L = new List < int > { 2 , 3 , 4 } } ) ;
156+ _collection . Insert ( new C { Id = _id1 , X = 1 , LX = 1 , Y = 11 , D = new D { Z = 11 } , S = "abc" , SA = new string [ ] { "Tom" , "Dick" , "Harry" } } ) ;
157+ _collection . Insert ( new C { Id = _id3 , X = 3 , LX = 3 , Y = 33 , D = new D { Z = 33 } , B = true , BA = new bool [ ] { true } , E = E . A , EA = new E [ ] { E . A , E . B } } ) ;
158+ _collection . Insert ( new C { Id = _id5 , X = 5 , LX = 5 , Y = 44 , D = new D { Z = 55 } , DBRef = new MongoDBRef ( "db" , "c" , 1 ) } ) ;
159+ _collection . Insert ( new C { Id = _id4 , X = 4 , LX = 4 , Y = 44 , D = new D { Z = 44 } , S = " xyz " , DA = new List < D > { new D { Z = 333 } , new D { Z = 444 } } } ) ;
158160 }
159161
160162 [ Test ]
@@ -4046,6 +4048,121 @@ public void TestWhereLSub1NotEquals3Not()
40464048 Assert . AreEqual ( 1 , Consume ( query ) ) ;
40474049 }
40484050
4051+ [ Test ]
4052+ public void TestWhereLXModTwoEquals1 ( )
4053+ {
4054+ var query = from c in _collection . AsQueryable < C > ( )
4055+ where c . LX % 2 == 1
4056+ select c ;
4057+
4058+ var translatedQuery = MongoQueryTranslator . Translate ( query ) ;
4059+ Assert . IsInstanceOf < SelectQuery > ( translatedQuery ) ;
4060+ Assert . AreSame ( _collection , translatedQuery . Collection ) ;
4061+ Assert . AreSame ( typeof ( C ) , translatedQuery . DocumentType ) ;
4062+
4063+ var selectQuery = ( SelectQuery ) translatedQuery ;
4064+ Assert . AreEqual ( "(C c) => ((c.LX % 2) == 1)" , ExpressionFormatter . ToString ( selectQuery . Where ) ) ;
4065+ Assert . IsNull ( selectQuery . OrderBy ) ;
4066+ Assert . IsNull ( selectQuery . Projection ) ;
4067+ Assert . IsNull ( selectQuery . Skip ) ;
4068+ Assert . IsNull ( selectQuery . Take ) ;
4069+
4070+ Assert . AreEqual ( "{ \" lx\" : { \" $mod\" : [2, 1] } }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
4071+ Assert . AreEqual ( 3 , Consume ( query ) ) ;
4072+ }
4073+
4074+ [ Test ]
4075+ public void TestWhereLXModTwoEquals1Not ( )
4076+ {
4077+ var query = from c in _collection . AsQueryable < C > ( )
4078+ where ! ( c . LX % 2 == 1 )
4079+ select c ;
4080+
4081+ var translatedQuery = MongoQueryTranslator . Translate ( query ) ;
4082+ Assert . IsInstanceOf < SelectQuery > ( translatedQuery ) ;
4083+ Assert . AreSame ( _collection , translatedQuery . Collection ) ;
4084+ Assert . AreSame ( typeof ( C ) , translatedQuery . DocumentType ) ;
4085+
4086+ var selectQuery = ( SelectQuery ) translatedQuery ;
4087+ Assert . AreEqual ( "(C c) => !((c.LX % 2) == 1)" , ExpressionFormatter . ToString ( selectQuery . Where ) ) ;
4088+ Assert . IsNull ( selectQuery . OrderBy ) ;
4089+ Assert . IsNull ( selectQuery . Projection ) ;
4090+ Assert . IsNull ( selectQuery . Skip ) ;
4091+ Assert . IsNull ( selectQuery . Take ) ;
4092+
4093+ Assert . AreEqual ( "{ \" lx\" : { \" $not\" : { \" $mod\" : [2, 1] } } }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
4094+ Assert . AreEqual ( 2 , Consume ( query ) ) ;
4095+ }
4096+
4097+ [ Test ]
4098+ public void TestWhereLXModTwoEquals1Reversed ( )
4099+ {
4100+ var query = from c in _collection . AsQueryable < C > ( )
4101+ where 1 == c . LX % 2
4102+ select c ;
4103+
4104+ var translatedQuery = MongoQueryTranslator . Translate ( query ) ;
4105+ Assert . IsInstanceOf < SelectQuery > ( translatedQuery ) ;
4106+ Assert . AreSame ( _collection , translatedQuery . Collection ) ;
4107+ Assert . AreSame ( typeof ( C ) , translatedQuery . DocumentType ) ;
4108+
4109+ var selectQuery = ( SelectQuery ) translatedQuery ;
4110+ Assert . AreEqual ( "(C c) => ((c.LX % 2) == 1)" , ExpressionFormatter . ToString ( selectQuery . Where ) ) ;
4111+ Assert . IsNull ( selectQuery . OrderBy ) ;
4112+ Assert . IsNull ( selectQuery . Projection ) ;
4113+ Assert . IsNull ( selectQuery . Skip ) ;
4114+ Assert . IsNull ( selectQuery . Take ) ;
4115+
4116+ Assert . AreEqual ( "{ \" lx\" : { \" $mod\" : [2, 1] } }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
4117+ Assert . AreEqual ( 3 , Consume ( query ) ) ;
4118+ }
4119+
4120+ [ Test ]
4121+ public void TestWhereLXModTwoNotEquals1 ( )
4122+ {
4123+ var query = from c in _collection . AsQueryable < C > ( )
4124+ where c . LX % 2 != 1
4125+ select c ;
4126+
4127+ var translatedQuery = MongoQueryTranslator . Translate ( query ) ;
4128+ Assert . IsInstanceOf < SelectQuery > ( translatedQuery ) ;
4129+ Assert . AreSame ( _collection , translatedQuery . Collection ) ;
4130+ Assert . AreSame ( typeof ( C ) , translatedQuery . DocumentType ) ;
4131+
4132+ var selectQuery = ( SelectQuery ) translatedQuery ;
4133+ Assert . AreEqual ( "(C c) => ((c.LX % 2) != 1)" , ExpressionFormatter . ToString ( selectQuery . Where ) ) ;
4134+ Assert . IsNull ( selectQuery . OrderBy ) ;
4135+ Assert . IsNull ( selectQuery . Projection ) ;
4136+ Assert . IsNull ( selectQuery . Skip ) ;
4137+ Assert . IsNull ( selectQuery . Take ) ;
4138+
4139+ Assert . AreEqual ( "{ \" lx\" : { \" $not\" : { \" $mod\" : [2, 1] } } }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
4140+ Assert . AreEqual ( 2 , Consume ( query ) ) ;
4141+ }
4142+
4143+ [ Test ]
4144+ public void TestWhereLXModTwoNotEquals1Not ( )
4145+ {
4146+ var query = from c in _collection . AsQueryable < C > ( )
4147+ where ! ( c . LX % 2 != 1 )
4148+ select c ;
4149+
4150+ var translatedQuery = MongoQueryTranslator . Translate ( query ) ;
4151+ Assert . IsInstanceOf < SelectQuery > ( translatedQuery ) ;
4152+ Assert . AreSame ( _collection , translatedQuery . Collection ) ;
4153+ Assert . AreSame ( typeof ( C ) , translatedQuery . DocumentType ) ;
4154+
4155+ var selectQuery = ( SelectQuery ) translatedQuery ;
4156+ Assert . AreEqual ( "(C c) => !((c.LX % 2) != 1)" , ExpressionFormatter . ToString ( selectQuery . Where ) ) ;
4157+ Assert . IsNull ( selectQuery . OrderBy ) ;
4158+ Assert . IsNull ( selectQuery . Projection ) ;
4159+ Assert . IsNull ( selectQuery . Skip ) ;
4160+ Assert . IsNull ( selectQuery . Take ) ;
4161+
4162+ Assert . AreEqual ( "{ \" lx\" : { \" $mod\" : [2, 1] } }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
4163+ Assert . AreEqual ( 3 , Consume ( query ) ) ;
4164+ }
4165+
40494166 [ Test ]
40504167 public void TestWhereSASub0ContainsO ( )
40514168 {
0 commit comments