Exemplo n.º 1
0
        public void AnswerOnComment_ValidMethodParameter_True()
        {
            //assing
            var  comment = new Fixture().Create <CreateAnswerCommentDto>();
            Game game    = new Game()
            {
                Id = comment.GameId
            };
            var commentEntity = new Fixture()
                                .Build <Comment>()
                                .With(p => p.Game, game)
                                .With(p => p.GameId, game.Id)
                                .Without(p => p.ParentComment)
                                .Without(p => p.ChildComments)
                                .Create <Comment>();


            commentRepositoryMoq.Setup((p) => p.GetSingleAsync(It.IsAny <Expression <Func <Comment, bool> > >()))
            .Returns(Task.FromResult(commentEntity));
            gameRepositoryMoq.Setup((p) => p.GetSingleAsync(It.IsAny <Expression <Func <Game, bool> > >()))
            .Returns(Task.FromResult(game));

            //act
            service.AnswerOnComment(comment);


            //assert
            unitofworkMoq.Verify(p => p.CommitAsync(), Times.Once);
            commentRepositoryMoq.Verify(p => p.Create(It.IsAny <Comment>()), Times.Once);
        }
        public async Task <IActionResult> CreateAnswerForAnotherComment(int id, [FromBody] CreateAnswerModel comment)
        {
            var commentDto = new CreateAnswerCommentDto()
            {
                ParentCommentId = id,
                Body            = comment.Body,
                GameId          = comment.GameId,
                Name            = comment.Name
            };

            await commnetService.AnswerOnComment(commentDto);

            return(StatusCode((int)HttpStatusCode.Created, "Comment was created"));
        }