Permalink
Browse files

SaveArbitraryDocuments failed because CouchBulkDocuments always did a…

… StartObject/EndObject even if the contained object was self-contained.

Added a unit test to cover this.
  • Loading branch information...
1 parent 598b0a1 commit d2b330cf7627aad2226b57280c649ac0733a1674 @RoystonS RoystonS committed Nov 28, 2010
Showing with 25 additions and 3 deletions.
  1. +15 −0 Tests/CouchTest.cs
  2. +10 −3 src/CouchBulkDocuments.cs
View
@@ -229,6 +229,21 @@ public void ShouldSaveArbitraryDocument()
Assert.IsNotNull(littleCar._id);
}
+ [Test]
+ public void ShouldSaveArbitraryDocuments()
+ {
+ var littleCar1 = new LittleCar { docType = "car", Make = "Make1" };
+ var littleCar2 = new LittleCar { docType = "car", Make = "Make2" };
+ var docs = new List<LittleCar> { littleCar1, littleCar2 };
+
+ db.SaveArbitraryDocuments(docs, true);
+ var documentIds = db.GetAllDocuments().Select(doc => doc.Id);
+ var loadedCars = db.GetArbitraryDocuments(documentIds, () => new LittleCar());
+
+ Assert.AreEqual(littleCar1.Make, loadedCars.ElementAt(0).Make);
+ Assert.AreEqual(littleCar2.Make, loadedCars.ElementAt(1).Make);
+ }
+
[Test]
public void ShouldLoadArbitraryDocument()
{
View
@@ -31,9 +31,16 @@ public virtual void WriteJson(JsonWriter writer)
writer.WriteStartArray();
foreach (ICouchDocument doc in Docs)
{
- writer.WriteStartObject();
- doc.WriteJson(writer);
- writer.WriteEndObject();
+ if (doc is ISelfContained)
+ {
+ doc.WriteJson(writer);
+ }
+ else
+ {
+ writer.WriteStartObject();
+ doc.WriteJson(writer);
+ writer.WriteEndObject();
+ }
}
writer.WriteEndArray();
}

0 comments on commit d2b330c

Please sign in to comment.