Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #12 from RoystonS/master

SaveArbitraryDocuments fails due to Json stream being in invalid state
  • Loading branch information...
commit b384a61137f4ef7d626220a6a0cec741d9134bc3 2 parents 3ec773a + d2b330c
@whenrik whenrik authored
Showing with 25 additions and 3 deletions.
  1. +15 −0 Tests/CouchTest.cs
  2. +10 −3 src/CouchBulkDocuments.cs
View
15 Tests/CouchTest.cs
@@ -230,6 +230,21 @@ public void ShouldSaveArbitraryDocument()
}
[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()
{
var firstCar = new LittleCar() { docType = "car", Make = "Yugo", Model = "Hell if i know" };
View
13 src/CouchBulkDocuments.cs
@@ -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();
}
Please sign in to comment.
Something went wrong with that request. Please try again.