PageRenderTime 60ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/MongoDB.DriverUnitTests/Linq/SelectQueryTests.cs

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

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