示例#1
0
        public void TestJsonDeserializer()
        {
            object deserializedObject;

            using (var reader = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "\\Data\\TestCall.json"))
            {
                deserializedObject = JsonSerializationExtensions.DeserializeStream(reader.BaseStream, typeof(Call));
            }

            deserializedObject.Should().NotBeNull();
            deserializedObject.Should().BeOfType <Call>();

            var callObject = deserializedObject as Call;

            callObject.Name.Should().Be("Priority 1E Cardiac Arrest D12");
        }
示例#2
0
        /// <summary>
        /// Update hand pointers from specified user info data.
        /// </summary>
        /// <param name="skeletons">
        /// Enumeration of UserInfo structures.
        /// </param>
        public void UpdateSkeletons(Skeleton[] skeletons)
        {
            if (skeletons == null)
            {
                throw new ArgumentNullException("skeletons");
            }

            if (this.skeletons == null || this.skeletons.Length != skeletons.Length)
            {
                this.skeletons = new object[skeletons.Length];
            }

            for (int i = 0; i < this.skeletons.Length; i++)
            {
                this.skeletons[i] = JsonSerializationExtensions.ExtractSerializableJsonData(skeletons[i]);
            }
        }
示例#3
0
        public void TestJsonSerializer()
        {
            var call = new Call();

            call.DepartmentId    = 1;
            call.Name            = "Priority 1E Cardiac Arrest D12";
            call.NatureOfCall    = "RP reports a person lying on the street not breathing.";
            call.Notes           = "RP doesn't know how to do CPR, can't roll over patient";
            call.MapPage         = "22T";
            call.GeoLocationData = "39.27710789298309,-119.77201511943328";
            call.Dispatches      = new Collection <CallDispatch>();
            call.LoggedOn        = DateTime.UtcNow;
            call.ReportingUserId = Guid.NewGuid().ToString();

            var serialization = JsonSerializationExtensions.SerializeJson(call);

            serialization.Should().NotBeNull();
            serialization.Should().NotBeEmpty();
        }
        public static PropertyBuilder <T> HasJsonConversion <T>(this PropertyBuilder <T> propertyBuilder) where T : class, new()
        {
            ValueConverter <T, string> converter = new ValueConverter <T, string>
                                                   (
                model => JsonSerializationExtensions.Serialize(model),
                valueFromDb => JsonSerializationExtensions.Deserialize <T>(valueFromDb) ?? new T()
                                                   );

            ValueComparer <T> comparer = new ValueComparer <T>
                                         (
                (leftModel, rightModel) => JsonSerializationExtensions.Serialize(leftModel) == JsonSerializationExtensions.Serialize(rightModel),
                model => model == null ? 0 : JsonSerializationExtensions.Serialize(model).GetHashCode(),
                model => JsonSerializationExtensions.Deserialize <T>(JsonSerializationExtensions.Serialize(model))
                                         );

            propertyBuilder.HasConversion(converter);
            propertyBuilder.Metadata.SetValueConverter(converter);
            propertyBuilder.Metadata.SetValueComparer(comparer);

            return(propertyBuilder);
        }