You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.2 KiB

  1. /* Copyright 2010-2011 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.Text;
  19. using NUnit.Framework;
  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. namespace MongoDB.DriverOnlineTests.Linq {
  26. [TestFixture]
  27. public class MongoLinqFindQueryTests {
  28. private class C {
  29. public ObjectId Id { get; set; }
  30. public int X { get; set; }
  31. public int Y { get; set; }
  32. }
  33. private MongoServer server;
  34. private MongoDatabase database;
  35. private MongoCollection<C> collection;
  36. [TestFixtureSetUp]
  37. public void Setup() {
  38. server = MongoServer.Create("mongodb://localhost/?safe=true");
  39. server.Connect();
  40. database = server["onlinetests"];
  41. collection = database.GetCollection<C>("linqtests");
  42. collection.Drop();
  43. collection.Insert(new C { X = 1, Y = 11 });
  44. collection.Insert(new C { X = 2, Y = 12 });
  45. collection.Insert(new C { X = 3, Y = 13 });
  46. collection.Insert(new C { X = 4, Y = 14 });
  47. collection.Insert(new C { X = 5, Y = 15 });
  48. }
  49. [Test]
  50. public void TestQueryXEquals1() {
  51. var query = from c in collection.AsQueryable<C>()
  52. where c.X == 1
  53. select c;
  54. var count = 0;
  55. foreach (var c in query) {
  56. Assert.AreEqual(1, c.X);
  57. count++;
  58. }
  59. Assert.AreEqual(1, count);
  60. }
  61. }
  62. }