public void AddPostByService()
        {
            var post = new PostDto()
            {
                Title        = "Title",
                Author       = "Author",
                CreationDate = DateTime.Now
            };

            _manager.AddPost(post);

            _mockPosts.Verify(m => m.Add(It.IsAny <Post>()), Times.Once);
            _mockUnitOfWork.Verify(m => m.Save(), Times.Once);
        }
示例#2
0
        public IHttpActionResult Post([FromBody] PostDto post)
        {
            try
            {
                _appService.AddPost(post);
            }
            catch (DataAccessException ex)
            {
                return(InternalServerError(ex));
            }
            catch (ValidationException ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok());
        }