public void ShouldUseETagForView() { var design = db.NewDesignDocument("computers"); design.AddView("by_cpumake", @"function(doc) { emit(doc.CPU, doc); }"); db.WriteDocument(design); CouchJsonDocument doc1 = db.CreateDocument("{\"CPU\": \"Intel\"}"); db.CreateDocument("{\"CPU\": \"AMD\"}"); db.CreateDocument("{\"CPU\": \"Via\"}"); db.CreateDocument("{\"CPU\": \"Sparq\"}"); CouchQuery query = db.Query("computers", "by_cpumake").StartKey("Intel").EndKey("Via").CheckETagUsingHead(); // Query has no result yet so should not be cached Assert.That(query.IsCachedAndValid(), Is.False); query.GetResult(); // Now it is cached and should be valid Assert.That(query.IsCachedAndValid(), Is.True); // Make a change invalidating the view db.SaveDocument(doc1); // It should now be false Assert.That(query.IsCachedAndValid(), Is.False); query.GetResult(); // And now it should be cached again Assert.That(query.IsCachedAndValid(), Is.True); query.GetResult(); // Still cached of course Assert.That(query.IsCachedAndValid(), Is.True); }
public void ShouldHandleStreaming() { var design = new CouchDesignDocument("test", db); design.AddView("docs", "function (doc) { emit(null, null); } "); design.Synch(); var doc = new CouchJsonDocument("{\"_id\":\"123\", \"CPU\": \"Intel\"}"); db.SaveDocument(doc); var result = db.Query("test", "docs").StreamResult <CouchDocument>(); Assert.That(result.FirstOrDefault() != null, "there should be one doc present"); try { // this should throw an invalid operation exception result.FirstOrDefault(); } finally { db.DeleteDocument(doc); db.DeleteDocument(design); } }
public void ShouldStoreGetAndDeleteAttachment() { var doc = new CouchJsonDocument("{\"CPU\": \"Intel\"}"); ICouchDocument cd = db.CreateDocument(doc); var attachmentName = "someAttachment.txt"; Assert.That(db.HasAttachment(cd, attachmentName), Is.False); db.WriteAttachment(cd, attachmentName, "jabbadabba", "text/plain"); Assert.That(db.HasAttachment(cd, attachmentName), Is.True); using (var response = db.ReadAttachment(cd, attachmentName)) { using (var reader = new StreamReader(response.GetResponseStream())) { Assert.That(reader.ReadToEnd(), Is.EqualTo("jabbadabba")); } } db.WriteAttachment(cd, attachmentName, "jabbadabba-doo", "text/plain"); Assert.That(db.HasAttachment(cd, attachmentName), Is.True); using (var response = db.ReadAttachment(cd, attachmentName)) { using (var reader = new StreamReader(response.GetResponseStream())) { Assert.That(reader.ReadToEnd(), Is.EqualTo("jabbadabba-doo")); } } db.DeleteAttachment(cd, attachmentName); Assert.That(db.HasAttachment(cd, attachmentName), Is.False); }
public void ShouldCreateDocument() { var doc = new CouchJsonDocument("{\"CPU\": \"Intel\"}"); ICouchDocument cd = db.CreateDocument(doc); Assert.That(db.CountDocuments(), Is.EqualTo(1)); Assert.That(cd.Id, Is.Not.Null); Assert.That(cd.Rev, Is.Not.Null); }
public void ShouldSaveDocumentWithId() { var doc = new CouchJsonDocument("{\"_id\":\"123\", \"CPU\": \"Intel\"}"); ICouchDocument cd = db.SaveDocument(doc); Assert.That(db.CountDocuments(), Is.EqualTo(1)); Assert.That(cd.Id, Is.Not.Null); Assert.That(cd.Rev, Is.Not.Null); }
public void ShouldReturnNullWhenNotFound() { var doc = db.GetDocument <CouchJsonDocument>("jadda"); Assert.That(doc, Is.Null); CouchJsonDocument doc2 = db.GetDocument("jadda"); Assert.That(doc2, Is.Null); }
public void ShouldGetDocument() { const string doc = "{\"CPU\": \"Intel\"}"; CouchJsonDocument oldDoc = db.CreateDocument(doc); CouchJsonDocument newDoc = db.GetDocument(oldDoc.Id); Assert.That(oldDoc.Id, Is.EqualTo(newDoc.Id)); Assert.That(oldDoc.Rev, Is.EqualTo(newDoc.Rev)); }
public void ShouldCreateDocumentWithSpecifiedId() { const string doc = "{\"_id\": \"foo\"}"; var doc1 = new CouchJsonDocument(doc); db.SaveDocument(doc1); Assert.That(db.CountDocuments(), Is.EqualTo(1)); Assert.That(doc1.Id, Is.EqualTo("foo")); Assert.That(doc1.Rev, Is.Not.Null); }
public void ShouldCheckChangedDocument() { CouchJsonDocument doc = db.CreateDocument("{\"CPU\": \"Intel\"}"); CouchJsonDocument doc2 = db.GetDocument(doc.Id); Assert.That(db.HasDocumentChanged(doc), Is.False); doc2.Obj["CPU"] = JToken.FromObject("AMD"); db.WriteDocument(doc2); Assert.That(db.HasDocumentChanged(doc), Is.True); }
public void ShouldThrowConflictExceptionOnAlreadyExists() { const string doc = "{\"CPU\": \"Intel\"}"; CouchJsonDocument doc1 = db.CreateDocument(doc); var doc2 = new CouchJsonDocument(doc) { Id = doc1.Id }; db.WriteDocument(doc2); }
public void ShouldThrowConflictExceptionOnStaleWrite() { const string doc = "{\"CPU\": \"Intel\"}"; CouchJsonDocument doc1 = db.CreateDocument(doc); CouchJsonDocument doc2 = db.GetDocument(doc1.Id); doc1.Obj["CPU"] = JToken.FromObject("AMD"); db.SaveDocument(doc1); doc2.Obj["CPU"] = JToken.FromObject("Via"); db.SaveDocument(doc2); }
public void ShouldCreateDocuments() { const string doc = "{\"CPU\": \"Intel\"}"; var doc1 = new CouchJsonDocument(doc); var doc2 = new CouchJsonDocument(doc); IList<ICouchDocument> list = new List<ICouchDocument> { doc1, doc2 }; db.SaveDocuments(list, true); Assert.That(db.CountDocuments(), Is.EqualTo(2)); Assert.That(doc1.Id, Is.Not.Null); Assert.That(doc1.Rev, Is.Not.Null); Assert.That(doc2.Id, Is.Not.Null); Assert.That(doc2.Rev, Is.Not.Null); Assert.That(doc1.Id, Is.Not.EqualTo(doc2.Id)); }
public void ShouldDeleteDocuments() { const string doc = "{\"CPU\": \"Intel\"}"; CouchJsonDocument doc1 = db.CreateDocument(doc); CouchJsonDocument doc2 = db.CreateDocument(doc); if (String.Compare(doc1.Id, doc2.Id) < 0) { db.DeleteDocuments(doc1.Id, doc2.Id); } else { db.DeleteDocuments(doc2.Id, doc1.Id); } Assert.That(db.HasDocument(doc1.Id), Is.False); Assert.That(db.HasDocument(doc2.Id), Is.False); }
public void ShouldCreateDocuments() { const string doc = "{\"CPU\": \"Intel\"}"; var doc1 = new CouchJsonDocument(doc); var doc2 = new CouchJsonDocument(doc); IList <ICouchDocument> list = new List <ICouchDocument> { doc1, doc2 }; db.SaveDocuments(list, true); Assert.That(db.CountDocuments(), Is.EqualTo(2)); Assert.That(doc1.Id, Is.Not.Null); Assert.That(doc1.Rev, Is.Not.Null); Assert.That(doc2.Id, Is.Not.Null); Assert.That(doc2.Rev, Is.Not.Null); Assert.That(doc1.Id, Is.Not.EqualTo(doc2.Id)); }
public void ShouldGetDocuments() { const string doc = "{\"CPU\": \"Intel\"}"; CouchJsonDocument doc1 = db.CreateDocument(doc); CouchJsonDocument doc2 = db.CreateDocument(doc); var ids = new List <string> { doc1.Id, doc2.Id }; // Bulk request for multiple keys. var docs = db.GetDocuments(ids); Assert.That(doc1.Id, Is.EqualTo(docs.First().Id)); Assert.That(doc2.Id, Is.EqualTo(docs.Last().Id)); var keys = new List <object> { doc1.Id, doc2.Id }; // Bulk query on a view for multple keys. docs = db.QueryAllDocuments().Keys(keys).IncludeDocuments().GetResult().Documents(); Assert.That(doc1.Id, Is.EqualTo(docs.First().Id)); Assert.That(doc2.Id, Is.EqualTo(docs.Last().Id)); }
public void ShouldHandleStreaming() { var design = new CouchDesignDocument("test", db); design.AddView("docs", "function (doc) { emit(null, null); } "); design.Synch(); var doc = new CouchJsonDocument("{\"_id\":\"123\", \"CPU\": \"Intel\"}"); db.SaveDocument(doc); var result = db.Query("test", "docs").StreamResult<CouchDocument>(); Assert.That(result.FirstOrDefault() != null, "there should be one doc present"); try { // this should throw an invalid operation exception result.FirstOrDefault(); } finally { db.DeleteDocument(doc); db.DeleteDocument(design); } }
public void ShouldStoreGetAndDeleteAttachment() { var doc = new CouchJsonDocument("{\"CPU\": \"Intel\"}"); ICouchDocument cd = db.CreateDocument(doc); Assert.That(db.HasAttachment(cd), Is.False); db.WriteAttachment(cd, "jabbadabba", "text/plain"); Assert.That(db.HasAttachment(cd), Is.True); Assert.That(db.ReadAttachment(cd), Is.EqualTo("jabbadabba")); db.WriteAttachment(cd, "jabbadabba-doo", "text/plain"); Assert.That(db.HasAttachment(cd), Is.True); Assert.That(db.ReadAttachment(cd), Is.EqualTo("jabbadabba-doo")); db.DeleteAttachment(cd); Assert.That(db.HasAttachment(cd), Is.False); }