private object FleeceValueToObject(int index) { var value = FLValueAtIndex(index); if (value == null) { return(null); } var root = new MRoot(_context, value, false); return(root.AsObject()); }
public unsafe void TestReadOnlyDictionary() { var now = DateTimeOffset.UtcNow; var nestedArray = new[] { 1L, 2L, 3L }; var nestedDict = new Dictionary <string, object> { ["foo"] = "bar" }; var masterData = new Dictionary <string, object> { ["date"] = now, ["array"] = nestedArray, ["dict"] = nestedDict }; var flData = new FLSliceResult(); Db.InBatch(() => { flData = masterData.FLEncode(); }); try { var context = new DocContext(Db, null); using (var mRoot = new MRoot(context)) { mRoot.Context.Should().BeSameAs(context); FLDoc *fleeceDoc = Native.FLDoc_FromResultData(flData, FLTrust.Trusted, Native.c4db_getFLSharedKeys(Db.c4db), FLSlice.Null); var flValue = Native.FLDoc_GetRoot(fleeceDoc); var mDict = new MDict(new MValue(flValue), mRoot); var deserializedDict = new DictionaryObject(mDict, false); deserializedDict["bogus"].Blob.Should().BeNull(); deserializedDict["date"].Date.Should().Be(now); deserializedDict.GetDate("bogus").Should().Be(DateTimeOffset.MinValue); deserializedDict.GetArray("array").Should().Equal(1L, 2L, 3L); deserializedDict.GetArray("bogus").Should().BeNull(); deserializedDict.GetDictionary("dict").Should().BeEquivalentTo(nestedDict); deserializedDict.GetDictionary("bogus").Should().BeNull(); var dict = deserializedDict.ToDictionary(); dict["array"].As <IList>().Should().Equal(1L, 2L, 3L); dict["dict"].As <IDictionary <string, object> >().Should().BeEquivalentTo(nestedDict); var isContain = mDict.Contains(""); isContain.Should().BeFalse(); Native.FLDoc_Release(fleeceDoc); } } finally { Native.FLSliceResult_Release(flData); } }
public unsafe void TestReadOnlyArray() { var now = DateTimeOffset.UtcNow; var nestedArray = new[] { 1L, 2L, 3L }; var nestedDict = new Dictionary <string, object> { ["foo"] = "bar" }; var masterData = new object[] { 1, "str", nestedArray, now, nestedDict }; var flData = new FLSliceResult(); Db.InBatch(() => { flData = masterData.FLEncode(); }); try { var context = new DocContext(Db, null); using (var mRoot = new MRoot(context)) { mRoot.Context.Should().BeSameAs(context); FLDoc *fleeceDoc = Native.FLDoc_FromResultData(flData, FLTrust.Trusted, Native.c4db_getFLSharedKeys(Db.c4db), FLSlice.Null); var flValue = Native.FLDoc_GetRoot(fleeceDoc); var mArr = new FleeceMutableArray(new MValue(flValue), mRoot); var deserializedArray = new ArrayObject(mArr, false); deserializedArray.GetArray(2).Should().Equal(1L, 2L, 3L); deserializedArray.GetArray(3).Should().BeNull(); deserializedArray.GetBlob(1).Should().BeNull(); deserializedArray.GetDate(3).Should().Be(now); deserializedArray.GetDate(4).Should().Be(DateTimeOffset.MinValue); deserializedArray[1].ToString().Should().Be("str"); deserializedArray.GetString(2).Should().BeNull(); deserializedArray.GetDictionary(4).Should().BeEquivalentTo(nestedDict); deserializedArray[0].Dictionary.Should().BeNull(); var list = deserializedArray.ToList(); list[2].Should().BeAssignableTo <IList <object> >(); list[4].Should().BeAssignableTo <IDictionary <string, object> >(); var mVal = new MValue(); mVal.Dispose(); Native.FLDoc_Release(fleeceDoc); } } finally { Native.FLSliceResult_Release(flData); } var mroot = new MRoot(); }
public unsafe void TestReadOnlyDictionary() { var now = DateTimeOffset.UtcNow; var nestedArray = new[] { 1L, 2L, 3L }; var nestedDict = new Dictionary <string, object> { ["foo"] = "bar" }; var masterData = new Dictionary <string, object> { ["date"] = now, ["array"] = nestedArray, ["dict"] = nestedDict }; var flData = new FLSliceResult(); Db.InBatch(() => { flData = masterData.FLEncode(); }); try { var context = new DocContext(Db, null); using (var mRoot = new MRoot(context)) { mRoot.Context.Should().BeSameAs(context); var flValue = NativeRaw.FLValue_FromTrustedData((FLSlice)flData); var mDict = new MDict(new MValue(flValue), mRoot); var deserializedDict = new DictionaryObject(mDict, false); deserializedDict["bogus"].Blob.Should().BeNull(); deserializedDict["date"].Date.Should().Be(now); deserializedDict.GetDate("bogus").Should().Be(DateTimeOffset.MinValue); deserializedDict.GetArray("array").Should().Equal(1L, 2L, 3L); deserializedDict.GetArray("bogus").Should().BeNull(); deserializedDict.GetDictionary("dict").Should().BeEquivalentTo(nestedDict); deserializedDict.GetDictionary("bogus").Should().BeNull(); var dict = deserializedDict.ToDictionary(); dict["array"].As <IList>().Should().Equal(1L, 2L, 3L); dict["dict"].As <IDictionary <string, object> >().ShouldBeEquivalentTo(nestedDict); } } finally { Native.FLSliceResult_Free(flData); } }
public unsafe void TestSharedstrings() { var now = DateTimeOffset.UtcNow; var nestedArray = new[] { 1L, 2L, 3L }; var nestedDict = new Dictionary <string, object> { ["foo"] = "bar" }; var masterData = new object[] { 1, "str", nestedArray, now, nestedDict }; var flData = new FLSliceResult(); Db.InBatch(() => { flData = masterData.FLEncode(); }); try { var context = new DocContext(Db, null); using (var mRoot = new MRoot(context)) { var flValue = NativeRaw.FLValue_FromTrustedData((FLSlice)flData); var mArr = new MArray(new MValue(flValue), mRoot); var sharedstrings = context.SharedStrings; FLEncoder *fLEncoder = Db.SharedEncoder; mRoot.FLEncode(fLEncoder); mRoot.Encode(); var isReadonly = mArr.IsReadOnly; isReadonly.Should().BeFalse(); #if !WINDOWS_UWP Assert.Throws <NotImplementedException>(() => mArr.IndexOf(now)); Assert.Throws <NotImplementedException>(() => mArr.Contains(now)); Assert.Throws <NotImplementedException>(() => mArr.Remove(now)); Assert.Throws <NotImplementedException>(() => mArr.CopyTo(new object[] { }, 12)); #endif var flDict = Native.FLValue_AsDict(flValue); var sharedStringCache = new SharedStringCache(); var sharedStringCache1 = new SharedStringCache(sharedStringCache); sharedStringCache1 = new SharedStringCache(sharedStringCache, flDict); var i = default(FLDictIterator); var iterKey = sharedStringCache1.GetDictIterKey(&i); sharedStringCache1.UseDocumentRoot(flDict); } } finally { Native.FLSliceResult_Free(flData); } }
public unsafe void TestReadOnlyArray() { var now = DateTimeOffset.UtcNow; var nestedArray = new[] { 1L, 2L, 3L }; var nestedDict = new Dictionary <string, object> { ["foo"] = "bar" }; var masterData = new object[] { 1, "str", nestedArray, now, nestedDict }; var flData = new FLSliceResult(); Db.InBatch(() => { flData = masterData.FLEncode(); }); try { var context = new DocContext(Db, null); using (var mRoot = new MRoot(context)) { mRoot.Context.Should().BeSameAs(context); var flValue = NativeRaw.FLValue_FromTrustedData((FLSlice)flData); var mArr = new MArray(new MValue(flValue), mRoot); var deserializedArray = new ArrayObject(mArr, false); deserializedArray.GetArray(2).Should().Equal(1L, 2L, 3L); deserializedArray.GetArray(3).Should().BeNull(); deserializedArray.GetBlob(1).Should().BeNull(); deserializedArray.GetDate(3).Should().Be(now); deserializedArray.GetDate(4).Should().Be(DateTimeOffset.MinValue); deserializedArray[1].ToString().Should().Be("str"); deserializedArray.GetString(2).Should().BeNull(); deserializedArray.GetDictionary(4).Should().BeEquivalentTo(nestedDict); deserializedArray[0].Dictionary.Should().BeNull(); var list = deserializedArray.ToList(); list[2].Should().BeAssignableTo <IList <object> >(); list[4].Should().BeAssignableTo <IDictionary <string, object> >(); } } finally { Native.FLSliceResult_Free(flData); } }