PageRenderTime 58ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/MongoDB.DriverUnitTestsVB/Linq/SelectQueryTests.vb

https://github.com/alistair/mongo-csharp-driver
Visual Basic | 6675 lines | 5290 code | 1325 blank | 60 comment | 13 complexity | 93c4bfa458b3f004a7003cdda0b87696 MD5 | raw file
Possible License(s): Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. ' Copyright 2010-2013 10gen Inc.
  2. '*
  3. '* Licensed under the Apache License, Version 2.0 (the "License");
  4. '* you may not use this file except in compliance with the License.
  5. '* You may obtain a copy of the License at
  6. '*
  7. '* http://www.apache.org/licenses/LICENSE-2.0
  8. '*
  9. '* Unless required by applicable law or agreed to in writing, software
  10. '* distributed under the License is distributed on an "AS IS" BASIS,
  11. '* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. '* See the License for the specific language governing permissions and
  13. '* limitations under the License.
  14. '
  15. Imports System
  16. Imports System.Collections.Generic
  17. Imports System.Linq
  18. Imports System.Text
  19. Imports System.Text.RegularExpressions
  20. Imports NUnit.Framework
  21. Imports MongoDB.Bson
  22. Imports MongoDB.Bson.Serialization.Attributes
  23. Imports MongoDB.Driver
  24. Imports MongoDB.Driver.Builders
  25. Imports MongoDB.Driver.Linq
  26. Imports System.Linq.Expressions
  27. Namespace MongoDB.DriverUnitTests.Linq
  28. <TestFixture()> _
  29. Public Class SelectQueryTests
  30. Public Enum E
  31. None
  32. A
  33. B
  34. C
  35. End Enum
  36. Public Class C
  37. Public Property Id() As ObjectId
  38. <BsonElement("x")> _
  39. Public Property X() As Integer
  40. <BsonElement("lx")> _
  41. Public Property LX() As Long
  42. <BsonElement("y")> _
  43. Public Property Y() As Integer
  44. <BsonElement("d")> _
  45. Public Property D() As D
  46. <BsonElement("da")> _
  47. Public Property DA() As List(Of D)
  48. <BsonElement("s")> _
  49. <BsonIgnoreIfNull()> _
  50. Public Property S() As String
  51. <BsonElement("a")> _
  52. <BsonIgnoreIfNull()> _
  53. Public Property A() As Integer()
  54. <BsonElement("b")> _
  55. Public Property B() As Boolean
  56. <BsonElement("l")> _
  57. <BsonIgnoreIfNull()> _
  58. Public Property L() As List(Of Integer)
  59. <BsonElement("dbref")> _
  60. <BsonIgnoreIfNull()> _
  61. Public Property DBRef() As MongoDBRef
  62. <BsonElement("e")> _
  63. <BsonIgnoreIfDefault()> _
  64. <BsonRepresentation(BsonType.[String])> _
  65. Public Property E() As E
  66. <BsonElement("ea")> _
  67. <BsonIgnoreIfNull()> _
  68. Public Property EA() As E()
  69. <BsonElement("sa")> _
  70. <BsonIgnoreIfNull()> _
  71. Public Property SA() As String()
  72. <BsonElement("ba")> _
  73. <BsonIgnoreIfNull()> _
  74. Public Property BA() As Boolean()
  75. End Class
  76. Public Class D
  77. <BsonElement("z")> _
  78. Public Z As Integer
  79. ' use field instead of property to test fields also
  80. Public Overrides Function Equals(ByVal obj As Object) As Boolean
  81. If obj Is Nothing OrElse Not obj.GetType().Equals(GetType(D)) Then
  82. Return False
  83. End If
  84. Return Z = DirectCast(obj, D).Z
  85. End Function
  86. Public Overrides Function GetHashCode() As Integer
  87. Return Z.GetHashCode()
  88. End Function
  89. Public Overrides Function ToString() As String
  90. Return String.Format("new D {{ Z = {0} }}", Z)
  91. End Function
  92. End Class
  93. ' used to test some query operators that have an IEqualityComparer parameter
  94. Private Class CEqualityComparer
  95. Implements IEqualityComparer(Of C)
  96. Public Function Equals1(ByVal x As C, ByVal y As C) As Boolean Implements IEqualityComparer(Of C).Equals
  97. Return x.Id.Equals(y.Id) AndAlso x.X.Equals(y.X) AndAlso x.Y.Equals(y.Y)
  98. End Function
  99. Public Function GetHashCode1(ByVal obj As C) As Integer Implements IEqualityComparer(Of C).GetHashCode
  100. Return obj.GetHashCode()
  101. End Function
  102. End Class
  103. ' used to test some query operators that have an IEqualityComparer parameter
  104. Private Class Int32EqualityComparer
  105. Implements IEqualityComparer(Of Integer)
  106. Public Function Equals1(ByVal x As Integer, ByVal y As Integer) As Boolean Implements IEqualityComparer(Of Integer).Equals
  107. Return x = y
  108. End Function
  109. Public Function GetHashCode1(ByVal obj As Integer) As Integer Implements IEqualityComparer(Of Integer).GetHashCode
  110. Return obj.GetHashCode()
  111. End Function
  112. End Class
  113. Private _server As MongoServer
  114. Private _database As MongoDatabase
  115. Private _collection As MongoCollection(Of C)
  116. Private _systemProfileCollection As MongoCollection(Of SystemProfileInfo)
  117. Private _id1 As ObjectId = ObjectId.GenerateNewId()
  118. Private _id2 As ObjectId = ObjectId.GenerateNewId()
  119. Private _id3 As ObjectId = ObjectId.GenerateNewId()
  120. Private _id4 As ObjectId = ObjectId.GenerateNewId()
  121. Private _id5 As ObjectId = ObjectId.GenerateNewId()
  122. <TestFixtureSetUp()> _
  123. Public Sub Setup()
  124. _server = Configuration.TestServer
  125. _server.Connect()
  126. _database = Configuration.TestDatabase
  127. _collection = Configuration.GetTestCollection(Of C)()
  128. _systemProfileCollection = _database.GetCollection(Of SystemProfileInfo)("system.profile")
  129. ' documents inserted deliberately out of order to test sorting
  130. _collection.Drop()
  131. _collection.Insert(New C() With
  132. {
  133. .Id = _id2,
  134. .X = 2,
  135. .LX = 2,
  136. .Y = 11,
  137. .D = New D() With {.Z = 22},
  138. .A = {2, 3, 4},
  139. .L = New List(Of Integer)({2, 3, 4})
  140. })
  141. _collection.Insert(New C() With
  142. {
  143. .Id = _id1,
  144. .X = 1,
  145. .LX = 1,
  146. .Y = 11,
  147. .D = New D() With {.Z = 11},
  148. .S = "abc",
  149. .SA = {"Tom", "Dick", "Harry"}
  150. })
  151. _collection.Insert(New C() With
  152. {
  153. .Id = _id3,
  154. .X = 3,
  155. .LX = 3,
  156. .Y = 33,
  157. .D = New D() With {.Z = 33},
  158. .B = True,
  159. .BA = {True},
  160. .E = E.A,
  161. .EA = New E() {E.A, E.B}
  162. })
  163. _collection.Insert(New C() With
  164. {
  165. .Id = _id5,
  166. .X = 5,
  167. .LX = 5,
  168. .Y = 44,
  169. .D = New D() With {.Z = 55},
  170. .DBRef = New MongoDBRef("db", "c", 1)
  171. })
  172. _collection.Insert(New C() With
  173. {
  174. .Id = _id4,
  175. .X = 4,
  176. .LX = 4,
  177. .Y = 44,
  178. .D = New D() With {.Z = 44},
  179. .DA = {New D() With {.Z = 333}}.ToList,
  180. .S = " xyz "
  181. })
  182. End Sub
  183. <Test()> _
  184. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The Aggregate query operator is not supported.")> _
  185. Public Sub TestAggregate()
  186. Dim result = (From c In _collection.AsQueryable(Of C)()
  187. Select c).Aggregate(Function(a, b) Nothing)
  188. End Sub
  189. <Test()> _
  190. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The Aggregate query operator is not supported.")> _
  191. Public Sub TestAggregateWithAccumulator()
  192. Dim result = (From c In _collection.AsQueryable(Of C)()
  193. Select c).Aggregate(0, Function(a, c) 0)
  194. End Sub
  195. <Test()> _
  196. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The Aggregate query operator is not supported.")> _
  197. Public Sub TestAggregateWithAccumulatorAndSelector()
  198. Dim result = (From c In _collection.AsQueryable(Of C)()
  199. Select c).Aggregate(0, Function(a, c) 0, Function(a) a)
  200. End Sub
  201. <Test()> _
  202. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The All query operator is not supported.")> _
  203. Public Sub TestAll()
  204. Dim result = (From c In _collection.AsQueryable(Of C)()
  205. Select c).All(Function(c) True)
  206. End Sub
  207. <Test()> _
  208. Public Sub TestAny()
  209. Dim result = (From c In _collection.AsQueryable(Of C)()
  210. Select c).Any()
  211. Assert.IsTrue(result)
  212. End Sub
  213. <Test()> _
  214. Public Sub TestAnyWhereXEquals1()
  215. Dim result = (From c In _collection.AsQueryable(Of C)()
  216. Where c.X = 1
  217. Select c).Any()
  218. Assert.IsTrue(result)
  219. End Sub
  220. <Test()> _
  221. Public Sub TestAnyWhereXEquals9()
  222. Dim result = (From c In _collection.AsQueryable(Of C)()
  223. Where c.X = 9
  224. Select c).Any()
  225. Assert.IsFalse(result)
  226. End Sub
  227. <Test()> _
  228. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="Any with predicate after a projection is not supported.")> _
  229. Public Sub TestAnyWithPredicateAfterProjection()
  230. Dim result = _collection.AsQueryable(Of C)().[Select](Function(c) c.Y).Any(Function(y) y = 11)
  231. End Sub
  232. <Test()> _
  233. Public Sub TestAnyWithPredicateAfterWhere()
  234. Dim result = _collection.AsQueryable(Of C)().Where(Function(c) c.X = 1).Any(Function(c) c.Y = 11)
  235. Assert.IsTrue(result)
  236. End Sub
  237. <Test()> _
  238. Public Sub TestAnyWithPredicateFalse()
  239. Dim result = _collection.AsQueryable(Of C)().Any(Function(c) c.X = 9)
  240. Assert.IsFalse(result)
  241. End Sub
  242. <Test()> _
  243. Public Sub TestAnyWithPredicateTrue()
  244. Dim result = _collection.AsQueryable(Of C)().Any(Function(c) c.X = 1)
  245. Assert.IsTrue(result)
  246. End Sub
  247. <Test()> _
  248. Public Sub TestAsQueryableWithNothingElse()
  249. Dim query = _collection.AsQueryable(Of C)()
  250. Dim result = query.ToList()
  251. Assert.AreEqual(5, result.Count)
  252. End Sub
  253. <Test()> _
  254. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The Average query operator is not supported.")> _
  255. Public Sub TestAverage()
  256. Dim result = (From c In _collection.AsQueryable(Of C)()
  257. Select 1.0).Average()
  258. End Sub
  259. <Test()> _
  260. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The Average query operator is not supported.")> _
  261. Public Sub TestAverageNullable()
  262. Dim result = (From c In _collection.AsQueryable(Of C)()
  263. Select New Nullable(Of Decimal)(1.0)).Average()
  264. End Sub
  265. <Test()> _
  266. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The Average query operator is not supported.")> _
  267. Public Sub TestAverageWithSelector()
  268. Dim result = (From c In _collection.AsQueryable(Of C)()
  269. Select c).Average(Function(c) 1.0)
  270. End Sub
  271. <Test()> _
  272. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The Average query operator is not supported.")> _
  273. Public Sub TestAverageWithSelectorNullable()
  274. Dim result = (From c In _collection.AsQueryable(Of C)()
  275. Select c).Average(Function(c) New Nullable(Of Decimal)(1.0))
  276. End Sub
  277. <Test()> _
  278. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The Cast query operator is not supported.")> _
  279. Public Sub TestCast()
  280. Dim query = (From c In _collection.AsQueryable(Of C)()
  281. Select C).Cast(Of C)()
  282. query.ToList()
  283. ' execute query
  284. End Sub
  285. <Test()> _
  286. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The Concat query operator is not supported.")> _
  287. Public Sub TestConcat()
  288. Dim source2 = New C(-1) {}
  289. Dim query = (From c In _collection.AsQueryable(Of C)()
  290. Select c).Concat(source2)
  291. query.ToList()
  292. ' execute query
  293. End Sub
  294. <Test()> _
  295. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The Contains query operator is not supported.")> _
  296. Public Sub TestContains()
  297. Dim item = New C()
  298. Dim result = (From c In _collection.AsQueryable(Of C)()
  299. Select c).Contains(item)
  300. End Sub
  301. <Test()> _
  302. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The Contains query operator is not supported.")> _
  303. Public Sub TestContainsWithEqualityComparer()
  304. Dim item = New C()
  305. Dim result = (From c In _collection.AsQueryable(Of C)()
  306. Select c).Contains(item, New CEqualityComparer())
  307. End Sub
  308. <Test()> _
  309. Public Sub TestCountEquals2()
  310. Dim result = (From c In _collection.AsQueryable(Of C)()
  311. Where c.Y = 11
  312. Select c).Count()
  313. Assert.AreEqual(2, result)
  314. End Sub
  315. <Test()> _
  316. Public Sub TestCountEquals5()
  317. Dim result = (From c In _collection.AsQueryable(Of C)()
  318. Select c).Count()
  319. Assert.AreEqual(5, result)
  320. End Sub
  321. <Test()> _
  322. Public Sub TestCountWithPredicate()
  323. Dim result = _collection.AsQueryable(Of C)().Count(Function(c) c.Y = 11)
  324. Assert.AreEqual(2, result)
  325. End Sub
  326. <Test()> _
  327. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="Count with predicate after a projection is not supported.")> _
  328. Public Sub TestCountWithPredicateAfterProjection()
  329. Dim result = _collection.AsQueryable(Of C)().[Select](Function(c) c.Y).Count(Function(y) y = 11)
  330. End Sub
  331. <Test()> _
  332. Public Sub TestCountWithPredicateAfterWhere()
  333. Dim result = _collection.AsQueryable(Of C)().Where(Function(c) c.X = 1).Count(Function(c) c.Y = 11)
  334. Assert.AreEqual(1, result)
  335. End Sub
  336. <Test()> _
  337. Public Sub TestCountWithSkipAndTake()
  338. Dim result = (From c In _collection.AsQueryable(Of C)()
  339. Select c).Skip(2).Take(2).Count()
  340. Assert.AreEqual(2, result)
  341. End Sub
  342. <Test()> _
  343. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The DefaultIfEmpty query operator is not supported.")> _
  344. Public Sub TestDefaultIfEmpty()
  345. Dim query = (From c In _collection.AsQueryable(Of C)()
  346. Select c).DefaultIfEmpty()
  347. query.ToList()
  348. ' execute query
  349. End Sub
  350. <Test()> _
  351. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The DefaultIfEmpty query operator is not supported.")> _
  352. Public Sub TestDefaultIfEmptyWithDefaultValue()
  353. Dim query = (From c In _collection.AsQueryable(Of C)()
  354. Select c).DefaultIfEmpty(Nothing)
  355. query.ToList()
  356. ' execute query
  357. End Sub
  358. <Test()> _
  359. Public Sub TestDistinctASub0()
  360. Dim query = (From c In _collection.AsQueryable(Of C)()
  361. Select c.A(0)).Distinct()
  362. Dim results = query.ToList()
  363. Assert.AreEqual(1, results.Count)
  364. Assert.IsTrue(results.Contains(2))
  365. End Sub
  366. <Test()> _
  367. Public Sub TestDistinctB()
  368. Dim query = (From c In _collection.AsQueryable(Of C)()
  369. Select c.B).Distinct()
  370. Dim results = query.ToList()
  371. Assert.AreEqual(2, results.Count)
  372. Assert.IsTrue(results.Contains(False))
  373. Assert.IsTrue(results.Contains(True))
  374. End Sub
  375. <Test()> _
  376. Public Sub TestDistinctBASub0()
  377. Dim query = (From c In _collection.AsQueryable(Of C)()
  378. Select c.BA(0)).Distinct()
  379. Dim results = query.ToList()
  380. Assert.AreEqual(1, results.Count)
  381. Assert.IsTrue(results.Contains(True))
  382. End Sub
  383. <Test()> _
  384. Public Sub TestDistinctD()
  385. Dim query = (From c In _collection.AsQueryable(Of C)()
  386. Select c.D).Distinct()
  387. Dim results = query.ToList()
  388. ' execute query
  389. Assert.AreEqual(5, results.Count)
  390. Assert.IsTrue(results.Contains(New D() With { _
  391. .Z = 11 _
  392. }))
  393. Assert.IsTrue(results.Contains(New D() With { _
  394. .Z = 22 _
  395. }))
  396. Assert.IsTrue(results.Contains(New D() With { _
  397. .Z = 33 _
  398. }))
  399. Assert.IsTrue(results.Contains(New D() With { _
  400. .Z = 44 _
  401. }))
  402. Assert.IsTrue(results.Contains(New D() With { _
  403. .Z = 55 _
  404. }))
  405. End Sub
  406. <Test()> _
  407. Public Sub TestDistinctDBRef()
  408. Dim query = (From c In _collection.AsQueryable(Of C)()
  409. Select c.DBRef).Distinct()
  410. Dim results = query.ToList()
  411. Assert.AreEqual(1, results.Count)
  412. Assert.IsTrue(results.Contains(New MongoDBRef("db", "c", 1)))
  413. End Sub
  414. <Test()> _
  415. Public Sub TestDistinctDBRefDatabase()
  416. Dim query = (From c In _collection.AsQueryable(Of C)()
  417. Select c.DBRef.DatabaseName).Distinct()
  418. Dim results = query.ToList()
  419. Assert.AreEqual(1, results.Count)
  420. Assert.IsTrue(results.Contains("db"))
  421. End Sub
  422. <Test()> _
  423. Public Sub TestDistinctDZ()
  424. Dim query = (From c In _collection.AsQueryable(Of C)()
  425. Select c.D.Z).Distinct()
  426. Dim results = query.ToList()
  427. Assert.AreEqual(5, results.Count)
  428. Assert.IsTrue(results.Contains(11))
  429. Assert.IsTrue(results.Contains(22))
  430. Assert.IsTrue(results.Contains(33))
  431. Assert.IsTrue(results.Contains(44))
  432. Assert.IsTrue(results.Contains(55))
  433. End Sub
  434. <Test()> _
  435. Public Sub TestDistinctE()
  436. Dim query = (From c In _collection.AsQueryable(Of C)()
  437. Select c.E).Distinct()
  438. Dim results = query.ToList()
  439. Assert.AreEqual(1, results.Count)
  440. Assert.IsTrue(results.Contains(E.A))
  441. End Sub
  442. <Test()> _
  443. Public Sub TestDistinctEASub0()
  444. Dim query = (From c In _collection.AsQueryable(Of C)()
  445. Select c.EA(0)).Distinct()
  446. Dim results = query.ToList()
  447. Assert.AreEqual(1, results.Count)
  448. Assert.IsTrue(results.Contains(E.A))
  449. End Sub
  450. <Test()> _
  451. Public Sub TestDistinctId()
  452. Dim query = (From c In _collection.AsQueryable(Of C)()
  453. Select c.Id).Distinct()
  454. Dim results = query.ToList()
  455. Assert.AreEqual(5, results.Count)
  456. Assert.IsTrue(results.Contains(_id1))
  457. Assert.IsTrue(results.Contains(_id2))
  458. Assert.IsTrue(results.Contains(_id3))
  459. Assert.IsTrue(results.Contains(_id4))
  460. Assert.IsTrue(results.Contains(_id5))
  461. End Sub
  462. <Test()> _
  463. Public Sub TestDistinctLSub0()
  464. Dim query = (From c In _collection.AsQueryable(Of C)()
  465. Select c.L(0)).Distinct()
  466. Dim results = query.ToList()
  467. Assert.AreEqual(1, results.Count)
  468. Assert.IsTrue(results.Contains(2))
  469. End Sub
  470. <Test()> _
  471. Public Sub TestDistinctS()
  472. Dim query = (From c In _collection.AsQueryable(Of C)()
  473. Select c.S).Distinct()
  474. Dim results = query.ToList()
  475. Assert.AreEqual(2, results.Count)
  476. Assert.IsTrue(results.Contains("abc"))
  477. Assert.IsTrue(results.Contains(" xyz "))
  478. End Sub
  479. <Test()> _
  480. Public Sub TestDistinctSASub0()
  481. Dim query = (From c In _collection.AsQueryable(Of C)()
  482. Select c.SA(0)).Distinct()
  483. Dim results = query.ToList()
  484. Assert.AreEqual(1, results.Count)
  485. Assert.IsTrue(results.Contains("Tom"))
  486. End Sub
  487. <Test()> _
  488. Public Sub TestDistinctX()
  489. Dim query = (From c In _collection.AsQueryable(Of C)()
  490. Select c.X).Distinct()
  491. Dim results = query.ToList()
  492. Assert.AreEqual(5, results.Count)
  493. Assert.IsTrue(results.Contains(1))
  494. Assert.IsTrue(results.Contains(2))
  495. Assert.IsTrue(results.Contains(3))
  496. Assert.IsTrue(results.Contains(4))
  497. Assert.IsTrue(results.Contains(5))
  498. End Sub
  499. <Test()> _
  500. Public Sub TestDistinctXWithQuery()
  501. Dim query = (From c In _collection.AsQueryable(Of C)()
  502. Where c.X > 3
  503. Select c.X).Distinct()
  504. Dim results = query.ToList()
  505. Assert.AreEqual(2, results.Count)
  506. Assert.IsTrue(results.Contains(4))
  507. Assert.IsTrue(results.Contains(5))
  508. End Sub
  509. <Test()> _
  510. Public Sub TestDistinctY()
  511. Dim query = (From c In _collection.AsQueryable(Of C)()
  512. Select c.Y).Distinct()
  513. Dim results = query.ToList()
  514. Assert.AreEqual(3, results.Count)
  515. Assert.IsTrue(results.Contains(11))
  516. Assert.IsTrue(results.Contains(33))
  517. Assert.IsTrue(results.Contains(44))
  518. End Sub
  519. <Test()> _
  520. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The version of the Distinct query operator with an equality comparer is not supported.")> _
  521. Public Sub TestDistinctWithEqualityComparer()
  522. Dim query = _collection.AsQueryable(Of C)().Distinct(New CEqualityComparer())
  523. query.ToList()
  524. ' execute query
  525. End Sub
  526. <Test()> _
  527. Public Sub TestElementAtOrDefaultWithManyMatches()
  528. Dim result = (From c In _collection.AsQueryable(Of C)()
  529. Select c).ElementAtOrDefault(2)
  530. Assert.AreEqual(3, result.X)
  531. Assert.AreEqual(33, result.Y)
  532. End Sub
  533. <Test()> _
  534. Public Sub TestElementAtOrDefaultWithNoMatch()
  535. Dim result = (From c In _collection.AsQueryable(Of C)()
  536. Where c.X = 9
  537. Select c).ElementAtOrDefault(0)
  538. Assert.IsNull(result)
  539. End Sub
  540. <Test()> _
  541. Public Sub TestElementAtOrDefaultWithOneMatch()
  542. Dim result = (From c In _collection.AsQueryable(Of C)()
  543. Where c.X = 3
  544. Select c).ElementAtOrDefault(0)
  545. Assert.AreEqual(3, result.X)
  546. Assert.AreEqual(33, result.Y)
  547. End Sub
  548. <Test()> _
  549. Public Sub TestElementAtOrDefaultWithTwoMatches()
  550. Dim result = (From c In _collection.AsQueryable(Of C)()
  551. Where c.Y = 11
  552. Select c).ElementAtOrDefault(1)
  553. Assert.AreEqual(1, result.X)
  554. Assert.AreEqual(11, result.Y)
  555. End Sub
  556. <Test()> _
  557. Public Sub TestElementAtWithManyMatches()
  558. Dim result = (From c In _collection.AsQueryable(Of C)()
  559. Select c).ElementAt(2)
  560. Assert.AreEqual(3, result.X)
  561. Assert.AreEqual(33, result.Y)
  562. End Sub
  563. <Test()> _
  564. <ExpectedException(GetType(InvalidOperationException))> _
  565. Public Sub TestElementAtWithNoMatch()
  566. Dim result = (From c In _collection.AsQueryable(Of C)()
  567. Where c.X = 9
  568. Select c).ElementAt(0)
  569. End Sub
  570. <Test()> _
  571. Public Sub TestElementAtWithOneMatch()
  572. Dim result = (From c In _collection.AsQueryable(Of C)()
  573. Where c.X = 3
  574. Select c).ElementAt(0)
  575. Assert.AreEqual(3, result.X)
  576. Assert.AreEqual(33, result.Y)
  577. End Sub
  578. <Test()> _
  579. Public Sub TestElementAtWithTwoMatches()
  580. Dim result = (From c In _collection.AsQueryable(Of C)()
  581. Where c.Y = 11
  582. Select c).ElementAt(1)
  583. Assert.AreEqual(1, result.X)
  584. Assert.AreEqual(11, result.Y)
  585. End Sub
  586. <Test()> _
  587. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The Except query operator is not supported.")> _
  588. Public Sub TestExcept()
  589. Dim source2 = New C(-1) {}
  590. Dim query = (From c In _collection.AsQueryable(Of C)()
  591. Select c).Except(source2)
  592. query.ToList()
  593. ' execute query
  594. End Sub
  595. <Test()> _
  596. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The Except query operator is not supported.")> _
  597. Public Sub TestExceptWithEqualityComparer()
  598. Dim source2 = New C(-1) {}
  599. Dim query = (From c In _collection.AsQueryable(Of C)()
  600. Select c).Except(source2, New CEqualityComparer())
  601. query.ToList()
  602. ' execute query
  603. End Sub
  604. <Test()> _
  605. Public Sub TestFirstOrDefaultWithManyMatches()
  606. Dim result = (From c In _collection.AsQueryable(Of C)()
  607. Select c).FirstOrDefault()
  608. Assert.AreEqual(2, result.X)
  609. Assert.AreEqual(11, result.Y)
  610. End Sub
  611. <Test()> _
  612. Public Sub TestFirstOrDefaultWithNoMatch()
  613. Dim result = (From c In _collection.AsQueryable(Of C)()
  614. Where c.X = 9
  615. Select c).FirstOrDefault()
  616. Assert.IsNull(result)
  617. End Sub
  618. <Test()> _
  619. Public Sub TestFirstOrDefaultWithOneMatch()
  620. Dim result = (From c In _collection.AsQueryable(Of C)()
  621. Where c.X = 3
  622. Select c).FirstOrDefault()
  623. Assert.AreEqual(3, result.X)
  624. Assert.AreEqual(33, result.Y)
  625. End Sub
  626. <Test()> _
  627. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="FirstOrDefault with predicate after a projection is not supported.")> _
  628. Public Sub TestFirstOrDefaultWithPredicateAfterProjection()
  629. Dim result = _collection.AsQueryable(Of C)().[Select](Function(c) c.Y).FirstOrDefault(Function(y) y = 11)
  630. End Sub
  631. <Test()> _
  632. Public Sub TestFirstOrDefaultWithPredicateAfterWhere()
  633. Dim result = (From c In _collection.AsQueryable(Of C)()
  634. Where c.X = 1
  635. Select c).FirstOrDefault(Function(c) c.Y = 11)
  636. Assert.AreEqual(1, result.X)
  637. Assert.AreEqual(11, result.Y)
  638. End Sub
  639. <Test()> _
  640. Public Sub TestFirstOrDefaultWithPredicateNoMatch()
  641. Dim result = (From c In _collection.AsQueryable(Of C)()
  642. Select c).FirstOrDefault(Function(c) c.X = 9)
  643. Assert.IsNull(result)
  644. End Sub
  645. <Test()> _
  646. Public Sub TestFirstOrDefaultWithPredicateOneMatch()
  647. Dim result = (From c In _collection.AsQueryable(Of C)()
  648. Select c).FirstOrDefault(Function(c) c.X = 3)
  649. Assert.AreEqual(3, result.X)
  650. Assert.AreEqual(33, result.Y)
  651. End Sub
  652. <Test()> _
  653. Public Sub TestFirstOrDefaultWithPredicateTwoMatches()
  654. Dim result = (From c In _collection.AsQueryable(Of C)()
  655. Select c).FirstOrDefault(Function(c) c.Y = 11)
  656. Assert.AreEqual(2, result.X)
  657. Assert.AreEqual(11, result.Y)
  658. End Sub
  659. <Test()> _
  660. Public Sub TestFirstOrDefaultWithTwoMatches()
  661. Dim result = (From c In _collection.AsQueryable(Of C)()
  662. Where c.Y = 11
  663. Select c).FirstOrDefault()
  664. Assert.AreEqual(2, result.X)
  665. Assert.AreEqual(11, result.Y)
  666. End Sub
  667. <Test()> _
  668. Public Sub TestFirstWithManyMatches()
  669. Dim result = (From c In _collection.AsQueryable(Of C)()
  670. Select c).First()
  671. Assert.AreEqual(2, result.X)
  672. Assert.AreEqual(11, result.Y)
  673. End Sub
  674. <Test()> _
  675. <ExpectedException(GetType(InvalidOperationException))> _
  676. Public Sub TestFirstWithNoMatch()
  677. Dim result = (From c In _collection.AsQueryable(Of C)()
  678. Where c.X = 9
  679. Select c).First()
  680. End Sub
  681. <Test()> _
  682. Public Sub TestFirstWithOneMatch()
  683. Dim result = (From c In _collection.AsQueryable(Of C)()
  684. Where c.X = 3
  685. Select c).First()
  686. Assert.AreEqual(3, result.X)
  687. Assert.AreEqual(33, result.Y)
  688. End Sub
  689. <Test()> _
  690. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="First with predicate after a projection is not supported.")> _
  691. Public Sub TestFirstWithPredicateAfterProjection()
  692. Dim result = _collection.AsQueryable(Of C)().[Select](Function(c) c.Y).First(Function(y) y = 11)
  693. End Sub
  694. <Test()> _
  695. Public Sub TestFirstWithPredicateAfterWhere()
  696. Dim result = (From c In _collection.AsQueryable(Of C)()
  697. Where c.X = 1
  698. Select c).First(Function(c) c.Y = 11)
  699. Assert.AreEqual(1, result.X)
  700. Assert.AreEqual(11, result.Y)
  701. End Sub
  702. <Test()> _
  703. Public Sub TestFirstWithPredicateNoMatch()
  704. Dim ex = Assert.Throws(Of InvalidOperationException)(Sub()
  705. Dim result = (From c In _collection.AsQueryable(Of C)()
  706. Select c).First(Function(c) c.X = 9)
  707. End Sub)
  708. Assert.AreEqual(ExpectedErrorMessage.FirstEmptySequence, ex.Message)
  709. End Sub
  710. <Test()> _
  711. Public Sub TestFirstWithPredicateOneMatch()
  712. Dim result = (From c In _collection.AsQueryable(Of C)()
  713. Select c).First(Function(c) c.X = 3)
  714. Assert.AreEqual(3, result.X)
  715. Assert.AreEqual(33, result.Y)
  716. End Sub
  717. <Test()> _
  718. Public Sub TestFirstWithPredicateTwoMatches()
  719. Dim result = (From c In _collection.AsQueryable(Of C)()
  720. Select c).First(Function(c) c.Y = 11)
  721. Assert.AreEqual(2, result.X)
  722. Assert.AreEqual(11, result.Y)
  723. End Sub
  724. <Test()> _
  725. Public Sub TestFirstWithTwoMatches()
  726. Dim result = (From c In _collection.AsQueryable(Of C)()
  727. Where c.Y = 11
  728. Select c).First()
  729. Assert.AreEqual(2, result.X)
  730. Assert.AreEqual(11, result.Y)
  731. End Sub
  732. <Test()> _
  733. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The GroupBy query operator is not supported.")> _
  734. Public Sub TestGroupByWithKeySelector()
  735. Dim query = (From c In _collection.AsQueryable(Of C)()
  736. Select c).GroupBy(Function(c) c)
  737. query.ToList()
  738. ' execute query
  739. End Sub
  740. <Test()> _
  741. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The GroupBy query operator is not supported.")> _
  742. Public Sub TestGroupByWithKeySelectorAndElementSelector()
  743. Dim query = (From c In _collection.AsQueryable(Of C)()
  744. Select c).GroupBy(Function(c) c, Function(c) c)
  745. query.ToList()
  746. ' execute query
  747. End Sub
  748. <Test()> _
  749. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The GroupBy query operator is not supported.")> _
  750. Public Sub TestGroupByWithKeySelectorAndElementSelectorAndEqualityComparer()
  751. Dim query = (From c In _collection.AsQueryable(Of C)()
  752. Select c).GroupBy(Function(c) c, Function(c) c, New CEqualityComparer())
  753. query.ToList()
  754. ' execute query
  755. End Sub
  756. <Test()> _
  757. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The GroupBy query operator is not supported.")> _
  758. Public Sub TestGroupByWithKeySelectorAndElementSelectorAndResultSelector()
  759. Dim query = (From c In _collection.AsQueryable(Of C)()
  760. Select c).GroupBy(Function(c) c, Function(c) c, Function(c, e) 1.0)
  761. query.ToList()
  762. ' execute query
  763. End Sub
  764. <Test()> _
  765. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The GroupBy query operator is not supported.")> _
  766. Public Sub TestGroupByWithKeySelectorAndElementSelectorAndResultSelectorAndEqualityComparer()
  767. Dim query = (From c In _collection.AsQueryable(Of C)()
  768. Select c).GroupBy(Function(c) c, Function(c) c, Function(c, e) e.First(), New CEqualityComparer())
  769. query.ToList()
  770. ' execute query
  771. End Sub
  772. <Test()> _
  773. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The GroupBy query operator is not supported.")> _
  774. Public Sub TestGroupByWithKeySelectorAndEqualityComparer()
  775. Dim query = (From c In _collection.AsQueryable(Of C)()
  776. Select c).GroupBy(Function(c) c, New CEqualityComparer())
  777. query.ToList()
  778. ' execute query
  779. End Sub
  780. <Test()> _
  781. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The GroupBy query operator is not supported.")> _
  782. Public Sub TestGroupByWithKeySelectorAndResultSelector()
  783. Dim query = (From c In _collection.AsQueryable(Of C)()
  784. Select c).GroupBy(Function(c) c, Function(k, e) 1.0)
  785. query.ToList()
  786. ' execute query
  787. End Sub
  788. <Test()> _
  789. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The GroupBy query operator is not supported.")> _
  790. Public Sub TestGroupByWithKeySelectorAndResultSelectorAndEqualityComparer()
  791. Dim query = (From c In _collection.AsQueryable(Of C)()
  792. Select c).GroupBy(Function(c) c, Function(k, e) e.First(), New CEqualityComparer())
  793. query.ToList()
  794. ' execute query
  795. End Sub
  796. <Test()> _
  797. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The GroupJoin query operator is not supported.")> _
  798. Public Sub TestGroupJoin()
  799. Dim inner = New C(-1) {}
  800. Dim query = _collection.AsQueryable(Of C)().GroupJoin(inner, Function(c) c, Function(c) c, Function(c, e) c)
  801. query.ToList()
  802. ' execute query
  803. End Sub
  804. <Test()> _
  805. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The GroupJoin query operator is not supported.")> _
  806. Public Sub TestGroupJoinWithEqualityComparer()
  807. Dim inner = New C(-1) {}
  808. Dim query = _collection.AsQueryable(Of C)().GroupJoin(inner, Function(c) c, Function(c) c, Function(c, e) c, New CEqualityComparer())
  809. query.ToList()
  810. ' execute query
  811. End Sub
  812. <Test()> _
  813. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The Intersect query operator is not supported.")> _
  814. Public Sub TestIntersect()
  815. Dim source2 = New C(-1) {}
  816. Dim query = (From c In _collection.AsQueryable(Of C)()
  817. Select c).Intersect(source2)
  818. query.ToList()
  819. ' execute query
  820. End Sub
  821. <Test()> _
  822. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The Intersect query operator is not supported.")> _
  823. Public Sub TestIntersectWithEqualityComparer()
  824. Dim source2 = New C(-1) {}
  825. Dim query = (From c In _collection.AsQueryable(Of C)()
  826. Select c).Intersect(source2, New CEqualityComparer())
  827. query.ToList()
  828. ' execute query
  829. End Sub
  830. <Test()> _
  831. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The Join query operator is not supported.")> _
  832. Public Sub TestJoin()
  833. Dim query = _collection.AsQueryable(Of C)().Join(_collection.AsQueryable(Of C)(), Function(c) c.X, Function(c) c.X, Function(x, y) x)
  834. query.ToList()
  835. ' execute query
  836. End Sub
  837. <Test()> _
  838. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="The Join query operator is not supported.")> _
  839. Public Sub TestJoinWithEqualityComparer()
  840. Dim query = _collection.AsQueryable(Of C)().Join(_collection.AsQueryable(Of C)(), Function(c) c.X, Function(c) c.X, Function(x, y) x, New Int32EqualityComparer())
  841. query.ToList()
  842. ' execute query
  843. End Sub
  844. <Test()> _
  845. Public Sub TestLastOrDefaultWithManyMatches()
  846. Dim result = (From c In _collection.AsQueryable(Of C)()
  847. Select c).LastOrDefault()
  848. Assert.AreEqual(4, result.X)
  849. Assert.AreEqual(44, result.Y)
  850. End Sub
  851. <Test()> _
  852. Public Sub TestLastOrDefaultWithNoMatch()
  853. Dim result = (From c In _collection.AsQueryable(Of C)()
  854. Where c.X = 9
  855. Select c).LastOrDefault()
  856. Assert.IsNull(result)
  857. End Sub
  858. <Test()> _
  859. Public Sub TestLastOrDefaultWithOneMatch()
  860. Dim result = (From c In _collection.AsQueryable(Of C)()
  861. Where c.X = 3
  862. Select c).LastOrDefault()
  863. Assert.AreEqual(3, result.X)
  864. Assert.AreEqual(33, result.Y)
  865. End Sub
  866. <Test()> _
  867. Public Sub TestLastOrDefaultWithOrderBy()
  868. Dim result = (From c In _collection.AsQueryable(Of C)()
  869. Order By c.X
  870. Select c).LastOrDefault()
  871. Assert.AreEqual(5, result.X)
  872. Assert.AreEqual(44, result.Y)
  873. End Sub
  874. <Test()> _
  875. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="LastOrDefault with predicate after a projection is not supported.")> _
  876. Public Sub TestLastOrDefaultWithPredicateAfterProjection()
  877. Dim result = _collection.AsQueryable(Of C)().[Select](Function(c) c.Y).LastOrDefault(Function(y) y = 11)
  878. End Sub
  879. <Test()> _
  880. Public Sub TestLastOrDefaultWithPredicateAfterWhere()
  881. Dim result = (From c In _collection.AsQueryable(Of C)()
  882. Where c.X = 1
  883. Select c).LastOrDefault(Function(c) c.Y = 11)
  884. Assert.AreEqual(1, result.X)
  885. Assert.AreEqual(11, result.Y)
  886. End Sub
  887. <Test()> _
  888. Public Sub TestLastOrDefaultWithPredicateNoMatch()
  889. Dim result = (From c In _collection.AsQueryable(Of C)()
  890. Select c).LastOrDefault(Function(c) c.X = 9)
  891. Assert.IsNull(result)
  892. End Sub
  893. <Test()> _
  894. Public Sub TestLastOrDefaultWithPredicateOneMatch()
  895. Dim result = (From c In _collection.AsQueryable(Of C)()
  896. Select c).LastOrDefault(Function(c) c.X = 3)
  897. Assert.AreEqual(3, result.X)
  898. Assert.AreEqual(33, result.Y)
  899. End Sub
  900. <Test()> _
  901. Public Sub TestLastOrDefaultWithPredicateTwoMatches()
  902. Dim result = (From c In _collection.AsQueryable(Of C)()
  903. Select c).LastOrDefault(Function(c) c.Y = 11)
  904. Assert.AreEqual(1, result.X)
  905. Assert.AreEqual(11, result.Y)
  906. End Sub
  907. <Test()> _
  908. Public Sub TestLastOrDefaultWithTwoMatches()
  909. Dim result = (From c In _collection.AsQueryable(Of C)()
  910. Where c.Y = 11
  911. Select c).LastOrDefault()
  912. Assert.AreEqual(1, result.X)
  913. Assert.AreEqual(11, result.Y)
  914. End Sub
  915. <Test()> _
  916. Public Sub TestLastWithManyMatches()
  917. Dim result = (From c In _collection.AsQueryable(Of C)()
  918. Select c).Last()
  919. Assert.AreEqual(4, result.X)
  920. Assert.AreEqual(44, result.Y)
  921. End Sub
  922. <Test()> _
  923. <ExpectedException(GetType(InvalidOperationException))> _
  924. Public Sub TestLastWithNoMatch()
  925. Dim result = (From c In _collection.AsQueryable(Of C)()
  926. Where c.X = 9
  927. Select c).Last()
  928. End Sub
  929. <Test()> _
  930. Public Sub TestLastWithOneMatch()
  931. Dim result = (From c In _collection.AsQueryable(Of C)()
  932. Where c.X = 3
  933. Select c).Last()
  934. Assert.AreEqual(3, result.X)
  935. Assert.AreEqual(33, result.Y)
  936. End Sub
  937. <Test()> _
  938. <ExpectedException(GetType(NotSupportedException), ExpectedMessage:="Last with predicate after a projection is not supported.")> _
  939. Public Sub TestLastWithPredicateAfterProjection()
  940. Dim result = _collection.AsQueryable(Of C)().Select(Function(c) c.Y).Last(Function(y) y = 11)
  941. End Sub
  942. <Test()> _
  943. Public Sub TestLastWithPredicateAfterWhere()
  944. Dim result = (From c In _collection.AsQueryable(Of C)()
  945. Where c.X = 1
  946. Select c).Last(Function(c) c.Y = 11)
  947. Assert.AreEqual(1, result.X)
  948. Assert.AreEqual(11, result.Y)
  949. End Sub
  950. <Test()> _
  951. Public Sub TestLastWithPredicateNoMatch()
  952. Dim ex = Assert.Throws(Of InvalidOperationException)(Sub()
  953. Dim result = (From c In _collection.AsQueryable(Of C)()
  954. Select c).Last(Function(c) c.X = 9)
  955. End Sub)
  956. Assert.AreEqual(ExpectedErrorMessage.LastEmptySequence, ex.Message)
  957. End Sub
  958. <Test()> _
  959. Public Sub TestLastWithPredicateOneMatch()
  960. Dim result = (From c In _collection.AsQueryable(Of C)()
  961. Select c).Last(Function(c) c.X = 3)
  962. Assert.AreEqual(3, result.X)
  963. Assert.AreEqual(33, result.Y)
  964. End Sub
  965. <Test()> _
  966. Public Sub TestLastWithPredicateTwoMatches()
  967. Dim result = (From c In _collection.AsQueryable(Of C)()
  968. Select c).Last(Function(c) c.Y = 11)
  969. Assert.AreEqual(1, result.X)
  970. Assert.AreEqual(11, result.Y)
  971. End Sub
  972. <Test()> _
  973. Public Sub TestLastWithOrderBy()
  974. Dim result = (From c In _collection.AsQueryable(Of C)()
  975. Order By c.X
  976. Select c).Last()
  977. Assert.AreEqual(5, result.X)
  978. Assert.AreEqual(44, result.Y)
  979. End Sub
  980. <Test()> _
  981. Public Sub TestLastWithTwoMatches()
  982. Dim result = (From c In _collection.AsQueryable(Of C)()
  983. Where c.Y = 11
  984. Select c).Last()
  985. Assert.AreEqual(1, result.X)
  986. Assert.AreEqual(11, result.Y)
  987. End Sub
  988. <Test()> _
  989. Public Sub TestLongCountEquals2()
  990. Dim result = (From c In _collection.AsQueryable(Of C)()
  991. Where c.Y = 11
  992. Select c).LongCount()
  993. Assert.AreEqual(2L, result)
  994. End Sub
  995. <Test()> _
  996. Public Sub TestLongCountEquals5()
  997. Dim result = (From c In _collection.AsQueryable(Of C)()
  998. Select c).LongCount()
  999. Assert.AreEqual(5L, result)
  1000. End Sub
  1001. <Test()> _
  1002. Public Sub TestLongCountWithSkipAndTake()
  1003. Dim result = (From c In _collection.AsQueryable(Of C)()
  1004. Select c).Skip(2).Take(2).LongCount()
  1005. Assert.AreEqual(2L, result)
  1006. End Sub
  1007. <Test()> _
  1008. Public Sub TestMaxDZWithProjection()
  1009. Dim result = (From c In _collection.AsQueryable(Of C)()
  1010. Select c.D.Z).Max()
  1011. Assert.AreEqual(55, result)
  1012. End Sub
  1013. <Test()> _
  1014. Public Sub TestMaxDZWithSelector()
  1015. Dim result = (From c In _collection.AsQueryable(Of C)()
  1016. Select c).Max(Function(c) c.D.Z)
  1017. Assert.AreEqual(55, result)
  1018. End Sub
  1019. <Test()> _
  1020. Public Sub TestMaxXWithProjection()
  1021. Dim result = (From c In _collection.AsQueryable(Of C)()
  1022. Select c.X).Max()
  1023. Assert.AreEqual(5, result)
  1024. End Sub
  1025. <Test()> _
  1026. Public Sub TestMaxXWithSelector()
  1027. Dim result = (From c In _collection.AsQueryable(Of C)()
  1028. Select c).Max(Function(c) c.X)
  1029. Assert.AreEqual(5, result)
  1030. End Sub
  1031. <Test()> _
  1032. Public Sub TestMaxXYWithProjection()
  1033. Dim result = (From c In _collection.AsQueryable(Of C)()
  1034. Select New With {c.X, c.Y}).Max()
  1035. Assert.AreEqual(5, result.X)
  1036. Assert.AreEqual(44, result.Y)
  1037. End Sub
  1038. <Test()> _
  1039. Public Sub TestMaxXYWithSelector()
  1040. Dim result = (From c In _collection.AsQueryable(Of C)()
  1041. Select c).Max(Function(c) New With
  1042. {
  1043. c.X,
  1044. c.Y
  1045. })
  1046. Assert.AreEqual(5, result.X)
  1047. Assert.AreEqual(44, result.Y)
  1048. End Sub
  1049. <Test()> _
  1050. Public Sub TestMinDZWithProjection()
  1051. Dim result = (From c In _collection.AsQueryable(Of C)()
  1052. Select c.D.Z).Min()
  1053. Assert.AreEqual(11, result)
  1054. End Sub
  1055. <Test()> _
  1056. Public Sub TestMinDZWithSelector()
  1057. Dim result = (From c In _collection.AsQueryable(Of C)()
  1058. Select c).Min(Function(c) c.D.Z)
  1059. Assert.AreEqual(11, result)
  1060. End Sub
  1061. <Test()> _
  1062. Public Sub TestMinXWithProjection()
  1063. Dim result = (From c In _collection.AsQueryable(Of C)()
  1064. Select c.X).Min()
  1065. Assert.AreEqual(1, result)
  1066. End Sub
  1067. <Test()> _
  1068. Public Sub TestMinXWithSelector()
  1069. Dim result = (From c In _collection.AsQueryable(Of C)()
  1070. Select c).Min(Function(c) c.X)
  1071. Assert.AreEqual(1, result)
  1072. End Sub
  1073. <Test()> _
  1074. Public Sub TestMinXYWithProjection()
  1075. Dim result = (From c In _collection.AsQueryable(Of C)()
  1076. Select New With {c.X, c.Y}).Min()
  1077. Assert.AreEqual(1, result.X)
  1078. Assert.AreEqual(11, result.Y)
  1079. End Sub
  1080. <Test()> _
  1081. Public Sub TestMinXYWithSelector()
  1082. Dim result = (From c In _collection.AsQueryable(Of C)()
  1083. Select c).Min(Function(c) New With
  1084. {
  1085. c.X,
  1086. c.Y
  1087. })
  1088. Assert.AreEqual(1, result.X)
  1089. Assert.AreEqual(11, result.Y)
  1090. End Sub
  1091. <Test()>
  1092. Public Sub TestOrderByValueTypeWithObjectReturnType()
  1093. Dim orderByClause As Expression(Of Func(Of C, Object)) = Function(c) c.LX
  1094. Dim query = _collection.AsQueryable(Of C)().OrderBy(orderByClause)
  1095. RunTestOrderByValueTypeWithMismatchingType(query, "(C c) => (Object)c.LX")
  1096. End Sub
  1097. <Test()>
  1098. Public Sub TestOrderByValueTypeWithIComparableReturnType()
  1099. Dim orderByClause As Expression(Of Func(Of C, IComparable)) = Function(c) c.LX
  1100. Dim query = _collection.AsQueryable(Of C)().OrderBy(orderByClause)
  1101. RunTestOrderByValueTypeWithMismatchingType(query, "(C c) => (IComparable)c.LX")
  1102. End Sub
  1103. Sub RunTestOrderByValueTypeWithMismatchingType(ByVal query As IOrderedQueryable, ByVal orderByString As String)
  1104. Dim mongoQuery = MongoQueryTranslator.Translate(query)
  1105. Assert.IsInstanceOf(Of SelectQuery)(mongoQuery)
  1106. Dim selectQuery As SelectQuery = mongoQuery
  1107. Assert.AreEqual(orderByString, ExpressionFormatter.ToString(selectQuery.OrderBy(0).Key))
  1108. End Sub
  1109. <Test()> _
  1110. Public Sub TestOrderByAscending(

Large files files are truncated, but you can click here to view the full file