public async Task <ActionResult <double> > CalculaJuros([FromQuery] CalculaJurosDto parameters) { try { CalculaJurosCommand command = new CalculaJurosCommand() { ValorInicial = parameters.ValorInicial, Meses = parameters.Meses, CasasDecimais = _defaultSettings.Value.DecimalPlaces, TaxaJuros = _defaultSettings.Value.Interest }; // Utilização do MediatR como preparação para separação do command em microserviço. double commandResult = await _mediator.Send(command); // Retorno 200 return(Ok(commandResult)); } catch (ValidationException ex) { // Retorno do status 400 - Bad Request return(BadRequest(new { ex.Message, ex.HelpLink })); } catch (Exception ex) { // Retorno do status 500 - Internal Server Error return(StatusCode((int)HttpStatusCode.InternalServerError, new { ex.Message, ex.HelpLink })); } }
public void Quando_calcula_juros() { var command = new CalculaJurosCommand(_valor, _juros, _meses); Assert.Equal(_valor, command.Valor); Assert.Equal(_juros, command.Juros); Assert.Equal(_meses, command.Meses); }
public async Task CalculaJurosCommandTest() { var command = new CalculaJurosCommand(100.0m, 5); var result = await SendAsync(command); result.Should().Be(105.10m); }
public async Task Calculo_Juros_Meses_Negativo() { var command = new CalculaJurosCommand() { CasasDecimais = 2, Meses = -9, ValorInicial = 100, TaxaJuros = 0.01 }; await ExecuteCommand(command); }
public async Task Calculo_Juros_ValorInicial_Zero() { var command = new CalculaJurosCommand() { CasasDecimais = 2, Meses = 9, ValorInicial = 0, TaxaJuros = 0.01 }; double result = await ExecuteCommand(command); Assert.AreEqual(result, 0); }
public async Task Calculo_Juros_2Casas_Trunca_Mais_Metade() { var command = new CalculaJurosCommand() { CasasDecimais = 2, Meses = 9, ValorInicial = 100, TaxaJuros = 0.01 }; double result = await ExecuteCommand(command); Assert.AreEqual(result, 109.36); }
public async Task CalculaJuros_DeveReornar_StatusCode_200() { // Arrange var command = new CalculaJurosCommand() { Tempo = 5, ValorInicial = 100 }; // Act var postResponse = await _testsFixture.Client.PostAsJsonAsync("api/CalculaJuros", command); // Assert postResponse.EnsureSuccessStatusCode(); }
public async Task <decimal> Get(decimal valor, int meses) { double taxa = 0; using (var client = new HttpClient()) { var response = await client.GetAsync(ApiRoutes.TaxaJuros.GetDocker); if (response.IsSuccessStatusCode) { taxa = Double.Parse(await response.Content.ReadAsStringAsync()); } } var command = new CalculaJurosCommand(valor, taxa, meses); var result = await _mediator.Send(command); return(result); }
public async Task ObterTaxaJuros_DeveReornar_Taxa() { // Arrange var command = new CalculaJurosCommand() { Tempo = 5, ValorInicial = 100 }; // Act var postResponse = await _testsFixture.Client.PostAsJsonAsync("api/CalculaJuros", command); // Assert var retorno = await postResponse.Content.ReadAsStringAsync(); decimal vlr = decimal.Parse(retorno.Replace(".", ",")); Assert.Equal((decimal)105.10, vlr); }
public CalculaJurosCommandHandlerTest() { _command = new CalculaJurosCommand(100, 0.01, 5); _handler = new CalculaJurosCommandHandler(); }
public async Task <decimal> Calcula(CalculaJurosCommand command) { decimal taxa = await this._taxaIntegration.ObterTaxa(); return(CalculadoraService.CalculaJuros(command.ValorInicial, taxa, command.Tempo)); }
private async Task <double> ExecuteCommand(CalculaJurosCommand command) { var handler = new CalculaJurosCommandHandler(); return(await handler.Handle(command, new CancellationToken())); }
public async Task <IActionResult> CalculaJuros([FromBody] CalculaJurosCommand command) { return(Ok(await this._calculaJurosApplication.Calcula(command))); }