public void TestCalcularJurosComposto() { var valorEsperado = 105.10M; var calcularJuros = new CalcularJuros(100, 5); var retorno = _calculaJurosService.CalculaJuros(calcularJuros); Assert.Equal(valorEsperado, retorno); }
public IActionResult Get(double valorInicial, int meses) { try { var calculaJuros = new CalcularJuros(valorInicial, meses); decimal valorFinal = _calculaJurosService.CalculaJuros(calculaJuros); return(Ok(valorFinal.ToString("N2"))); } catch (Exception ex) { return(BadRequest($"Erro: {ex.Message}")); } }
public async Task <IActionResult> CalculaJuros([FromQuery] CalculaJurosDTO calculaJurosDTO) { try { var valor = await _calculaJurosService.CalculaJuros(calculaJurosDTO); return(Ok(valor)); } catch (ValidationException ex) { _logger.LogError(ex, "ValidationException"); return(BadRequest(_validationErrorService.FormatError(ex))); } catch (Exception ex) { _logger.LogError(ex, "Exception"); return(Problem(ex.Message)); } }
public async void CalculaJuros__ShouldReturnValidationException_WhenMounthsIsNull() { //Arrange var parms = new CalculaJurosDTO { Meses = null, ValorInicial = 100 }; //Act and Assert var result = await Assert.ThrowsAsync <ValidationException>(async() => await _sut.CalculaJuros(parms)); var details = result.Errors .Select(s => new Detail() { Code = s.ErrorCode, Message = $"{s.PropertyName} {s.ErrorMessage}", }); var total = details.Count(); Assert.Equal(1, total); Assert.Equal("NULL_MOUNTH", details.First().Code); }
public async Task <string> CalculaJuros(decimal valorInicial, int tempo) => await _calculaJurosService.CalculaJuros(valorInicial, tempo);