public void Diff() { var original = new Dictionary <string, double> { ["1"] = 1.0, ["2"] = 2.0, ["3"] = 3.0, }; var other = new Dictionary <string, double> { ["1"] = 1.0, ["2"] = 2.1, ["4"] = 4.0, }; Assert.IsFalse(original.Diff(original, out _)); Assert.IsTrue(original.Diff(other, out DictionaryDiff <string, double> diff)); Check("1", 1.0, diff.Unchanged); Check("3", 3.0, diff.Removed); Check("4", 4.0, diff.Added); Assert.AreEqual(1, diff.Changed.Count); Assert.AreEqual("2", diff.Changed[0].Key); Assert.AreEqual(2.0, diff.Changed[0].OldValue); Assert.AreEqual(2.1, diff.Changed[0].NewValue); Assert.AreEqual(
public void Diff() { var a = new Dictionary<string, int>() { { "A", 1 }, { "B", 2 }, {"C", 3}}; var b = a.Assoc("B", -2); var diff = a.Diff(b); Assert.AreEqual("([B,(2, -2)])", diff.Print()); diff = a.Diff(b, "A".And("B")); Assert.AreEqual("([B,(2, -2)])", diff.Print()); diff = a.Diff(b, "A".And("C")); Assert.AreEqual("()", diff.Print()); var copyA = a.Copy(); diff = a.Diff(copyA); Assert.AreEqual("()", diff.Print()); }
// Method to save multiple (list/collection) records into couchbase db public void SaveUsers(string users) { var vals = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(users); foreach (var employee in vals) { employee.Add("type", "employee"); // if document doesnt exists, and empty one will be created var doc = couchDatabase.GetDocument(employee["id"].ToString()); try { if (doc.Properties == null) { doc.PutProperties(employee); } else { var props = new Dictionary <string, object>(doc.Properties); var keys = props.Diff(employee); if (keys.Count > 0) { foreach (var key in keys) { props[key] = employee[key]; } doc.PutProperties(props); } } } catch (CouchbaseLiteException ex) { Debug.WriteLine(ex.Message); } } }
// Method to save 1 record into couchbase public string SaveUser(Employee employee) { var lEmployee = employee.GetDictionary(); lEmployee.Add("type", "employee"); // if document doesnt exists, and empty one will be created var doc = couchDatabase.GetDocument(lEmployee["id"].ToString()); try { if (doc.Properties == null) { doc.PutProperties(lEmployee); } else { var props = new Dictionary <string, object>(doc.Properties); var keys = props.Diff(lEmployee); if (keys.Count > 0) { foreach (var key in keys) { props[key] = lEmployee[key]; } doc.PutProperties(props); } } return(""); } catch (CouchbaseLiteException ex) { return(ex.Message); } }
public void Diff_MissingFields() { var a = new Dictionary<string, int>() { { "A", 1 } }; var b = new Dictionary<string, int>() { { "B", 2 } }; var diff = a.Diff(b, nullVal: -1); Assert.AreEqual("([A,(1, -1)],[B,(-1, 2)])", diff.Print()); }