static void ShouldBeEqual(Comment source, Comment restored)
 {
     Assert.AreEqual(source.Id, restored.Id, "Id");
     Assert.AreEqual(source.Text ?? "", restored.Text, "Text");
     Assert.AreEqual(source.CreationDate, restored.CreationDate, "CreationDate");
     Assert.AreEqual(source.PostId, restored.PostId, "PostId");
     Assert.AreEqual(source.Score, restored.Score, "Score");
     Assert.AreEqual(source.UserId, restored.UserId, "UserId");
 }
        public void given_empty_comment()
        {
            var source = new Comment();

            var bin = source.ToBinary();
            var restored = Comment.TryGetFromBinary(bin);

            ShouldBeEqual(source, restored);
        }
        public void given_populated_comment()
        {
            var source = new Comment()
                {
                    Id = 100,
                    Text = "Comment for test",
                    CreationDate = new DateTime(2011, 12, 1, 13, 13, 13),
                    PostId = 12,
                    Score = 2,
                    UserId = 11
                };

            var bin = source.ToBinary();
            var restored = Comment.TryGetFromBinary(bin);

            ShouldBeEqual(source, restored);
        }
Exemplo n.º 4
0
        private static Comment ParseComments(string line)
        {
            try
            {
                long defaultLong;
                int defaultInt;
                DateTime defaultDate;

                var comment = new Comment
                    {
                        Id = long.TryParse(Get(line, "Id"), out defaultLong) ? defaultLong : -1,
                        PostId = long.TryParse(Get(line, "PostId"), out defaultLong) ? defaultLong : -1,
                        CreationDate =
                            DateTime.TryParse(Get(line, "CreationDate"), out defaultDate)
                                ? defaultDate
                                : DateTime.MinValue,
                        Text = HttpUtility.HtmlDecode(Get(line, "Text")),
                        UserId = long.TryParse(Get(line, "UserId"), out defaultLong) ? defaultLong : -1,
                        Score = int.TryParse(Get(line, "Score"), out defaultInt) ? defaultInt : -1,
                    };

                return comment;
            }
            catch (Exception)
            {
                return null;
            }
        }