public void AddBookComment_BadArgument_Exception() { var bookCommentCreateModel = new BookCommentCreateModel { BookId = "", Comment = "" }; using var commentService = new CommentService(_mockCommentRepository.Object, _mapper); Assert.ThrowsAsync <CustomException>(() => commentService.AddBookComment(bookCommentCreateModel, It.IsAny <string>())); }
public async Task AddBookComment(BookCommentCreateModel bookCommentCreateModel, string userId) { if (bookCommentCreateModel == null || bookCommentCreateModel.BookId.IsNullOrEmpty() || bookCommentCreateModel.Comment.IsNullOrEmpty()) { throw new CustomException("Некоректные данные"); } var model = _mapper.Map <BookComment>(bookCommentCreateModel); model.UserId = userId; await _commentRepository.AddBookComment(model); }
public void AddBookComment_GoodArgument_Success() { var bookCommentCreateModel = new BookCommentCreateModel { BookId = "SomeBookId", Comment = "SomeBookComment" }; using var commentService = new CommentService(_mockCommentRepository.Object, _mapper); var addBookComment = commentService.AddBookComment(bookCommentCreateModel, It.IsAny <string>()); _mockCommentRepository.Verify(w => w.AddBookComment(It.IsAny <BookComment>()), Times.Once); }
public async Task <ActionResult> AddByBook([FromBody] BookCommentCreateModel model) { string userId = "anyId"; if (Request.Cookies.ContainsKey("id")) { userId = Request.Cookies["id"]; } try { using var service = _commentService; await service.AddBookComment(model, userId); return(Ok()); } catch (Exception) { return(BadRequest("Error")); } }