Exemple #1
0
        public void AddComment()
        {
            //-- arrange
            var countBeforeAdd = _repository.GetComments(1, _resourceParameters).Count();

            var comment = new Comment
            {
                UserId      = 1,
                Body        = "body",
                TimeCreated = DateTime.Now
            };

            //-- act
            _repository.AddComment(1, comment);
            _repository.Save();

            var actual = _repository.GetComments(1, _resourceParameters).Count();

            //-- assert
            Assert.AreEqual(countBeforeAdd + 1, actual);

            //-- clean up
            _repository.DeleteComment(comment);
            _repository.Save();
        }
Exemple #2
0
        public IActionResult DeleteComment(int userId, int blogId, int postId, int commentId,
                                           [FromBody] UserCredentialsDto credentials)
        {
            if (!_weblogDataRepository.UserExists(userId) ||
                !_weblogDataRepository.BlogExists(blogId) ||
                !_weblogDataRepository.PostExists(postId))
            {
                return(NotFound());
            }

            var commentFromRepo = _weblogDataRepository.GetComment(commentId);

            if (commentFromRepo is null)
            {
                return(NotFound());
            }

            var emailAddress = credentials.EmailAddress;
            var password     = credentials.Password;

            if (!_weblogDataRepository.Authorized(commentFromRepo.UserId, emailAddress, password))
            {
                return(Unauthorized());
            }

            _weblogDataRepository.DeleteComment(commentFromRepo);
            _weblogDataRepository.Save();

            return(NoContent());
        }