public async Task CalculateInterest(decimal amount, int months, decimal expectedResult)
        {
            _mock.Setup(s => s.GetInterestRateAsync()).ReturnsAsync(new decimal(0.01));

            var financial    = new Financial(amount, months);
            var actualResult = await financial.CalculateInterest(_mock.Object);

            actualResult.Should().Be(expectedResult).And.BeOfType(typeof(decimal));
        }
Ejemplo n.º 2
0
        public async Task <FinancialContract> Handle(CalculateInterestCommand request,
                                                     CancellationToken cancellationToken)
        {
            try
            {
                _logging.Information(new { details = "calculate interest", entity = request });

                var financial      = new Financial(request.Amount, request.Months);
                var interestResult = await financial.CalculateInterest(_interestRateQueryApi);

                var currencyType = request.CurrencyDisplay ?? CurrencyDisplay.PtBr;

                return(new FinancialContract
                {
                    Id = financial.Id,
                    Amount = financial.Amount,
                    Months = financial.Months,
                    SimpleInterest = interestResult,
                    ValuesInCurrency = new DisplayValuesContract
                    {
                        Type = currencyType.ToString(),
                        AmountCurrency =
                            financial.Amount.FormatToCurrency(currencyType),
                        SimpleInterestCurrency = interestResult.FormatToCurrency(currencyType)
                    }
                });
            }
            catch (Exception e)
            {
                _logging.Error(new
                {
                    details   = "calculate interest",
                    entity    = request,
                    exception = new { inner = e.InnerException, message = e.Message }
                });

                throw;
            }
        }