コード例 #1
0
        public void Test_AddCommentToGame_Body_Is_Null()
        {
            //arrange
            CommentService servise = new CommentService(_unitOfWork.Object);
            CommentDTO comment = new CommentDTO() { ParentCommentId = 2, Body = null, Name = "Autor2" };
            GameDTO game = new GameDTO() { Key = "me3" };

            //act
            servise.AddCommentToGame(comment, game);
        }
コード例 #2
0
 public void AddCommentToGame(CommentDTO comment, GameDTO game)
 {
     if (comment == null || game == null ||comment.Name == null || comment.Body == null || game.Key == null)
         throw new ArgumentNullException();
     IGameRepository games = _unitOfWork.Games as IGameRepository;
     IGenericRepository<Comment> comments = _unitOfWork.Comments;
     Comment fullComment = Mapper.Map<CommentDTO, Comment>(comment);
     fullComment.ParentComment = comment.ParentCommentId != 0 ? comments.GetById(comment.ParentCommentId) : null;
     fullComment.Game = games.GetGameByKey(game.Key);
     comments.Insert(fullComment);
     if (fullComment.ParentComment != null)
     {
         Comment parentComment = fullComment.ParentComment;
         parentComment.ChildComments.Add(fullComment);
         comments.Update(parentComment);
     }
     _unitOfWork.SaveChanges();
 }
コード例 #3
0
        public void Test_AddCommentToGame_With_ParrentId()
        {
            //arrange
            CommentService servise = new CommentService(_unitOfWork.Object);
            CommentDTO comment = new CommentDTO() { ParentCommentId = 2, Body = "Text4", Name = "Autor2" };
            GameDTO game = new GameDTO() { Key = "me3" };

            //act
            servise.AddCommentToGame(comment, game);

            //assert
            _comments.Verify(c => c.Insert(It.IsAny<Comment>()), Times.Once());
        }