Exemple #1
0
        public void SerializesInsightWithScore()
        {
            var jObject = JObject.Parse(jsonWithScore);
            var insight = Insight.FromSerializedInsight(new SerializedInsight
            {
                Id             = jObject["id"].Value <string>(),
                SourceModel    = jObject["source-model"].Value <string>(),
                GroupId        = jObject["group-id"]?.Value <string>(),
                GeneratedTime  = jObject["generated-time"].Value <double>(),
                CloseTime      = jObject["close-time"].Value <double>(),
                Symbol         = jObject["symbol"].Value <string>(),
                Ticker         = jObject["ticker"].Value <string>(),
                Type           = (InsightType)Enum.Parse(typeof(InsightType), jObject["type"].Value <string>(), true),
                ReferenceValue = jObject["reference"].Value <decimal>(),
                Direction      = (InsightDirection)Enum.Parse(typeof(InsightDirection), jObject["direction"].Value <string>(), true),
                Period         = jObject["period"].Value <double>(),
                Magnitude      = jObject["magnitude"].Value <double>(),
                ScoreIsFinal   = jObject["score-final"].Value <bool>(),
                ScoreMagnitude = jObject["score-magnitude"].Value <double>(),
                ScoreDirection = jObject["score-direction"].Value <double>(),
                EstimatedValue = jObject["estimated-value"].Value <decimal>()
            });
            var result = JsonConvert.SerializeObject(insight, Formatting.Indented);

            Assert.AreEqual(jsonWithScore, result);
        }
        public void SerializesOldInsightWithMissingCreatedTime()
        {
            var serializedInsight = JsonConvert.DeserializeObject <SerializedInsight>(jsonWithMissingCreatedTime);
            var insight           = Insight.FromSerializedInsight(serializedInsight);
            var result            = JsonConvert.SerializeObject(insight, Formatting.None);

            Assert.AreEqual(serializedInsight.CreatedTime, serializedInsight.GeneratedTime);
            Assert.AreEqual(jsonWithExpectedOutputFromMissingCreatedTimeValue, result);
        }