Permalink
Browse files

cleaning up a little

  • Loading branch information...
1 parent 1ff7ff6 commit e543727f82bad97e56ef30978f412cd3cd4d9258 @craiggwilson craiggwilson committed Aug 9, 2010
@@ -160,12 +160,46 @@ public void Should_support_projections_with_base_class_collections_with_linq()
Assert.AreEqual(2, animals.Count);
Assert.AreEqual(19, animals[0].Age);
Assert.AreEqual("Bob", animals[0].Name);
- Assert.IsNull(animals[0].Name);
Assert.AreEqual(20, animals[1].Age);
Assert.AreEqual("Jim", animals[1].Name);
}
[Test]
+ public void Should_support_projections_with_concrete_class_collection()
+ {
+ var animalCollection = DB.GetCollection<Animal>();
+ animalCollection.Save(new Bear() { Age = 20, Name = "Jim" });
+ animalCollection.Save(new Tiger() { Age = 19, Name = "Bob" });
+
+ var catCollection = DB.GetCollection<Cat>();
+
+ var cats = catCollection.FindAll().Fields(new { Age = true }).Sort("Age", IndexOrder.Ascending).Documents.ToList();
+
+ Assert.AreEqual(1, cats.Count);
+ Assert.IsInstanceOfType(typeof(Tiger), cats[0]);
+ Assert.AreEqual(19, cats[0].Age);
+ Assert.IsNull(cats[0].Name);
+ }
+
+ [Test]
+ public void Should_support_projections_with_concrete_class_collections_with_linq()
+ {
+ var animalCollection = DB.GetCollection<Animal>();
+ animalCollection.Save(new Bear() { Age = 20, Name = "Jim" });
+ animalCollection.Save(new Tiger() { Age = 19, Name = "Bob" });
+
+ var catCollection = DB.GetCollection<Cat>();
+
+ var cats = (from a in catCollection.Linq()
+ orderby a.Age ascending
+ select new { a.Name, a.Age }).ToList();
+
+ Assert.AreEqual(1, cats.Count);
+ Assert.AreEqual(19, cats[0].Age);
+ Assert.AreEqual("Bob", cats[0].Name);
+ }
+
+ [Test]
public void Should_fetch_with_concrete_class_collection()
{
var animalCollection = DB.GetCollection<Animal>();
@@ -14,6 +14,8 @@ class Animal
public Oid Id { get; set; }
public int Age { get; set; }
+
+ public string Name { get; set; }
}
class Bear : Animal
@@ -157,6 +159,77 @@ public void Should_fetch_with_inherited_class_collection_through_linq()
}
[Test]
+ public void Should_support_projections_with_base_class_collection()
+ {
+ var animalCollection = DB.GetCollection<Animal>();
+ animalCollection.Save(new Animal() { Age = 20, Name = "Jim" });
+ animalCollection.Save(new Tiger() { Age = 19, Name = "Bob" });
+
+ var animals = animalCollection.FindAll().Fields(new { Age = true }).Sort("Age", IndexOrder.Ascending).Documents.ToList();
+
+ Assert.AreEqual(2, animals.Count);
+ Assert.IsInstanceOfType(typeof(Tiger), animals[0]);
+ Assert.AreEqual(19, animals[0].Age);
+ Assert.IsNull(animals[0].Name);
+ Assert.IsInstanceOfType(typeof(Animal), animals[1]);
+ Assert.AreEqual(20, animals[1].Age);
+ Assert.IsNull(animals[1].Name);
+ }
+
+ [Test]
+ public void Should_support_projections_with_base_class_collections_with_linq()
+ {
+ var animalCollection = DB.GetCollection<Animal>();
+ animalCollection.Save(new Animal() { Age = 20, Name = "Jim" });
+ animalCollection.Save(new Tiger() { Age = 19, Name = "Bob" });
+
+ var animals = (from a in animalCollection.Linq()
+ orderby a.Age ascending
+ select new { a.Name, a.Age }).ToList();
+
+ Assert.AreEqual(2, animals.Count);
+ Assert.AreEqual(19, animals[0].Age);
+ Assert.AreEqual("Bob", animals[0].Name);
+ Assert.AreEqual(20, animals[1].Age);
+ Assert.AreEqual("Jim", animals[1].Name);
+ }
+
+ [Test]
+ public void Should_support_projections_with_inherited_class_collection()
+ {
+ var animalCollection = DB.GetCollection<Animal>();
+ animalCollection.Save(new Animal() { Age = 20, Name = "Jim" });
+ animalCollection.Save(new Tiger() { Age = 19, Name = "Bob" });
+
+ var catCollection = DB.GetCollection<Cat>();
+
+ var cats = catCollection.FindAll().Fields(new { Age = true }).Sort("Age", IndexOrder.Ascending).Documents.ToList();
+
+ Assert.AreEqual(1, cats.Count);
+ Assert.IsInstanceOfType(typeof(Tiger), cats[0]);
+ Assert.AreEqual(19, cats[0].Age);
+ Assert.IsNull(cats[0].Name);
+ }
+
+ [Test]
+ public void Should_support_projections_with_inherited_class_collections_with_linq()
+ {
+ var animalCollection = DB.GetCollection<Animal>();
+ animalCollection.Save(new Animal() { Age = 20, Name = "Jim" });
+ animalCollection.Save(new Tiger() { Age = 19, Name = "Bob" });
+
+ var catCollection = DB.GetCollection<Cat>();
+
+ var cats = (from a in catCollection.Linq()
+ orderby a.Age ascending
+ select new { a.Name, a.Age }).ToList();
+
+ Assert.AreEqual(1, cats.Count);
+ Assert.AreEqual(19, cats[0].Age);
+ Assert.AreEqual("Bob", cats[0].Name);
+ }
+
+ [Test]
public void Should_get_correct_count_with_base_class_collection()
{
var animalCollection = DB.GetCollection<Animal>();
@@ -8,7 +8,7 @@
using MongoDB.Serialization;
using MongoDB.Util;
-namespace MongoDB.Connections
+namespace MongoDB.Connections
{
/// <summary>
/// Connection is a managment unit which uses a RawConnection from connection pool
@@ -18,7 +18,7 @@ namespace MongoDB.Connections
/// by a new fresh connection.
/// </remarks>
/// </summary>
- internal class Connection : IDisposable
+ internal class Connection : IDisposable
{
private readonly IConnectionFactory _factory;
private RawConnection _connection;
Oops, something went wrong.

0 comments on commit e543727

Please sign in to comment.