public static UserInteraction FromJson(JsonObject jsonObject) { IJsonValue value; if (!jsonObject.TryGetValue("type", out value)) return null; var userInteraction = new UserInteraction(); var index = Formats.IndexOf(value.GetString()); if (index != -1) userInteraction.InteractionType = (UserInteractionType)index; if (!jsonObject.TryGetValue("properties", out value)) return null; var properties = value.GetObject(); if (properties == null) return null; if (properties.TryGetValue("description", out value)) userInteraction.Description = value.GetString(); if (properties.TryGetValue("commentText", out value)) userInteraction.CommentText = value.GetString(); if (properties.TryGetValue("commentTime", out value)) userInteraction.CommentTime = DateTimeHelper.FromString(value.GetString()); if (properties.TryGetValue("replyToUrl", out value)) userInteraction.ReplyToUrl = value.GetString(); if (properties.TryGetValue("creator", out value)) userInteraction.Creator = SchemaFactory.Parse(value.GetObject()) as IPerson; return userInteraction; }
public void UserInteractionConvertTest() { var data = DateTimeOffset.UtcNow; var userInteraction = new UserInteraction { CommentText = "Comment", CommentTime = data, InteractionType = UserInteractionType.Comments, Description = "Description", ReplyToUrl = "http://url" }; var json = userInteraction.ToJson(); var testObject = UserInteraction.FromJson(json); Assert.AreEqual("Comment", testObject.CommentText); Assert.AreEqual("http://url", testObject.ReplyToUrl); Assert.AreEqual("Description", testObject.Description); Assert.AreEqual(UserInteractionType.Comments, testObject.InteractionType); Assert.AreEqual(data, testObject.CommentTime); }