Esempio n. 1
0
        public void AddAuthorComment_BadArgument_Exception()
        {
            var authorCommentCreateModel = new AuthorCommentCreateModel
            {
                AuthorId = "",
                Comment  = ""
            };

            using var commentService = new CommentService(_mockCommentRepository.Object, _mapper);
            Assert.ThrowsAsync <CustomException>(() => commentService.AddAuthorComment(authorCommentCreateModel, It.IsAny <string>()));
        }
        public async Task AddAuthorComment(AuthorCommentCreateModel authorCommentCreateModel, string userId)
        {
            if (authorCommentCreateModel == null ||
                authorCommentCreateModel.AuthorId.IsNullOrEmpty() ||
                authorCommentCreateModel.Comment.IsNullOrEmpty())
            {
                throw new CustomException("Некоректные данные");
            }
            var model = _mapper.Map <AuthorComment>(authorCommentCreateModel);

            model.UserId = userId;
            await _commentRepository.AddAuthorComment(model);
        }
Esempio n. 3
0
        public void AddAuthorComment_GoodArgument_Success()
        {
            var authorCommentCreateModel = new AuthorCommentCreateModel
            {
                AuthorId = "SomeAuthorId",
                Comment  = "SomeAuthorComment"
            };

            using var commentService = new CommentService(_mockCommentRepository.Object, _mapper);
            var addAuthorComment = commentService.AddAuthorComment(authorCommentCreateModel, It.IsAny <string>());

            _mockCommentRepository.Verify(w => w.AddAuthorComment(It.IsAny <AuthorComment>()), Times.Once);
        }
        public async Task <ActionResult> AddByAuthor([FromBody] AuthorCommentCreateModel model)
        {
            string userId = "anyId";

            if (Request.Cookies.ContainsKey("id"))
            {
                userId = Request.Cookies["id"];
            }

            try
            {
                using var service = _commentService;
                await service.AddAuthorComment(model, userId);

                return(Ok());
            }
            catch (Exception)
            {
                return(BadRequest("Error"));
            }
        }