Exemplo n.º 1
0
        public async Task CalculatePaymentsWhenInterestIsZero()
        {
            var loan = new Loan(5, 0, 500, new Guid());

            var result = await _loanService.CalculatePayments(loan);

            result.Should().HaveValue();
            result.Should().HaveNumberOfPayments(loan.NumberOfInstallments);
            result.Should().HaveAllPaymentsWithAmount(100);
        }
Exemplo n.º 2
0
        public async Task <BaseResponse <CreateLoanDto> > Handle(CreateLoanCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var loan   = new Loan(request.NumberOfInstallments, request.Interest, request.Amount, request.PersonId);
                var loanId = await _loanRepository.CreateLoanAsync(loan);

                var loanWithPayments = await _loanService.CalculatePayments(loan);

                var paymentDtos = _mapper.Map <IEnumerable <PaymentDto> >(loanWithPayments.Payments);

                var loanCost = _loanService.CalculateLoanCost(loan);

                return(new BaseResponse <CreateLoanDto>(new CreateLoanDto()
                {
                    Id = loanId,
                    Payments = paymentDtos,
                    TotalCost = loanCost
                }));
            }
            catch (Exception e)
            {
                // there should be logging
                return(new BaseResponse <CreateLoanDto>("An error occurred when handling request."));
            }
        }