public void ReplicationTest() { RemoteDB remoteDB = new RemoteDB(); //DocInfo[] info = remoteDB.GetAllDocuments("http://127.0.0.1:5984", "test"); NouchDB nouchDB = new NouchDB(); //nouchDB.Delete(new Options()); //Debug.WriteLine(nouchDB.Changes()); //string res = RevsDiff(nouchDB, remoteDB, info); //res = "{\"keys\":" + res + "}"; long lastSync = nouchDB.GetLastSync("http://127.0.0.1:5984/test"); JsonData docs = remoteDB.GetChanges("http://127.0.0.1:5984", "test", true, lastSync); foreach (JsonData result in docs["results"]) { string id = (string)result["id"]; string rev = (string)result["changes"][0]["rev"]; // //result.Remove("_rev"); // //result.Remove("_id"); string doc = result["doc"].ToJson(); try { nouchDB.PutDoc(id, doc, rev); } catch (Exception ee) { Debug.WriteLine(ee.ToString()); } } Debug.WriteLine("Document sync: " + docs["results"].Count); Debug.WriteLine(nouchDB.AllDocs()); nouchDB.SetLastSync("http://127.0.0.1:5984/test", (int)docs["last_seq"]); //nouchDB.Close(); }
public void SimpleInsertAndUpdate() { NouchDB nouchDB = new NouchDB(); //nouchDB.Delete(new Options()); //nouchDB.Open(dbName); var customer = new Customer { name = "Joe Bloggs", age = 31 }; string input = JsonMapper.ToJson(customer); nouchDB.PutDoc("doc_id1", input); string output = nouchDB.GetDoc("doc_id1"); Assert.AreEqual(input, output); string res = nouchDB.Info(); var customer2 = new Customer { name = "Fred", age = 55 }; input = JsonMapper.ToJson(customer2); nouchDB.PutDoc("doc_id1", input); output = nouchDB.GetDoc("doc_id1"); Assert.AreEqual(input, output); List <int> obj = JsonMapper.ToObject <List <int> >(nouchDB.Info()); Assert.AreEqual(1, obj[0]); // 1 doc Assert.AreEqual(2, obj[1]); // 2 sequences Debug.Write(nouchDB.AllDocs()); //nouchDB.Close(); }