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 void UpdateDoc(MutableDocument doc, int rounds, string tag) { for (var i = 1; i <= rounds; i++) { doc.SetInt("update", i); doc.SetString("tag", tag); var address = doc.GetDictionary("address"); address.Should().NotBeNull(); var street = $"{i} street."; address.SetString("street", street); var phones = doc.GetArray("phones"); phones.Should().NotBeNull(); phones.Count.Should().Be(2); var phone = $"650-000-{i:D4}"; phones.SetString(0, phone); doc.SetDate("updated", DateTimeOffset.UtcNow); Db.Save(doc).Dispose(); } }