Esempio n. 1
0
        public IHttpActionResult Post([FromBody] CommentDto comment)
        {
            try
            {
                _appService.AddComment(comment);
            }
            catch (DataAccessException ex)
            {
                return(InternalServerError(ex));
            }
            catch (ValidationException ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok());
        }
        public void AddCommentByService()
        {
            var comment = new CommentDto()
            {
                User         = "******",
                Text         = "Text",
                CreationDate = DateTime.Now,
                PostId       = 1
            };

            _mockPosts.Setup(m => m.Get(It.Is <int>(arg => arg == 1))).Returns(new Post());

            _manager.AddComment(comment);

            _mockValidator.Verify(m => m.GetCommentDtoValidationErrors(comment));
            _mockComments.Verify(m => m.Add(It.IsAny <Comment>()), Times.Once);
            _mockUnitOfWork.Verify(m => m.Save(), Times.Once);
        }