Skip to content

Commit

Permalink
added more tests for inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
craiggwilson committed Aug 9, 2010
1 parent 1b12023 commit 9b0e02b
Showing 1 changed file with 24 additions and 18 deletions.
Expand Up @@ -9,7 +9,7 @@ namespace MongoDB.IntegrationTests.Inheritance
[TestFixture]
public class TestInheritanceWithConcreteBaseClass : MongoTestBase
{
abstract class Animal
class Animal
{
public Oid Id { get; set; }

Expand All @@ -33,6 +33,12 @@ public override string TestCollections
get { return "Animal"; }
}

[SetUp]
public void TestSetup()
{
CleanDB();
}

protected override Configuration.MongoConfigurationBuilder GetConfiguration()
{
var builder = base.GetConfiguration();
Expand All @@ -56,19 +62,19 @@ protected override Configuration.MongoConfigurationBuilder GetConfiguration()
public void Should_persist_discriminator_using_base_class_collection()
{
var animalCollection = DB.GetCollection<Animal>();
animalCollection.Save(new Bear() { Age = 20 });
animalCollection.Save(new Animal() { Age = 20 });
animalCollection.Save(new Tiger() { Age = 19 });

var docCollection = DB.GetCollection<Document>("Animal");

var docs = docCollection.FindAll().Sort("Age", IndexOrder.Ascending).Documents.ToList();

Assert.AreEqual(new[] { "Cat", "Tiger" }, (List<string>)docs[0]["_t"]);
Assert.AreEqual("Bear", (string)docs[1]["_t"]);
Assert.IsNull(docs[1]["_t"]);
}

[Test]
public void Should_persist_discriminator_using_concrete_class_collection()
public void Should_persist_discriminator_using_inherited_class_collection()
{
var animalCollection = DB.GetCollection<Cat>();
animalCollection.Save(new Lion() { Age = 20 });
Expand All @@ -86,23 +92,23 @@ public void Should_persist_discriminator_using_concrete_class_collection()
public void Should_fetch_with_base_class_collection()
{
var animalCollection = DB.GetCollection<Animal>();
animalCollection.Save(new Bear() { Age = 20 });
animalCollection.Save(new Animal() { Age = 20 });
animalCollection.Save(new Tiger() { Age = 19 });

var animals = animalCollection.FindAll().Sort("Age", IndexOrder.Ascending).Documents.ToList();

Assert.AreEqual(2, animals.Count);
Assert.IsInstanceOfType(typeof(Tiger), animals[0]);
Assert.AreEqual(19, animals[0].Age);
Assert.IsInstanceOfType(typeof(Bear), animals[1]);
Assert.IsInstanceOfType(typeof(Animal), animals[1]);
Assert.AreEqual(20, animals[1].Age);
}

[Test]
public void Should_fetch_with_base_class_collection_through_linq()
{
var animalCollection = DB.GetCollection<Animal>();
animalCollection.Save(new Bear() { Age = 20 });
animalCollection.Save(new Animal() { Age = 20 });
animalCollection.Save(new Tiger() { Age = 19 });

var animals = (from a in animalCollection.Linq()
Expand All @@ -112,15 +118,15 @@ public void Should_fetch_with_base_class_collection_through_linq()
Assert.AreEqual(2, animals.Count);
Assert.IsInstanceOfType(typeof(Tiger), animals[0]);
Assert.AreEqual(19, animals[0].Age);
Assert.IsInstanceOfType(typeof(Bear), animals[1]);
Assert.IsInstanceOfType(typeof(Animal), animals[1]);
Assert.AreEqual(20, animals[1].Age);
}

[Test]
public void Should_fetch_with_concrete_class_collection()
public void Should_fetch_with_inherited_class_collection()
{
var animalCollection = DB.GetCollection<Animal>();
animalCollection.Save(new Bear() { Age = 20 });
animalCollection.Save(new Animal() { Age = 20 });
animalCollection.Save(new Tiger() { Age = 19 });

var catCollection = DB.GetCollection<Cat>();
Expand All @@ -133,10 +139,10 @@ public void Should_fetch_with_concrete_class_collection()
}

[Test]
public void Should_fetch_with_concrete_class_collection_through_linq()
public void Should_fetch_with_inherited_class_collection_through_linq()
{
var animalCollection = DB.GetCollection<Animal>();
animalCollection.Save(new Bear() { Age = 20 });
animalCollection.Save(new Animal() { Age = 20 });
animalCollection.Save(new Tiger() { Age = 19 });

var catCollection = DB.GetCollection<Cat>();
Expand All @@ -154,7 +160,7 @@ public void Should_fetch_with_concrete_class_collection_through_linq()
public void Should_get_correct_count_with_base_class_collection()
{
var animalCollection = DB.GetCollection<Animal>();
animalCollection.Save(new Bear() { Age = 20 });
animalCollection.Save(new Animal() { Age = 20 });
animalCollection.Save(new Tiger() { Age = 19 });

Assert.AreEqual(2, animalCollection.Count());
Expand All @@ -164,17 +170,17 @@ public void Should_get_correct_count_with_base_class_collection()
public void Should_get_correct_count_with_base_class_collection_using_linq()
{
var animalCollection = DB.GetCollection<Animal>();
animalCollection.Save(new Bear() { Age = 20 });
animalCollection.Save(new Animal() { Age = 20 });
animalCollection.Save(new Tiger() { Age = 19 });

Assert.AreEqual(2, animalCollection.Linq().Count());
}

[Test]
public void Should_get_correct_count_with_concrete_class_collection()
public void Should_get_correct_count_with_inherited_class_collection()
{
var animalCollection = DB.GetCollection<Animal>();
animalCollection.Save(new Bear() { Age = 20 });
animalCollection.Save(new Animal() { Age = 20 });
animalCollection.Save(new Tiger() { Age = 19 });

var catCollection = DB.GetCollection<Cat>();
Expand All @@ -183,10 +189,10 @@ public void Should_get_correct_count_with_concrete_class_collection()
}

[Test]
public void Should_get_correct_count_with_concrete_class_collection_using_linq()
public void Should_get_correct_count_with_inherited_class_collection_using_linq()
{
var animalCollection = DB.GetCollection<Animal>();
animalCollection.Save(new Bear() { Age = 20 });
animalCollection.Save(new Animal() { Age = 20 });
animalCollection.Save(new Tiger() { Age = 19 });

var catCollection = DB.GetCollection<Cat>();
Expand Down

0 comments on commit 9b0e02b

Please sign in to comment.