public void TestSetNull() { using (var mDoc = new MutableDocument("test")) { var mDict = new MutableDictionaryObject(); mDict.SetValue("obj-null", null); mDict.SetString("string-null", null); mDict.SetArray("array-null", null); mDict.SetDictionary("dict-null", null); mDoc.SetDictionary("dict", mDict); SaveDocument(mDoc, doc => { doc.Count.Should().Be(1); doc.Contains("dict").Should().BeTrue(); var d = doc.GetDictionary("dict"); d.Should().NotBeNull(); d.Count.Should().Be(4); d.Contains("obj-null").Should().BeTrue(); d.Contains("string-null").Should().BeTrue(); d.Contains("array-null").Should().BeTrue(); d.Contains("dict-null").Should().BeTrue(); d.GetValue("obj-null").Should().BeNull();; d.GetValue("string-null").Should().BeNull();; d.GetValue("array-null").Should().BeNull();; d.GetValue("dict-null").Should().BeNull(); }); } }
public void TestGetDictionary() { var mNestedDict = new MutableDictionaryObject(); mNestedDict.SetLong("key1", 1L); mNestedDict.SetString("key2", "Hello"); mNestedDict.SetValue("key3", null); var mDict = new MutableDictionaryObject(); mDict.SetLong("key1", 1L); mDict.SetString("key2", "Hello"); mDict.SetValue("key3", null); mDict.SetDictionary("nestedDict", mNestedDict); using (var mDoc = new MutableDocument("test")) { mDoc.SetDictionary("dict", mDict); using (var doc = Db.Save(mDoc)) { var dict = doc.GetDictionary("dict"); dict.Should().NotBeNull(); dict.GetDictionary("not-exists").Should().BeNull(); var nestedDict = dict.GetDictionary("nestedDict"); nestedDict.Should().NotBeNull(); nestedDict.ToDictionary().ShouldBeEquivalentTo(mNestedDict.ToDictionary()); } } }
public void TestSetNestedDictionaries() { var doc = new MutableDocument("doc1"); var level1 = new MutableDictionaryObject(); level1.SetString("name", "n1"); doc.SetDictionary("level1", level1); var level2 = new MutableDictionaryObject(); level2.SetString("name", "n2"); level1.SetDictionary("level2", level2); var level3 = new MutableDictionaryObject(); level3.SetString("name", "n3"); level2.SetDictionary("level3", level3); doc.GetDictionary("level1").ShouldBeEquivalentTo(level1, "because that is what was inserted"); level1.GetDictionary("level2").ShouldBeEquivalentTo(level2, "because that is what was inserted"); level2.GetDictionary("level3").ShouldBeEquivalentTo(level3, "because that is what was inserted"); var dict = new Dictionary <string, object> { ["level1"] = new Dictionary <string, object> { ["name"] = "n1", ["level2"] = new Dictionary <string, object> { ["name"] = "n2", ["level3"] = new Dictionary <string, object> { ["name"] = "n3" } } } }; doc.ToDictionary().ShouldBeEquivalentTo(dict, "because otherwise the document's contents are incorrect"); Db.Save(doc); var gotDoc = Db.GetDocument("doc1"); gotDoc.GetDictionary("level1").Should().NotBeSameAs(level1); gotDoc.ToDictionary().ShouldBeEquivalentTo(dict); }