Exemple #1
0
        public IActionResult UpdatePost(int userId, int blogId, int postId,
                                        [FromBody] PostForManipulationDto post)
        {
            if (!_weblogDataRepository.UserExists(userId) ||
                !_weblogDataRepository.BlogExists(blogId))
            {
                return(NotFound());
            }

            var emailAddress = post.Credentials.EmailAddress;
            var password     = post.Credentials.Password;

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

            var postFromRepo = _weblogDataRepository.GetPost(postId);

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

            _mapper.Map(post, postFromRepo);

            _weblogDataRepository.UpdatePost(postFromRepo);
            _weblogDataRepository.Save();

            return(NoContent());
        }
Exemple #2
0
        public void UpdatePost()
        {
            //-- arrange
            var post = new Post
            {
                Title       = "old-title",
                Body        = "old-body",
                TimeCreated = DateTime.Now
            };

            _repository.AddPost(1, post);
            _repository.Save();

            post.Title = "new-title";
            post.Body  = "new-body";

            //-- act
            _repository.UpdatePost(post);
            _repository.Save();

            var actual = _repository.GetPost(1);

            //-- assert
            Assert.AreEqual("new-title", actual.Title);
            Assert.AreEqual("new-body", actual.Body);

            //-- cleanup
            _repository.DeletePost(post);
            _repository.Save();
        }