Пример #1
0
        public IActionResult DeletePost(int userId, int blogId, int postId,
                                        [FromBody] UserCredentialsDto credentials)
        {
            if (!_weblogDataRepository.UserExists(userId) ||
                !_weblogDataRepository.BlogExists(blogId))
            {
                return(NotFound());
            }

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

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

            var postFromRepo = _weblogDataRepository.GetPost(postId);

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

            _weblogDataRepository.DeletePost(postFromRepo);
            _weblogDataRepository.Save();

            return(NoContent());
        }
Пример #2
0
        public void AddPost()
        {
            //-- arrange
            var countBeforeAdd = _repository.GetPosts(1, _resourceParameters).Count();

            var post = new Post
            {
                Title       = "title",
                Body        = "body",
                TimeCreated = DateTime.Now
            };

            //-- act
            _repository.AddPost(1, post);
            _repository.Save();

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

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

            //-- clean up
            _repository.DeletePost(post);
            _repository.Save();
        }