public async Task ShouldReturnOneCustomer() { var command = new GetCustomerByIdQuery(1); var handler = new GetCustomerByIdQueryHandler(_mapper, _customerReadOnlyRepository); var result = await handler.Handle(command, CancellationToken.None); var customer = await _customerReadOnlyRepository.GetById(1); Assert.IsTrue(result != null); Assert.IsTrue(customer.Email == result.Email); }
public void Execute(CustomerGetRequest request) { try { var customer = customerReadOnlyRepository.GetById(request.CustomerId); if (customer == null) { output.NotFound($"Not found customer with id: {request.CustomerId}"); return; } output.Standard(customer); } catch (Exception ex) { output.Error($"Error on process: {ex.Message}"); } }
public async Task <ICommandResult> Handle(DeleteCustomerCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { return(CommandResult(success: false, message: "Id inválido", data: null)); } Customer customer = await _customerReadOnlyRepository.GetById(request.Id); if (customer == null) { return(CommandResult(success: false, message: "Usuário não encontrado", data: null)); } await _customerRepository.Delete(customer); await Commit(); return(CommandResult(success: true, message: "Usuário deletado", data: null)); }
public async Task <CustomerViewModel> Handle(GetCustomerByIdQuery request, CancellationToken cancellationToken) { return(_mapper.Map <CustomerViewModel>(await _customerReadOnlyRepository.GetById(request.Id))); }
public async Task <CommandResult> Handle(UpdateCustomerCommand request, CancellationToken cancellationToken) { if (request.IsValid()) { Customer existingCustomer = await _customerReadOnlyRepository.GetByEmail(request.Email); if (existingCustomer != null && existingCustomer.Id != request.Id) { return(CommandResult(success: false, message: "E-mail já cadastrado", data: null)); } Customer customerToUpdate = new Customer(request.Id, request.FirstName, request.LastName, request.Email, request.Address, request.Age); await _customerRepository.Update(customerToUpdate); await Commit(); return(CommandResult(success: true, message: "Usuário atualizado com sucesso", data: _mapper.Map <CustomerViewModel>(await _customerReadOnlyRepository.GetById(request.Id)))); } else { return(CommandResult(success: false, message: "Erro ao atualizar usuário", data: request.ValidationResult.Errors)); } }
public void ShouldGetById() { var model = customerReadOnlyRepository.GetById(idCustomer); model.Should().NotBeNull(); }