public void TestCreateDictionaryWithCSharpDictionary()
        {
            var dict = new Dictionary <string, object> {
                ["street"] = "1 Main street",
                ["city"]   = "Mountain View",
                ["state"]  = "CA"
            };
            var address = new MutableDictionaryObject(dict);

            address.ShouldBeEquivalentTo(dict, "because that is what was stored");
            address.ToDictionary().ShouldBeEquivalentTo(dict, "because that is what was stored");

            var doc1 = new MutableDocument("doc1");

            doc1.SetDictionary("address", address);
            doc1.GetDictionary("address")
            .Should()
            .BeSameAs(address, "because the document should return the same instance");

            Db.Save(doc1);
            var gotDoc = Db.GetDocument("doc1");

            gotDoc.GetDictionary("address")
            .ToDictionary()
            .ShouldBeEquivalentTo(dict, "because the content should not have changed");
        }
        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 TestGetValueFromNewEmptyDictionary()
        {
            DictionaryObject dict = new MutableDictionaryObject();

            dict.GetInt("key").Should().Be(0, "because that is the default value");
            dict.GetLong("key").Should().Be(0L, "because that is the default value");
            dict.GetDouble("key").Should().Be(0.0, "because that is the default value");
            dict.GetBoolean("key").Should().Be(false, "because that is the default value");
            dict.GetDate("key").Should().Be(DateTimeOffset.MinValue, "because that is the default value");
            dict.GetBlob("key").Should().BeNull("because that is the default value");
            dict.GetValue("key").Should().BeNull("because that is the default value");
            dict.GetString("key").Should().BeNull("because that is the default value");
            dict.GetDictionary("key").Should().BeNull("because that is the default value");
            dict.GetArray("key").Should().BeNull("because that is the default value");
            dict.ToDictionary().Should().BeEmpty("because the dictionary is empty");

            var doc = new MutableDocument("doc1");

            doc.SetDictionary("dict", dict);

            Db.Save(doc);
            var gotDoc = Db.GetDocument("doc1");

            dict = gotDoc.GetDictionary("dict");
            dict.GetInt("key").Should().Be(0, "because that is the default value");
            dict.GetLong("key").Should().Be(0L, "because that is the default value");
            dict.GetDouble("key").Should().Be(0.0, "because that is the default value");
            dict.GetBoolean("key").Should().Be(false, "because that is the default value");
            dict.GetDate("key").Should().Be(DateTimeOffset.MinValue, "because that is the default value");
            dict.GetBlob("key").Should().BeNull("because that is the default value");
            dict.GetValue("key").Should().BeNull("because that is the default value");
            dict.GetString("key").Should().BeNull("because that is the default value");
            dict.GetDictionary("key").Should().BeNull("because that is the default value");
            dict.GetArray("key").Should().BeNull("because that is the default value");
            dict.ToDictionary().Should().BeEmpty("because the dictionary is empty");
        }
        public void TestCreateDictionary()
        {
            var address = new MutableDictionaryObject();

            address.Count.Should().Be(0, "because the dictionary is empty");
            address.ToDictionary().Should().BeEmpty("because the dictionary is empty");

            var doc1 = new MutableDocument("doc1");

            doc1.SetDictionary("address", address);
            doc1.GetDictionary("address")
            .Should()
            .BeSameAs(address, "because the document should return the same instance");

            Db.Save(doc1);
            var gotDoc = Db.GetDocument("doc1");

            gotDoc.GetDictionary("address").ToDictionary().Should().BeEmpty("because the content should not have changed");
        }
        public void TestEnumeratingDictionary()
        {
            var dict = new MutableDictionaryObject();

            for (int i = 0; i < 20; i++)
            {
                dict.SetInt($"key{i}", i);
            }

            var content = dict.ToDictionary();
            var result  = new Dictionary <string, object>();

            foreach (var item in dict)
            {
                result[item.Key] = item.Value;
            }

            result.ShouldBeEquivalentTo(content, "because that is the correct content");
            content = dict.Remove("key2").SetInt("key20", 20).SetInt("key21", 21).ToDictionary();

            result = new Dictionary <string, object>();
            foreach (var item in dict)
            {
                result[item.Key] = item.Value;
            }

            result.ShouldBeEquivalentTo(content, "because that is the correct content");

            var doc = new MutableDocument("doc1");

            doc.SetDictionary("dict", dict);
            SaveDocument(doc, d =>
            {
                result      = new Dictionary <string, object>();
                var dictObj = d.GetDictionary("dict");
                foreach (var item in dictObj)
                {
                    result[item.Key] = item.Value;
                }

                result.ShouldBeEquivalentTo(content, "because that is the correct content");
            });
        }