示例#1
0
        public List <CommentNReplies> GetList(int postId, string postType, string openId = "")
        {
            List <CommentNReplies> comments = new List <CommentNReplies>();

            try
            {
                var dao = new CommentsDao(mysqlConnection);
                comments.AddRange(dao.GetList(postId, postType));

                if (!string.IsNullOrEmpty(openId))
                {
                    comments.AddRange(dao.GetPendingList(postId, postType, openId)); //发表评论的人可以看到自己发表但未审核的评论
                }

                //读取作者对评论的回复
                comments.ForEach(comment =>
                {
                    comment.Replies = dao.GetAuthorReplies(comment.comment_id);
                });
            }
            catch (Exception ex)
            {
                logger.Error("获取评论失败", ex);
            }

            return(comments.OrderByDescending(comm => comm.createdAt).ToList());
        }
示例#2
0
        public void GetList_GettingData_ReturnList()
        {
            var data     = CreateCommentData();
            var storMock = new Mock <IStorage>();

            storMock.Setup(x => x.GetComments(It.IsNotNull <int?>())).Returns(data);

            var sut    = new CommentsDao(storMock.Object);
            var result = sut.GetList(1, null, 0, 0, 0).ToList();

            Assert.AreEqual(data.Count, result.Count);
            Assert.AreSame(data[0], result[0]);

            result = sut.GetList(1, "Id", 1, 0, 1).ToList();
            Assert.AreEqual(data.Count, result.Count);
            Assert.AreSame(data[data.Count - 1], result[0]);
        }