Skip to content

Commit 9b0e02b

Browse files
committed
added more tests for inheritance
1 parent 1b12023 commit 9b0e02b

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

source/MongoDB.Tests/IntegrationTests/Inheritance/TestInheritanceWithConcreteBaseClass.cs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace MongoDB.IntegrationTests.Inheritance
99
[TestFixture]
1010
public class TestInheritanceWithConcreteBaseClass : MongoTestBase
1111
{
12-
abstract class Animal
12+
class Animal
1313
{
1414
public Oid Id { get; set; }
1515

@@ -33,6 +33,12 @@ public override string TestCollections
3333
get { return "Animal"; }
3434
}
3535

36+
[SetUp]
37+
public void TestSetup()
38+
{
39+
CleanDB();
40+
}
41+
3642
protected override Configuration.MongoConfigurationBuilder GetConfiguration()
3743
{
3844
var builder = base.GetConfiguration();
@@ -56,19 +62,19 @@ protected override Configuration.MongoConfigurationBuilder GetConfiguration()
5662
public void Should_persist_discriminator_using_base_class_collection()
5763
{
5864
var animalCollection = DB.GetCollection<Animal>();
59-
animalCollection.Save(new Bear() { Age = 20 });
65+
animalCollection.Save(new Animal() { Age = 20 });
6066
animalCollection.Save(new Tiger() { Age = 19 });
6167

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

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

6672
Assert.AreEqual(new[] { "Cat", "Tiger" }, (List<string>)docs[0]["_t"]);
67-
Assert.AreEqual("Bear", (string)docs[1]["_t"]);
73+
Assert.IsNull(docs[1]["_t"]);
6874
}
6975

7076
[Test]
71-
public void Should_persist_discriminator_using_concrete_class_collection()
77+
public void Should_persist_discriminator_using_inherited_class_collection()
7278
{
7379
var animalCollection = DB.GetCollection<Cat>();
7480
animalCollection.Save(new Lion() { Age = 20 });
@@ -86,23 +92,23 @@ public void Should_persist_discriminator_using_concrete_class_collection()
8692
public void Should_fetch_with_base_class_collection()
8793
{
8894
var animalCollection = DB.GetCollection<Animal>();
89-
animalCollection.Save(new Bear() { Age = 20 });
95+
animalCollection.Save(new Animal() { Age = 20 });
9096
animalCollection.Save(new Tiger() { Age = 19 });
9197

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

94100
Assert.AreEqual(2, animals.Count);
95101
Assert.IsInstanceOfType(typeof(Tiger), animals[0]);
96102
Assert.AreEqual(19, animals[0].Age);
97-
Assert.IsInstanceOfType(typeof(Bear), animals[1]);
103+
Assert.IsInstanceOfType(typeof(Animal), animals[1]);
98104
Assert.AreEqual(20, animals[1].Age);
99105
}
100106

101107
[Test]
102108
public void Should_fetch_with_base_class_collection_through_linq()
103109
{
104110
var animalCollection = DB.GetCollection<Animal>();
105-
animalCollection.Save(new Bear() { Age = 20 });
111+
animalCollection.Save(new Animal() { Age = 20 });
106112
animalCollection.Save(new Tiger() { Age = 19 });
107113

108114
var animals = (from a in animalCollection.Linq()
@@ -112,15 +118,15 @@ orderby a.Age ascending
112118
Assert.AreEqual(2, animals.Count);
113119
Assert.IsInstanceOfType(typeof(Tiger), animals[0]);
114120
Assert.AreEqual(19, animals[0].Age);
115-
Assert.IsInstanceOfType(typeof(Bear), animals[1]);
121+
Assert.IsInstanceOfType(typeof(Animal), animals[1]);
116122
Assert.AreEqual(20, animals[1].Age);
117123
}
118124

119125
[Test]
120-
public void Should_fetch_with_concrete_class_collection()
126+
public void Should_fetch_with_inherited_class_collection()
121127
{
122128
var animalCollection = DB.GetCollection<Animal>();
123-
animalCollection.Save(new Bear() { Age = 20 });
129+
animalCollection.Save(new Animal() { Age = 20 });
124130
animalCollection.Save(new Tiger() { Age = 19 });
125131

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

135141
[Test]
136-
public void Should_fetch_with_concrete_class_collection_through_linq()
142+
public void Should_fetch_with_inherited_class_collection_through_linq()
137143
{
138144
var animalCollection = DB.GetCollection<Animal>();
139-
animalCollection.Save(new Bear() { Age = 20 });
145+
animalCollection.Save(new Animal() { Age = 20 });
140146
animalCollection.Save(new Tiger() { Age = 19 });
141147

142148
var catCollection = DB.GetCollection<Cat>();
@@ -154,7 +160,7 @@ orderby a.Age ascending
154160
public void Should_get_correct_count_with_base_class_collection()
155161
{
156162
var animalCollection = DB.GetCollection<Animal>();
157-
animalCollection.Save(new Bear() { Age = 20 });
163+
animalCollection.Save(new Animal() { Age = 20 });
158164
animalCollection.Save(new Tiger() { Age = 19 });
159165

160166
Assert.AreEqual(2, animalCollection.Count());
@@ -164,17 +170,17 @@ public void Should_get_correct_count_with_base_class_collection()
164170
public void Should_get_correct_count_with_base_class_collection_using_linq()
165171
{
166172
var animalCollection = DB.GetCollection<Animal>();
167-
animalCollection.Save(new Bear() { Age = 20 });
173+
animalCollection.Save(new Animal() { Age = 20 });
168174
animalCollection.Save(new Tiger() { Age = 19 });
169175

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

173179
[Test]
174-
public void Should_get_correct_count_with_concrete_class_collection()
180+
public void Should_get_correct_count_with_inherited_class_collection()
175181
{
176182
var animalCollection = DB.GetCollection<Animal>();
177-
animalCollection.Save(new Bear() { Age = 20 });
183+
animalCollection.Save(new Animal() { Age = 20 });
178184
animalCollection.Save(new Tiger() { Age = 19 });
179185

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

185191
[Test]
186-
public void Should_get_correct_count_with_concrete_class_collection_using_linq()
192+
public void Should_get_correct_count_with_inherited_class_collection_using_linq()
187193
{
188194
var animalCollection = DB.GetCollection<Animal>();
189-
animalCollection.Save(new Bear() { Age = 20 });
195+
animalCollection.Save(new Animal() { Age = 20 });
190196
animalCollection.Save(new Tiger() { Age = 19 });
191197

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

0 commit comments

Comments
 (0)