Esempio n. 1
0
        public void AddCommentTest()
        {
            var comment = new CommentDto()
            {
                ArticleId   = 123,
                CommentText = "qwerty",
                UserName    = "******"
            };

            Mock.Get(articleRepository).Setup(x => x.Get(123)).Returns(new Article()
            {
                Id = 123, Comments = new List <Comment>()
            });

            blog.AddComment(comment);

            Mock.Get(articleRepository).Verify(repo => repo.Get(123), Times.Once);
            Mock.Get(articleRepository).Verify(repo => repo.Update(It.IsAny <Article>()), Times.Once);

            uowMock.Verify(x => x.Commit(), Times.Once);
        }
Esempio n. 2
0
        public async Task <IActionResult> Comment(string blogPostID, string comment)
        {
            BlogPost post = await blog.GetPostById(blogPostID);

            if (post == null)
            {
                return(RedirectToAction("Index"));
            }

            try
            {
                await blog.AddComment(blogPostID, comment);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return(RedirectToAction("Detail", new {
                id = blogPostID,
                name = post.Title
            }));
        }
Esempio n. 3
0
 /// <summary>
 /// Adds comment.
 /// </summary>
 /// <param name="comment">Comment object</param>
 public void AddComment(CommentDto comment)
 {
     blog.AddComment(comment);
 }