Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added more tests for inheritance

  • Loading branch information...
commit 9b0e02bb6f47d8097c3fc1a6d87e1b3448c8aec5 1 parent 1b12023
Craig Wilson authored August 09, 2010
42  source/MongoDB.Tests/IntegrationTests/Inheritance/TestInheritanceWithConcreteBaseClass.cs
@@ -9,7 +9,7 @@ namespace MongoDB.IntegrationTests.Inheritance
9 9
     [TestFixture]
10 10
     public class TestInheritanceWithConcreteBaseClass : MongoTestBase
11 11
     {
12  
-        abstract class Animal
  12
+        class Animal
13 13
         {
14 14
             public Oid Id { get; set; }
15 15
 
@@ -33,6 +33,12 @@ public override string TestCollections
33 33
             get { return "Animal"; }
34 34
         }
35 35
 
  36
+        [SetUp]
  37
+        public void TestSetup()
  38
+        {
  39
+            CleanDB();
  40
+        }
  41
+
36 42
         protected override Configuration.MongoConfigurationBuilder GetConfiguration()
37 43
         {
38 44
             var builder = base.GetConfiguration();
@@ -56,7 +62,7 @@ protected override Configuration.MongoConfigurationBuilder GetConfiguration()
56 62
         public void Should_persist_discriminator_using_base_class_collection()
57 63
         {
58 64
             var animalCollection = DB.GetCollection<Animal>();
59  
-            animalCollection.Save(new Bear() { Age = 20 });
  65
+            animalCollection.Save(new Animal() { Age = 20 });
60 66
             animalCollection.Save(new Tiger() { Age = 19 });
61 67
 
62 68
             var docCollection = DB.GetCollection<Document>("Animal");
@@ -64,11 +70,11 @@ public void Should_persist_discriminator_using_base_class_collection()
64 70
             var docs = docCollection.FindAll().Sort("Age", IndexOrder.Ascending).Documents.ToList();
65 71
 
66 72
             Assert.AreEqual(new[] { "Cat", "Tiger" }, (List<string>)docs[0]["_t"]);
67  
-            Assert.AreEqual("Bear", (string)docs[1]["_t"]);
  73
+            Assert.IsNull(docs[1]["_t"]);
68 74
         }
69 75
 
70 76
         [Test]
71  
-        public void Should_persist_discriminator_using_concrete_class_collection()
  77
+        public void Should_persist_discriminator_using_inherited_class_collection()
72 78
         {
73 79
             var animalCollection = DB.GetCollection<Cat>();
74 80
             animalCollection.Save(new Lion() { Age = 20 });
@@ -86,7 +92,7 @@ public void Should_persist_discriminator_using_concrete_class_collection()
86 92
         public void Should_fetch_with_base_class_collection()
87 93
         {
88 94
             var animalCollection = DB.GetCollection<Animal>();
89  
-            animalCollection.Save(new Bear() { Age = 20 });
  95
+            animalCollection.Save(new Animal() { Age = 20 });
90 96
             animalCollection.Save(new Tiger() { Age = 19 });
91 97
 
92 98
             var animals = animalCollection.FindAll().Sort("Age", IndexOrder.Ascending).Documents.ToList();
@@ -94,7 +100,7 @@ public void Should_fetch_with_base_class_collection()
94 100
             Assert.AreEqual(2, animals.Count);
95 101
             Assert.IsInstanceOfType(typeof(Tiger), animals[0]);
96 102
             Assert.AreEqual(19, animals[0].Age);
97  
-            Assert.IsInstanceOfType(typeof(Bear), animals[1]);
  103
+            Assert.IsInstanceOfType(typeof(Animal), animals[1]);
98 104
             Assert.AreEqual(20, animals[1].Age);
99 105
         }
100 106
 
@@ -102,7 +108,7 @@ public void Should_fetch_with_base_class_collection()
102 108
         public void Should_fetch_with_base_class_collection_through_linq()
103 109
         {
104 110
             var animalCollection = DB.GetCollection<Animal>();
105  
-            animalCollection.Save(new Bear() { Age = 20 });
  111
+            animalCollection.Save(new Animal() { Age = 20 });
106 112
             animalCollection.Save(new Tiger() { Age = 19 });
107 113
 
108 114
             var animals = (from a in animalCollection.Linq()
@@ -112,15 +118,15 @@ public void Should_fetch_with_base_class_collection_through_linq()
112 118
             Assert.AreEqual(2, animals.Count);
113 119
             Assert.IsInstanceOfType(typeof(Tiger), animals[0]);
114 120
             Assert.AreEqual(19, animals[0].Age);
115  
-            Assert.IsInstanceOfType(typeof(Bear), animals[1]);
  121
+            Assert.IsInstanceOfType(typeof(Animal), animals[1]);
116 122
             Assert.AreEqual(20, animals[1].Age);
117 123
         }
118 124
 
119 125
         [Test]
120  
-        public void Should_fetch_with_concrete_class_collection()
  126
+        public void Should_fetch_with_inherited_class_collection()
121 127
         {
122 128
             var animalCollection = DB.GetCollection<Animal>();
123  
-            animalCollection.Save(new Bear() { Age = 20 });
  129
+            animalCollection.Save(new Animal() { Age = 20 });
124 130
             animalCollection.Save(new Tiger() { Age = 19 });
125 131
 
126 132
             var catCollection = DB.GetCollection<Cat>();
@@ -133,10 +139,10 @@ public void Should_fetch_with_concrete_class_collection()
133 139
         }
134 140
 
135 141
         [Test]
136  
-        public void Should_fetch_with_concrete_class_collection_through_linq()
  142
+        public void Should_fetch_with_inherited_class_collection_through_linq()
137 143
         {
138 144
             var animalCollection = DB.GetCollection<Animal>();
139  
-            animalCollection.Save(new Bear() { Age = 20 });
  145
+            animalCollection.Save(new Animal() { Age = 20 });
140 146
             animalCollection.Save(new Tiger() { Age = 19 });
141 147
 
142 148
             var catCollection = DB.GetCollection<Cat>();
@@ -154,7 +160,7 @@ public void Should_fetch_with_concrete_class_collection_through_linq()
154 160
         public void Should_get_correct_count_with_base_class_collection()
155 161
         {
156 162
             var animalCollection = DB.GetCollection<Animal>();
157  
-            animalCollection.Save(new Bear() { Age = 20 });
  163
+            animalCollection.Save(new Animal() { Age = 20 });
158 164
             animalCollection.Save(new Tiger() { Age = 19 });
159 165
 
160 166
             Assert.AreEqual(2, animalCollection.Count());
@@ -164,17 +170,17 @@ public void Should_get_correct_count_with_base_class_collection()
164 170
         public void Should_get_correct_count_with_base_class_collection_using_linq()
165 171
         {
166 172
             var animalCollection = DB.GetCollection<Animal>();
167  
-            animalCollection.Save(new Bear() { Age = 20 });
  173
+            animalCollection.Save(new Animal() { Age = 20 });
168 174
             animalCollection.Save(new Tiger() { Age = 19 });
169 175
 
170 176
             Assert.AreEqual(2, animalCollection.Linq().Count());
171 177
         }
172 178
 
173 179
         [Test]
174  
-        public void Should_get_correct_count_with_concrete_class_collection()
  180
+        public void Should_get_correct_count_with_inherited_class_collection()
175 181
         {
176 182
             var animalCollection = DB.GetCollection<Animal>();
177  
-            animalCollection.Save(new Bear() { Age = 20 });
  183
+            animalCollection.Save(new Animal() { Age = 20 });
178 184
             animalCollection.Save(new Tiger() { Age = 19 });
179 185
 
180 186
             var catCollection = DB.GetCollection<Cat>();
@@ -183,10 +189,10 @@ public void Should_get_correct_count_with_concrete_class_collection()
183 189
         }
184 190
 
185 191
         [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()
187 193
         {
188 194
             var animalCollection = DB.GetCollection<Animal>();
189  
-            animalCollection.Save(new Bear() { Age = 20 });
  195
+            animalCollection.Save(new Animal() { Age = 20 });
190 196
             animalCollection.Save(new Tiger() { Age = 19 });
191 197
 
192 198
             var catCollection = DB.GetCollection<Cat>();

0 notes on commit 9b0e02b

Please sign in to comment.
Something went wrong with that request. Please try again.