Permalink
Browse files

more unit tests

  • Loading branch information...
1 parent e2155bd commit 32004048fee7a39b264cf0e4c7f15ae774d30d12 @kolosy kolosy committed Nov 15, 2009
Showing with 44 additions and 5 deletions.
  1. +40 −4 Tests/Autoreconcile/CouchAutoreconcileTest.cs
  2. +1 −1 src/CouchDesignDocument.cs
  3. +3 −0 src/CouchGenericViewResult.cs
@@ -77,6 +77,14 @@ public void SetUp()
db = server.GetNewDatabase(DbName);
}
+ [TearDown]
+ public void TearDown()
+ {
+ db.Delete();
+ }
+
+ #endregion
+
[Test, ExpectedException(ExceptionType = typeof(CouchConflictException))]
public void ShouldCauseConflict()
{
@@ -90,13 +98,41 @@ public void ShouldCauseConflict()
db.SaveDocument(doc);
}
- [TearDown]
- public void TearDown()
+ [Test]
+ public void ShouldHandleConflict()
{
- db.Delete();
+ var doc = new Car("Hoopty", "Type R", 5);
+ doc = db.SaveDocument(doc) as Car;
+
+ var rev = doc.Rev;
+ doc = db.SaveDocument(doc) as Car;
+
+ doc.Rev = rev;
+ db.SaveDocument(doc);
+
+ Assert.That(doc.Rev.StartsWith("3"), "Incorrect revision");
}
- #endregion
+ [Test]
+ public void ShouldResolveConflict()
+ {
+ var doc = new Car("Hoopty", "Type R", 5);
+ doc = db.SaveDocument(doc) as Car;
+
+ var doc2 = new Car("Slightly Better", "Type R", 6);
+ doc2.Id = doc.Id;
+ doc2.Rev = doc.Rev;
+
+ doc.Model = "Type S";
+ doc = db.SaveDocument(doc) as Car;
+
+ doc2 = db.SaveDocument(doc2) as Car;
+
+ Assert.That(doc2.Rev.StartsWith("3"), "Incorrect revision");
+ Assert.AreEqual("Slightly Better", doc2.Make);
+ Assert.AreEqual("Type S", doc2.Model);
+ Assert.AreEqual(6, doc2.HorsePowers);
+ }
private CouchServer server;
private CouchDatabase db;
@@ -203,7 +203,7 @@ public override void ReadJson(JObject obj)
foreach (var property in fulltext.Properties())
{
var v = new CouchLuceneViewDefinition(property.Name, this);
- v.ReadJson((JObject) views[property.Name]);
+ v.ReadJson((JObject) fulltext[property.Name]);
LuceneDefinitions.Add(v);
}
}
@@ -92,6 +92,9 @@ protected virtual IList<T> RetrieveDocuments<T>(string docOrValue) where T : ICa
foreach (JToken row in Rows())
{
var doc = new T();
+ if (row[docOrValue] == null)
+ continue;
+
doc.ReadJson(row[docOrValue].Value<JObject>());
list.Add(doc);
}

0 comments on commit 3200404

Please sign in to comment.