Exemplo n.º 1
0
 public IActionResult GetCommentById(int id)
 {
     if (_commentRepository.GetById(id) != null)
     {
         var comment = _commentRepository.GetById(id);
         return(Ok(comment));
     }
     else
     {
         return(NotFound());
     }
 }
        public void CommentRepository_Update_UpdatesComment()
        {
            //arrange
            ICommentRepo cr = GetInMemoryCommentRepository();

            //act
            cr.Add(comment);
            var savedComment = cr.GetById(1); //should have Id of 1

            savedComment.Content = "Updated content";
            cr.Update(savedComment);
            var updatedComment = cr.GetById(1);

            //assert
            Assert.Equal("Updated content", updatedComment.Content);
        }
        public void CommentRepository_GetById_ThrowsExceptionWhenIdNotFound()
        {
            //arrange
            ICommentRepo cr = GetInMemoryCommentRepository();

            //act
            cr.Add(comment);
            //Id should be 1

            //assert
            Assert.ThrowsAny <ArgumentNullException>(() => cr.GetById(0));
        }
        public void CommentRepository_Add_AddsComment()
        {
            //arrange
            ICommentRepo cr = GetInMemoryCommentRepository();

            //act
            cr.Add(comment);
            var savedComment = cr.GetById(1); //should have Id of 1

            //assert
            Assert.Equal(1, savedComment.CommentId);
            Assert.Equal(1, savedComment.ReviewId);
            Assert.Equal(1, savedComment.UserId);
            Assert.IsType <DateTime>(savedComment.Date);
        }
Exemplo n.º 5
0
 public IActionResult GetById(int id)
 {
     return(Ok(_comment.GetById(id)));
 }