@@ -126,11 +126,12 @@ public int GetHashCode(int obj)
126
126
private MongoDatabase _database ;
127
127
private MongoCollection < C > _collection ;
128
128
private MongoCollection < SystemProfileInfo > _systemProfileCollection ;
129
- private ObjectId id1 = ObjectId . GenerateNewId ( ) ;
130
- private ObjectId id2 = ObjectId . GenerateNewId ( ) ;
131
- private ObjectId id3 = ObjectId . GenerateNewId ( ) ;
132
- private ObjectId id4 = ObjectId . GenerateNewId ( ) ;
133
- private ObjectId id5 = ObjectId . GenerateNewId ( ) ;
129
+
130
+ private ObjectId _id1 = ObjectId . GenerateNewId ( ) ;
131
+ private ObjectId _id2 = ObjectId . GenerateNewId ( ) ;
132
+ private ObjectId _id3 = ObjectId . GenerateNewId ( ) ;
133
+ private ObjectId _id4 = ObjectId . GenerateNewId ( ) ;
134
+ private ObjectId _id5 = ObjectId . GenerateNewId ( ) ;
134
135
135
136
[ TestFixtureSetUp ]
136
137
public void Setup ( )
@@ -143,11 +144,11 @@ public void Setup()
143
144
144
145
// documents inserted deliberately out of order to test sorting
145
146
_collection . Drop ( ) ;
146
- _collection . Insert ( new C { Id = id2 , X = 2 , Y = 11 , D = new D { Z = 22 } , A = new [ ] { 2 , 3 , 4 } , L = new List < int > { 2 , 3 , 4 } } ) ;
147
- _collection . Insert ( new C { Id = id1 , X = 1 , Y = 11 , D = new D { Z = 11 } , S = "x is 1" , SA = new string [ ] { "Tom" , "Dick" , "Harry" } } ) ;
148
- _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 } } ) ;
149
- _collection . Insert ( new C { Id = id5 , X = 5 , Y = 44 , D = new D { Z = 55 } , DBRef = new MongoDBRef ( "db" , "c" , 1 ) } ) ;
150
- _collection . Insert ( new C { Id = id4 , X = 4 , Y = 44 , D = new D { Z = 44 } } ) ;
147
+ _collection . Insert ( new C { Id = _id2 , X = 2 , Y = 11 , D = new D { Z = 22 } , A = new [ ] { 2 , 3 , 4 } , L = new List < int > { 2 , 3 , 4 } } ) ;
148
+ _collection . Insert ( new C { Id = _id1 , X = 1 , Y = 11 , D = new D { Z = 11 } , S = "x is 1" , SA = new string [ ] { "Tom" , "Dick" , "Harry" } } ) ;
149
+ _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 } } ) ;
150
+ _collection . Insert ( new C { Id = _id5 , X = 5 , Y = 44 , D = new D { Z = 55 } , DBRef = new MongoDBRef ( "db" , "c" , 1 ) } ) ;
151
+ _collection . Insert ( new C { Id = _id4 , X = 4 , Y = 44 , D = new D { Z = 44 } } ) ;
151
152
}
152
153
153
154
[ Test ]
@@ -480,11 +481,11 @@ public void TestDistinctId()
480
481
select c . Id ) . Distinct ( ) ;
481
482
var results = query . ToList ( ) ;
482
483
Assert . AreEqual ( 5 , results . Count ) ;
483
- Assert . IsTrue ( results . Contains ( id1 ) ) ;
484
- Assert . IsTrue ( results . Contains ( id2 ) ) ;
485
- Assert . IsTrue ( results . Contains ( id3 ) ) ;
486
- Assert . IsTrue ( results . Contains ( id4 ) ) ;
487
- Assert . IsTrue ( results . Contains ( id5 ) ) ;
484
+ Assert . IsTrue ( results . Contains ( _id1 ) ) ;
485
+ Assert . IsTrue ( results . Contains ( _id2 ) ) ;
486
+ Assert . IsTrue ( results . Contains ( _id3 ) ) ;
487
+ Assert . IsTrue ( results . Contains ( _id4 ) ) ;
488
+ Assert . IsTrue ( results . Contains ( _id5 ) ) ;
488
489
}
489
490
490
491
[ Test ]
@@ -1178,35 +1179,119 @@ public void TestLongCountWithSkipAndTake()
1178
1179
}
1179
1180
1180
1181
[ Test ]
1181
- [ ExpectedException ( typeof ( InvalidOperationException ) , ExpectedMessage = "The Max query operator is not supported." ) ]
1182
- public void TestMax ( )
1182
+ public void TestMaxDZWithProjection ( )
1183
+ {
1184
+ var result = ( from c in _collection . AsQueryable < C > ( )
1185
+ select c . D . Z ) . Max ( ) ;
1186
+ Assert . AreEqual ( 55 , result ) ;
1187
+ }
1188
+
1189
+ [ Test ]
1190
+ public void TestMaxDZWithSelector ( )
1191
+ {
1192
+ var result = ( from c in _collection . AsQueryable < C > ( )
1193
+ select c ) . Max ( c => c . D . Z ) ;
1194
+ Assert . AreEqual ( 55 , result ) ;
1195
+ }
1196
+
1197
+ [ Test ]
1198
+ [ ExpectedException ( typeof ( NotSupportedException ) , ExpectedMessage = "Max must be used with either Select or a selector argument, but not both." ) ]
1199
+ public void TestMaxWithProjectionAndSelector ( )
1200
+ {
1201
+ var result = ( from c in _collection . AsQueryable < C > ( )
1202
+ select c . D ) . Max ( d => d . Z ) ;
1203
+ }
1204
+
1205
+ [ Test ]
1206
+ public void TestMaxXWithProjection ( )
1183
1207
{
1184
1208
var result = ( from c in _collection . AsQueryable < C > ( )
1185
- select c ) . Max ( ) ;
1209
+ select c . X ) . Max ( ) ;
1210
+ Assert . AreEqual ( 5 , result ) ;
1211
+ }
1212
+
1213
+ [ Test ]
1214
+ public void TestMaxXWithSelector ( )
1215
+ {
1216
+ var result = ( from c in _collection . AsQueryable < C > ( )
1217
+ select c ) . Max ( c => c . X ) ;
1218
+ Assert . AreEqual ( 5 , result ) ;
1219
+ }
1220
+
1221
+ [ Test ]
1222
+ public void TestMaxXYWithProjection ( )
1223
+ {
1224
+ var result = ( from c in _collection . AsQueryable < C > ( )
1225
+ select new { c . X , c . Y } ) . Max ( ) ;
1226
+ Assert . AreEqual ( 5 , result . X ) ;
1227
+ Assert . AreEqual ( 44 , result . Y ) ;
1186
1228
}
1187
1229
1188
1230
[ Test ]
1189
- [ ExpectedException ( typeof ( InvalidOperationException ) , ExpectedMessage = "The Max query operator is not supported." ) ]
1190
- public void TestMaxWithSelector ( )
1231
+ public void TestMaxXYWithSelector ( )
1191
1232
{
1192
1233
var result = ( from c in _collection . AsQueryable < C > ( )
1193
- select c ) . Max ( c => 1.0 ) ;
1234
+ select c ) . Max ( c => new { c . X , c . Y } ) ;
1235
+ Assert . AreEqual ( 5 , result . X ) ;
1236
+ Assert . AreEqual ( 44 , result . Y ) ;
1194
1237
}
1195
1238
1196
1239
[ Test ]
1197
- [ ExpectedException ( typeof ( InvalidOperationException ) , ExpectedMessage = "The Min query operator is not supported." ) ]
1198
- public void TestMin ( )
1240
+ public void TestMinDZWithProjection ( )
1199
1241
{
1200
1242
var result = ( from c in _collection . AsQueryable < C > ( )
1201
- select c ) . Min ( ) ;
1243
+ select c . D . Z ) . Min ( ) ;
1244
+ Assert . AreEqual ( 11 , result ) ;
1202
1245
}
1203
1246
1204
1247
[ Test ]
1205
- [ ExpectedException ( typeof ( InvalidOperationException ) , ExpectedMessage = "The Min query operator is not supported." ) ]
1206
- public void TestMinWithSelector ( )
1248
+ public void TestMinDZWithSelector ( )
1207
1249
{
1208
1250
var result = ( from c in _collection . AsQueryable < C > ( )
1209
- select c ) . Min ( c => 1.0 ) ;
1251
+ select c ) . Min ( c => c . D . Z ) ;
1252
+ Assert . AreEqual ( 11 , result ) ;
1253
+ }
1254
+
1255
+ [ Test ]
1256
+ [ ExpectedException ( typeof ( NotSupportedException ) , ExpectedMessage = "Min must be used with either Select or a selector argument, but not both." ) ]
1257
+ public void TestMinWithProjectionAndSelector ( )
1258
+ {
1259
+ var result = ( from c in _collection . AsQueryable < C > ( )
1260
+ select c . D ) . Min ( d => d . Z ) ;
1261
+ }
1262
+
1263
+ [ Test ]
1264
+ public void TestMinXWithProjection ( )
1265
+ {
1266
+ var result = ( from c in _collection . AsQueryable < C > ( )
1267
+ select c . X ) . Min ( ) ;
1268
+ Assert . AreEqual ( 1 , result ) ;
1269
+ }
1270
+
1271
+ [ Test ]
1272
+ public void TestMinXWithSelector ( )
1273
+ {
1274
+ var result = ( from c in _collection . AsQueryable < C > ( )
1275
+ select c ) . Min ( c => c . X ) ;
1276
+ Assert . AreEqual ( 1 , result ) ;
1277
+ }
1278
+
1279
+ [ Test ]
1280
+ public void TestMinXYWithProjection ( )
1281
+ {
1282
+ var result = ( from c in _collection . AsQueryable < C > ( )
1283
+ select new { c . X , c . Y } ) . Min ( ) ;
1284
+ Assert . AreEqual ( 1 , result . X ) ;
1285
+ Assert . AreEqual ( 11 , result . Y ) ;
1286
+ }
1287
+
1288
+ [ Test ]
1289
+ public void TestMinXYWithSelector ( )
1290
+ {
1291
+ var result = ( from c in _collection . AsQueryable < C > ( )
1292
+ select c ) . Min ( c => new { c . X , c . Y } ) ;
1293
+ Assert . AreEqual ( 1 , result . X ) ;
1294
+ Assert . AreEqual ( 11 , result . Y ) ;
1210
1295
}
1211
1296
1212
1297
[ Test ]
0 commit comments