Permalink
Browse files

CreateDocument now saves if an Id is supplied. This introduced a requ…

…irement that the object passed be an IBaseObject. The alternative is to use the dynamic keyword which pushes us into .Net 4.0
  • Loading branch information...
1 parent 258a50c commit 4b8e325b2bf9201e305f17dd1663b5ebc408687e @soitgoes committed Dec 13, 2011
@@ -59,6 +59,21 @@ public void Should_Trigger_Replication()
var obj = client.TriggerReplication("http://Professor:Farnsworth@"+ host+":5984/" +replicateDatabase, baseDatabase);
Assert.IsTrue(obj != null);
}
+ public class Bunny {
+ public Bunny() { }
+ public string Name { get; set; }
+ }
+ [Test]
+ public void Creating_A_Document_Should_Keep_Id_If_Supplied()
+ {
+ var doc = new Document<Bunny>(new Bunny());
+ doc.Id = "myid";
+ var db = client.GetDatabase(baseDatabase);
+ db.CreateDocument(doc);
+ var savedDoc = db.GetDocument("myid");
+ Assert.IsNotNull(savedDoc, "Saved doc should be able to be retrieved by the same id");
+ }
+
[Test]
public void Should_Create_Document_From_String()
{
@@ -43,9 +43,13 @@ public JObject CreateDocument(string id, string jsonForDocument)
resp.GetJObject();
}
- public JObject CreateDocument<T>(T doc)
+ public JObject CreateDocument(IBaseObject doc)
{
var serialized = ObjectSerializer.Serialize(doc);
+ if (doc.Id != null)
+ {
+ return CreateDocument(doc.Id, serialized);
+ }
return CreateDocument(serialized);
}
/// <summary>
@@ -15,7 +15,7 @@ public interface IDocumentDatabase
/// <returns>The status from CouchDb as a JObject</returns>
JObject CreateDocument(string id, string jsonForDocument);
- JObject CreateDocument<T>(T doc);
+ JObject CreateDocument(IBaseObject doc);
/// <summary>
/// Creates a document when you intend for Couch to generate the id for you.

0 comments on commit 4b8e325

Please sign in to comment.