예제 #1
0
        public ActionResult <Comment> Get(Guid id)
        {
            var resultValidation = new CommentExistValidator().Validate(id);

            if (!resultValidation.IsValid)
            {
                return(BadRequest(resultValidation.Errors));
            }

            return(Ok(commentRepository.GetById(id)));
        }
예제 #2
0
        public void TestValidationCommentExist()
        {
            var okComment = CommentBuilder.New().Build();

            new CreateComment().CreateNewRegister(okComment);

            var badComment = CommentBuilder.New().WithContent("SomeRandomContent").Build();

            var resultValidation1 = new CommentExistValidator().Validate(okComment.Id);
            var resultValidation2 = new CommentExistValidator().Validate(badComment.Id);

            Assert.True(resultValidation1.IsValid);
            Assert.False(resultValidation2.IsValid);
        }
예제 #3
0
        public ActionResult <Comment> Put(Guid id, string content)
        {
            var resultValidation = new CommentExistValidator().Validate(id);

            if (!resultValidation.IsValid)
            {
                return(BadRequest(resultValidation.Errors));
            }

            Comment oldComment = commentRepository.GetById(id);
            Comment newComment = new Comment(id, oldComment.Autor, content, oldComment.PublicationId);

            resultValidation = new CommentValidator().Validate(newComment);

            if (!resultValidation.IsValid)
            {
                return(BadRequest(resultValidation.Errors));
            }

            return(Ok(commentRepository.Update(newComment)));
        }