Ejemplo n.º 1
0
        public IActionResult DeleteBlog(int userId, int blogId,
                                        [FromBody] UserCredentialsDto credentials)
        {
            if (!_weblogDataRepository.UserExists(userId))
            {
                return(NotFound());
            }

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

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

            var blogFromRepo = _weblogDataRepository.GetBlog(blogId);

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

            _weblogDataRepository.DeleteBlog(blogFromRepo);
            _weblogDataRepository.Save();

            return(NoContent());
        }
Ejemplo n.º 2
0
        public void AddBlog()
        {
            //-- arrange
            var countBeforeAdd = _repository.GetBlogs(_resourceParameters).Count();

            var blog = new Blog
            {
                Title   = "title",
                Excerpt = "excerpt"
            };

            //-- act
            _repository.AddBlog(1, blog);
            _repository.Save();

            var actual = _repository.GetBlogs(_resourceParameters).Count();

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

            //-- clean up
            _repository.DeleteBlog(blog);
            _repository.Save();
        }