示例#1
0
        public async Task <IHttpActionResult> Put(int id, [FromBody] CommentDto comment)
        {
            try
            {
                await _appService.UpdateCommentAsync(comment);
            }
            catch (DataAccessException ex)
            {
                return(InternalServerError(ex));
            }
            catch (ValidationException ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Content(HttpStatusCode.Accepted, comment));
        }
        public async Task UpdateCommentAsyncByManager()
        {
            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());

            await _manager.UpdateCommentAsync(comment);

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