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; } }
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); }
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); }
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); }
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); }