コード例 #1
0
 /// <summary>
 /// Creates a new model from the specified Couchbase object.
 /// </summary>
 /// <returns>A new model.</returns>
 /// <param name="dictionaryObject">Dictionary object.</param>
 public PersonObfuscated(DictionaryObject dictionaryObject) :
     this(
         entryGuid : dictionaryObject.ParseGuid(JsonProperties.EntryGuid),
         entryType : dictionaryObject.GetString(JsonProperties.EntryType),
         firstName : dictionaryObject.GetString(JsonProperties.FirstName),
         lastName : dictionaryObject.GetString(JsonProperties.LastName),
         maidenName : dictionaryObject.GetString(JsonProperties.MaidenName),
         displayName : dictionaryObject.GetString(JsonProperties.DisplayName),
         organizationName : dictionaryObject.GetString(JsonProperties.OrganizationName),
         locationGuid : dictionaryObject.ParseGuid(JsonProperties.LocationGuid),
         siteGuid : dictionaryObject.ParseGuid(JsonProperties.SiteGuid),
         siteName : dictionaryObject.GetString(JsonProperties.SiteName),
         userStatus : dictionaryObject.GetString(JsonProperties.UserStatus),
         departmentName : dictionaryObject.GetString(JsonProperties.DepartmentName),
         residenceArea : dictionaryObject.GetString(JsonProperties.ResidenceArea),
         workAreaName : dictionaryObject.GetString(JsonProperties.WorkAreaName),
         teamName : dictionaryObject.GetString(JsonProperties.TeamName),
         contacts : dictionaryObject.ParseDictionaryObjects(JsonProperties.Contacts)
         .Select(Contact.Create)
         .ToList(),
         spouseEntryGuid : dictionaryObject.ParseGuid(JsonProperties.SpouseEntryGuid),
         personPrimaryPhotoGuid : dictionaryObject.ParseGuid(JsonProperties.PersonPrimaryPhotoGuid),
         primaryPhotoUrl : dictionaryObject.GetString(JsonProperties.PrimaryPhotoUrl),
         emergencyContactGuids : dictionaryObject.ParseGuids(JsonProperties.EmergencyContactGuids),
         lastUpdated : dictionaryObject.GetDate(IPerishableDataExtensions.JsonProperties.LastUpdated),
         expirationDate : dictionaryObject.GetDate(IPerishableDataExtensions.JsonProperties.ExpirationDate))
 {
 }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
            }
        }