コード例 #1
0
        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>()));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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"));
            }
        }