Ejemplo n.º 1
0
        public virtual void Create(CreateUpdateCommentInput item)
        {
            try
            {
                var validationResults = _createUpdateCommentValidator.Validate(item, ruleSet: "Create");

                if (!validationResults.IsValid)
                {
                    throw new ValidationException(validationResults.Errors);
                }

                _unitOfWork.GetComments().Create(Mapper.Map <Comment>(item));
                _unitOfWork.Save();
            }
            catch (ValidationException exception)
            {
                _logger.Warn(exception.Message);
                throw;
            }
            catch (Exception exception)
            {
                _logger.Trace(exception.StackTrace);
                throw;
            }
        }
Ejemplo n.º 2
0
        public void Create_Comment_With_Wrong_Id()
        {
            // Arrange
            var testComment = new CreateUpdateCommentInput
            {
                Id   = 245,
                Name = comments[1].Name,
                Body = comments[1].Body
            };

            // Act
            _commentService.Create(testComment);
        }
Ejemplo n.º 3
0
        public void Update_Comment_With_Wrong_Id()
        {
            // Arrange
            var testPublisher = new CreateUpdateCommentInput
            {
                Id   = 245,
                Body = comments[1].Body,
                Name = comments[1].Name,
                Date = comments[1].Date
            };

            // Act
            _commentService.Update(testPublisher);
        }
Ejemplo n.º 4
0
        public void Create_Comment_With_Right_Data()
        {
            // Arrange
            var testComment = new CreateUpdateCommentInput
            {
                Id   = 17,
                Name = "This is test name",
                Body = "This is test body for comment"
            };

            // Act
            _commentService.Create(testComment);

            // Assert
            _commentRepositoryMock.Verify(_ => _.Create(It.IsAny <Comment>()), Times.Once);
        }
Ejemplo n.º 5
0
        public void Update_Comment_With_Right_Data()
        {
            // Arrange
            var testComment = new CreateUpdateCommentInput
            {
                Id   = comments[1].Id,
                Body = comments[1].Body,
                Name = "NewName",
                Date = comments[1].Date
            };

            // Act
            _commentService.Update(testComment);

            // Assert
            _commentRepositoryMock.Verify(_ => _.Update(It.IsAny <Comment>()), Times.Once);
        }