Exemple #1
0
        public async void AlterarUsuario(Guid id, string nome)
        {
            var command = new AlterarUsuarioCommand(id, nome);
            var handler = new AlterarUsuarioHandler(_query, _repository, _uow);

            _query.FindById(id).Returns(new Usuario(id, nome));
            var result = await handler.Handle(command, CancellationToken.None);

            var model = result.GetModel <UsuarioResult>();

            Assert.True(result.IsValid);
            Assert.Equal(id, model.Id);
            Assert.Equal(nome, model.Nome);
        }
Exemple #2
0
        public async Task <CommandResult> Handle(AlterarUsuarioCommand request, CancellationToken cancellationToken)
        {
            var usuario = await _query.FindById(request.Id);

            if (usuario == null)
            {
                return(CommandResultFactory.NotFoundResult <Usuario>());
            }
            if (await _query.Any(u => u.Id != request.Id && u.Nome == request.Nome))
            {
                return(CommandResultFactory.DuplicatedResult <Usuario>());
            }

            usuario.Alterar(request);
            await _repository.UpdateAsync(usuario);

            await _uow.CommitAsync();

            var result = (UsuarioResult)usuario;

            return(CommandResultFactory.UpdateSucessResult <Usuario>(result));
        }
 public async Task <Usuario> Listar(Guid id)
 {
     return(await _query.FindById(id));
 }