public ActionResult AddComment(string addComment, Guid itemId) { var comment = new CommentDtoModel() { ItemId = itemId, Description = addComment, UserId = new Guid(User.Identity.GetUserId()) }; this.commentService.AddCommnet(comment); return(this.PartialView("_CommentsPartial", this.commentService.GetAll(itemId))); }
public void CallMapperServiceOnce() { //Arrange var mockeGenericRepository = new Mock <IGenericEfRepository <Comment> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedMapper = new Mock <IMapingService>(); var commentStub = new CommentDtoModel(); mockedMapper.Setup(x => x.Map <Comment>(It.IsAny <CommentDtoModel>())).Verifiable(); var sut = new CommentService(mockeGenericRepository.Object, mockedUnitOfWork.Object, mockedMapper.Object); //Act sut.AddCommnet(commentStub); //Assert mockedMapper.Verify(x => x.Map <Comment>(It.IsAny <CommentDtoModel>()), Times.Once); }
public void PassSameCommentWithDateToMapper() { //Arrange var mockeGenericRepository = new Mock <IGenericEfRepository <Comment> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedMapper = new Mock <IMapingService>(); var commentStub = new CommentDtoModel(); mockedMapper.Setup(x => x.Map <Comment>(commentStub)).Verifiable(); var sut = new CommentService(mockeGenericRepository.Object, mockedUnitOfWork.Object, mockedMapper.Object); //Act commentStub.Date = DateTime.Now; sut.AddCommnet(commentStub); //Assert mockedMapper.Verify(x => x.Map <Comment>(It.Is <CommentDtoModel>(y => y == commentStub)), Times.Once); }
public void AddCommnet(CommentDtoModel comment) { comment.Date = DateTime.Now; base.Add(mapper.Map <Comment>(comment)); }