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());
                }
            }
        }
Пример #3
0
        public void TestDictionaryWithULong()
        {
            using (var doc = new MutableDocument("test_ulong")) {
                var dict = new MutableDictionaryObject();
                dict.SetValue("high_value", UInt64.MaxValue);
                doc.SetDictionary("nested", dict);
                Db.Save(doc);
            }

            using (var doc = Db.GetDocument("test_ulong")) {
                doc["nested"]["high_value"].Value.Should().Be(UInt64.MaxValue);
            }
        }
Пример #4
0
        public void TestTypesInDictionaryToJSON()
        {
            var dic = PopulateDictData();
            var md  = new MutableDictionaryObject();

            foreach (var item in dic)
            {
                md.SetValue(item.Key, item.Value); // platform dictionary and list or array will be converted into Couchbase object in SetValue method
            }

            using (var doc = new MutableDocument("doc1")) {
                doc.SetDictionary("dict", md);
                Db.Save(doc);
            }

            using (var doc = Db.GetDocument("doc1")) {
                var dict = doc.GetDictionary("dict");
                var json = dict.ToJSON();
                ValidateToJsonValues(json, dic);
            }
        }