Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

SaveArbitraryDocuments fails due to Json stream being in invalid state #12

Merged
merged 1 commit into from

2 participants

@RoystonS

Hi there,

I've found a problem with Divan with SaveArbitraryDocuments. Basically, it doesn't work because when CouchBulkDocuments writes itself out, it always assumes that its contained objects are not ISelfContained, and so always wraps their writes with a StartObject/EndObject. This fails for SaveArbitraryDocuments as that works with CouchDocumentWrapper, which does implement ISelfContained.

I've added a unit test, and popped a fix in. If it looks right, do feel free to pull the change in.

Cheers,
Royston.

@RoystonS RoystonS SaveArbitraryDocuments failed because CouchBulkDocuments always did a…
… StartObject/EndObject even if the contained object was self-contained.

Added a unit test to cover this.
d2b330c
@whenrik whenrik merged commit b384a61 into foretagsplatsen:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 28, 2010
  1. @RoystonS

    SaveArbitraryDocuments failed because CouchBulkDocuments always did a…

    RoystonS authored
    … StartObject/EndObject even if the contained object was self-contained.
    
    Added a unit test to cover this.
This page is out of date. Refresh to see the latest.
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();
}
Something went wrong with that request. Please try again.