Skip to content

Commit

Permalink
cleaning up a little
Browse files Browse the repository at this point in the history
  • Loading branch information
craiggwilson committed Aug 9, 2010
1 parent 1ff7ff6 commit e543727
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 203 deletions.
Expand Up @@ -160,11 +160,45 @@ 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()
{
Expand Down
Expand Up @@ -14,6 +14,8 @@ class Animal
public Oid Id { get; set; }

public int Age { get; set; }

public string Name { get; set; }
}

class Bear : Animal
Expand Down Expand Up @@ -156,6 +158,77 @@ public void Should_fetch_with_inherited_class_collection_through_linq()
Assert.AreEqual(19, animals[0].Age);
}

[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()
{
Expand Down
4 changes: 2 additions & 2 deletions source/MongoDB/Connections/Connection.cs
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit e543727

Please sign in to comment.