コード例 #1
0
        public override async Task <ComentarPostagemCommandResult> Handle(ComentarPostagemCommand request, CancellationToken cancellationToken)
        {
            Postagem postagem = await ObterPostagemCriticandoSeNaoExitirNoRepositorio(request.Id);

            Comentario comentario = new Comentario(_user.CurrentRequestUserId, postagem.Id, request.Comentario);

            postagem.Comentar(comentario);

            return(await Task.FromResult(new ComentarPostagemCommandResult(comentario.Id, postagem.Id, _user.CurrentRequestUserId)));
        }
コード例 #2
0
        public void RemoverComentario_ComentarioExistente_DeveRemoverComSucesso()
        {
            //Arrange
            Postagem postagem    = CriarPostagemValida();
            string   comentario1 = _faker.Lorem.Word();
            string   comentario2 = _faker.Lorem.Word();
            Guid     usuarioId   = Guid.NewGuid();

            postagem.Comentar(new Comentario(usuarioId, postagem.Id, comentario1));
            postagem.Comentar(new Comentario(usuarioId, postagem.Id, comentario2));

            Comentario comentario = postagem.Comentarios.FirstOrDefault();

            //Act
            postagem.RemoverComentario(comentario.Id, usuarioId);

            //Assert
            postagem.TotalDeComentarios().Should().Be(1);
            postagem.Comentarios.Should().NotContain(c => c.Id == comentario.Id);
        }
コード例 #3
0
        public void Comentar_ComentarioValido_ComentarioAdicionadoComSucesso()
        {
            //Arrange
            Postagem postagem    = CriarPostagemValida();
            string   comentario  = _faker.Lorem.Word();
            string   comentario2 = _faker.Lorem.Word();
            Guid     usuarioId   = Guid.NewGuid();

            //Act
            postagem.Comentar(new Comentario(usuarioId, postagem.Id, comentario));
            postagem.Comentar(new Comentario(usuarioId, postagem.Id, comentario2));

            //Assert
            postagem.TotalDeComentarios().Should().Be(2);

            postagem.Comentarios.ToList()[0].Corpo.Conteudo.Should().Be(comentario);
            postagem.Comentarios.ToList()[0].SubComentarios.Should().HaveCount(0);

            postagem.Comentarios.ToList()[1].Corpo.Conteudo.Should().Be(comentario2);
            postagem.Comentarios.ToList()[1].SubComentarios.Should().HaveCount(0);
        }
コード例 #4
0
        public void Comentar_ComentarioDoProprioAutor_DeveJogarDomainInvalidOperationException()
        {
            //Arrange
            Postagem postagem   = CriarPostagemValida();
            string   comentario = _faker.Lorem.Word();
            Guid     usuarioId  = postagem.UsuarioId;

            //Act
            Action comentar = () => postagem.Comentar(new Comentario(usuarioId, postagem.Id, comentario));

            //Assert
            comentar.Should().ThrowExactly <DomainInvalidOperationException>()
            .And.ErrorCode.Should().Be(DomainErrorCodes.INVALID_OPERATION_ERROR_CODE);
        }