public bool Transferir(TransferenciaBancariaDTO dadosTransferencia) { try { Transacao.ExecutarEmTransacao(() => { Lancamentos lancamento = new Lancamentos(dadosTransferencia.ContaOrigem, dadosTransferencia.contaDestino, dadosTransferencia.Valor); ContaCorrente origem = _contaRepositorio.Buscar(dadosTransferencia.ContaOrigem); ContaCorrente destino = _contaRepositorio.Buscar(dadosTransferencia.contaDestino); if (origem == null || destino == null) { throw new ArgumentNullException(ValidationResource.ContaNaoExistente); } origem.Debitar(dadosTransferencia.Valor); origem.Lancamentos.Add(lancamento); destino.Creditar(dadosTransferencia.Valor); _contaRepositorio.Salvar(origem); _contaRepositorio.Salvar(destino); }); return(true); } catch (Exception e) { throw e; } }
public LancamentoRepositorioMoq(TransferenciaBancariaDTO dadosTransferencia) { //TransferenciaBancariaDTO dadosTransferencia = new TransferenciaBancariaDTO() //{ // ContaOrigem = 000001, // ContaDestino = 000002, // Valor = 100 //}; this.lancamento = new Lancamento(dadosTransferencia); this.Mock.Setup(m => m.Adicionar(It.IsAny <Lancamento>())); }
public HttpResponseMessage Post([FromBody] TransferenciaBancariaDTO dadosTransferencia) { try { return(new HttpResponseMessage(HttpStatusCode.OK)); //var sucesso = _operacaoServico.Transferir(dadosTransferencia); //if (sucesso) // return new HttpResponseMessage(HttpStatusCode.OK); //else // return new HttpResponseMessage(HttpStatusCode.BadRequest); } catch (Exception) { return(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } }
public void ValidaContaOrigemNaoExistente() { try { TransferenciaBancariaDTO DTO = new TransferenciaBancariaDTO() { contaDestino = 5, ContaOrigem = 100, Valor = 1000 }; var sucesso = this.servico.Transferir(DTO); Assert.False(sucesso); } catch (Exception) { Assert.True(true); } }
public Lancamento(TransferenciaBancariaDTO dadosTransferencia) { ContaOrigem = dadosTransferencia.ContaOrigem; ContaDestino = dadosTransferencia.ContaDestino; Valor = dadosTransferencia.Valor; }