public void TestBasicGetFragmentValues() { var doc = new MutableDocument("doc1"); doc.SetData(new Dictionary <string, object> { ["name"] = "Jason", ["address"] = new Dictionary <string, object> { ["street"] = "1 Main Street", ["phones"] = new Dictionary <string, object> { ["mobile"] = "650-123-4567" } }, ["references"] = new[] { new Dictionary <string, object> { ["name"] = "Scott" }, new Dictionary <string, object> { ["name"] = "Sam" } } }); doc["name"].String.Should().Be("Jason", "because that is what was stored"); doc["address"]["street"].String.Should().Be("1 Main Street", "because that is what was stored"); doc["address"]["phones"]["mobile"].String.Should().Be("650-123-4567", "because that is what was stored"); doc["references"][0]["name"].String.Should().Be("Scott", "because that is what was stored"); doc["references"][1]["name"].String.Should().Be("Sam", "because that is what was stored"); doc["references"][2]["name"].Value.Should().BeNull("because this is an invalid index"); doc["dummy"]["dummy"]["dummy"].Value.Should().BeNull("because these are invalid keys"); doc["dummy"]["dummy"][0]["dummy"].Value.Should().BeNull("because these are invalid keys and indices"); }
public void TestDictionaryArray() { var doc = new MutableDocument("doc1"); var data = new[] { new Dictionary <string, object> { ["name"] = "1" }, new Dictionary <string, object> { ["name"] = "2" }, new Dictionary <string, object> { ["name"] = "3" }, new Dictionary <string, object> { ["name"] = "4" } }; doc.SetData(new Dictionary <string, object> { ["dicts"] = data }); var dicts = doc.GetArray("dicts"); dicts.Count.Should().Be(4, "because that is the number of entries added"); var d1 = dicts.GetDictionary(0); var d2 = dicts.GetDictionary(1); var d3 = dicts.GetDictionary(2); var d4 = dicts.GetDictionary(3); d1.GetString("name").Should().Be("1", "because that is what was stored"); d2.GetString("name").Should().Be("2", "because that is what was stored"); d3.GetString("name").Should().Be("3", "because that is what was stored"); d4.GetString("name").Should().Be("4", "because that is what was stored"); Db.Save(doc); var gotDoc = Db.GetDocument("doc1"); var savedDicts = gotDoc.GetArray("dicts"); savedDicts.Count.Should().Be(4, "because that is the number of entries"); var savedD1 = savedDicts.GetDictionary(0); var savedD2 = savedDicts.GetDictionary(1); var savedD3 = savedDicts.GetDictionary(2); var savedD4 = savedDicts.GetDictionary(3); savedD1.GetString("name").Should().Be("1", "because that is what was stored"); savedD2.GetString("name").Should().Be("2", "because that is what was stored"); savedD3.GetString("name").Should().Be("3", "because that is what was stored"); savedD4.GetString("name").Should().Be("4", "because that is what was stored"); }
private bool ResolveConflict(MutableDocument updatedDoc, Document currentDoc) { var updateDocDict = updatedDoc.ToDictionary(); var curDocDict = currentDoc.ToDictionary(); foreach (var value in curDocDict) { if (updateDocDict.ContainsKey(value.Key) && !value.Value.Equals(updateDocDict[value.Key])) { updateDocDict[value.Key] = value.Value + ", " + updateDocDict[value.Key]; } else if (!updateDocDict.ContainsKey(value.Key)) { updateDocDict.Add(value.Key, value.Value); } } updatedDoc.SetData(updateDocDict); return(true); }