public IActionResult CalculaJuros(decimal valorInicial, int tempo) { //return Ok(Juros.CalcularJuros(valorInicial, tempo, 0.01M)); try { using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:44371/api/api1/"); var responseTask = client.GetAsync("taxajuros"); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsStringAsync(); readTask.Wait(); var taxaJuros = JsonConvert.DeserializeObject <Decimal>(readTask.Result); return(Ok(Juros.CalcularJuros(valorInicial, tempo, taxaJuros))); } else { return(Problem()); } } } catch (Exception ex) { return(Problem()); } }
public ActionResult <Response <Juros> > GetTaxaJuros() { try { _loggingService.LogInfo($"Retornando taxa de juros valor { new { taxaJuros = _taxaJuros } }."); var conteudo = new Juros { Taxa = _taxaJuros }; var response = ResponseHelper.CreateResponse("Taxa de Juros recuperada com sucesso.", HttpStatusCode.OK, new List <Error>(), conteudo); return(Ok(response)); } catch (Exception ex) { _loggingService.LogError($"Exceção ocorreu. {ex.Message}", ex); var response = ResponseHelper.CreateResponse("Algo inesperado ocorreu. Por favor cheque a lista de erros.", HttpStatusCode.InternalServerError, new List <Error> { new Error { Mensagem = ex.Message } }); return(StatusCode(500, response)); } }
public void Should_return_same_value_when_interest_rate_is_zero() { var valor = 100; var result = new Juros(0); Assert.Equal(valor, result.Calcula(valor, 10)); }
public async Task CalculaJurosAsync_Deve_CalcularCorretamente() { //Arrange var taxaJuros = 0.01M; var juros = new Juros { Taxa = taxaJuros }; var response = new Response <Juros> { Status = new Status { Mensagem = "Taxa de Juros recuperada com sucesso.", StatusCode = HttpStatusCode.OK, Erros = new List <Error>() }, Conteudo = juros }; _configurationMock.Setup(_ => _.GetSection(It.IsAny <string>())).Returns(new Mock <IConfigurationSection>().Object); _webClientServiceMock.Setup(_ => _.GetRequest <Response <Juros> >(It.IsAny <string>())).ReturnsAsync(response); //Act var valorFinal = await _jurosService.CalculaJurosAsync(50, 3); //Assert valorFinal.Should().Be(51.51M); _webClientServiceMock.Verify(_ => _.GetRequest <Response <Juros> >(It.IsAny <string>()), Times.Once); }
public Juros GetTaxaJuros() { Juros taxaJuros = new Juros() { TaxaJuros = "0,01" }; return(taxaJuros); }
public void ValidaTipoGetTaxaJuros() { Juros taxaJuros = new Juros() { TaxaJuros = "0,01" }; TaxaJurosServices objGetTaxaJuros = new TaxaJurosServices(); Assert.IsType <Juros>(objGetTaxaJuros.GetTaxaJuros()); }
public void RetornarGetTaxaJuros() { Juros taxaJuros = new Juros() { TaxaJuros = "0,01" }; TaxaJurosServices objGetTaxaJuros = new TaxaJurosServices(); Assert.Equal(taxaJuros.TaxaJuros, objGetTaxaJuros.GetTaxaJuros().TaxaJuros); }
public static void Main(string[] args) { Juros EX = new Juros(); decimal CapitalInicial = 10000; decimal TaxaJuros = 3; decimal Prazo = 3; decimal Montante = EX.ObtenhaMontante(CapitalInicial, TaxaJuros, Prazo); decimal JurosTotal = EX.ObtenhaJuroTotal(Montante, CapitalInicial); Console.WriteLine("O resultado do montante é: {0}", Montante); Console.WriteLine("O valor do juros é: {0}", JurosTotal); }
public double CalcularJurosComposto(Juros juros) { double valorFinal = juros.ValorInicial * Math.Pow(1 + juros.TaxaDeJuros, juros.QuantidadeMeses); valorFinal = Math.Truncate(100 * valorFinal) / 100; if (valorFinal > double.MaxValue) { throw new DoubleInvalidException(); } return(valorFinal); }
public void DeveRetornarOValorDoJuros() { var valorEsperado = 1000 * 0.05 * 2; var juros = new Juros(); juros.Capital = 1000; juros.Taxa = 0.05; juros.Periodo = 2; var valorAtual = juros.CalculaJuros(); Assert.Equal(valorEsperado, valorAtual); }
private async void TaxaJuros() { using var client = new HttpClient { BaseAddress = new System.Uri("http://localhost:65460") }; requisicao = client.GetAsync($"/api/taxajuros/").Result; resposta = await requisicao.Content.ReadAsStringAsync(); taxaJuros = JsonConvert.DeserializeObject <Juros>(resposta); }
public TaxaJuros Get() { IJuros juros = new Juros(); var taxaJuros = new TaxaJuros() { TaxaJurosDecimal = juros.ValorTaxaJuros() / 100, TaxaJurosPercentagem = juros.ValorTaxaJuros() }; return(taxaJuros); }
public override string ToString() { return($"Vencimento: {Data.ToString("dd/MM/yyyy")}" + Environment.NewLine + $"Valor do serviço: R$ {ValorDoServico.ToString("F2", CultureInfo.InvariantCulture)}" + Environment.NewLine + $"Tarifa: R$ {Tarifa.ToString("F2", CultureInfo.InvariantCulture)}" + Environment.NewLine + $"Juros: R$ {Juros.ToString("F2", CultureInfo.InvariantCulture)}" + Environment.NewLine + $"Total: R$ {Total.ToString("F2", CultureInfo.InvariantCulture)}"); }
public void GetTaxaJurosComMoq() { var juros = new Mock <IServiceTaxaJuros>(MockBehavior.Strict); Juros taxaJuros = new Juros() { TaxaJuros = "0,01" }; juros.Setup(w => w.GetTaxaJuros()).Returns(() => taxaJuros); Assert.Equal <Juros>(taxaJuros, juros.Object.GetTaxaJuros()); }
public ActionResult <decimal> Get(decimal valorInicial, int meses) { var taxaJurosController = new TaxaJurosController(); var valorJuros = taxaJurosController.Get(); if (valorJuros == null) { return(BadRequest("Taxa de juros null.")); } var juros = new Juros(valorJuros.Value); return(Ok(juros.Calcula(valorInicial, meses))); }
public void DeveAceitarValores() { var valorEsperado = new { ValorInicial = _valorInicial, Meses = meses, TaxaJuros = _taxaJuros }; var juros = new Juros(valorEsperado.ValorInicial, valorEsperado.Meses, valorEsperado.TaxaJuros); valorEsperado.ToExpectedObject().ShouldMatch(juros); }
public CalcularJurosResponse CalcularJurosComposto(CalcularJurosRequest request) { if (request == null) { throw new ArgumentNullException(); } var juros = new Juros(request.QuantidadeMeses, request.ValorInicial); juros.ValorInicial = _repositoryJuros.CalcularJurosComposto(juros); decimal result = Convert.ToDecimal(juros.ValorInicial).CustomTruncate(); return(new CalcularJurosResponse(result)); }
public void ValorTaxaJuros_Test() { // arrange Mock <IJuros> jurosMock = new Mock <IJuros>(); jurosMock.Setup(x => x.ValorTaxaJuros()) .Returns(1); // act IJuros juros = new Juros(); var valorRecebido = juros.ValorTaxaJuros(); var valorEsperado = jurosMock.Object.ValorTaxaJuros(); // assert Assert.Equal(valorEsperado, valorRecebido); }
public async Task <Juros> CalcularJuros(Juros parametros) { parametros.Taxa = new Taxa() { ValorTaxa = this.ObterTaxaJurosAtual() }; if (!ExecutarValidacao(new JurosValidation(), parametros)) { return(null); } var potencia = this.CalcularPotencia(parametros.Meses, Convert.ToDouble(parametros.Taxa.ValorTaxa)); parametros.ValorFinal = (parametros.ValorInicial * potencia); return(await Task.FromResult <Juros>(parametros)); }
public async Task <Juros> ObterTaxaJurosAsync(decimal valorInicial, int meses) { var fullURL = GetAccountRepURL(); var client = _clientFactory.CreateClient(); var httpResponse = await client.GetAsync(fullURL); if (!httpResponse.IsSuccessStatusCode) { throw new Exception("Não foi possivel obter as Taxa de Juros do endpoint: " + fullURL); } var content = await httpResponse.Content.ReadAsStringAsync(); var taxa = JsonConvert.DeserializeObject <decimal>(content); var juros = new Juros(valorInicial, meses, taxa); return(juros); }
public void CalcularJuros_Test() { // arrange Mock <IJuros> jurosMock = new Mock <IJuros>(); jurosMock.Setup(x => x.ValorTaxaJuros()) .Returns(0.01); jurosMock.Setup(x => x.CalcularJuros(It.IsAny <double>(), It.IsAny <int>(), It.IsAny <double>())) .Returns(105.1); // act IJuros juros = new Juros(); var valorTaxaJuros = juros.ValorTaxaJuros() / 100; var valorRecebido = juros.CalcularJuros(100, 5, valorTaxaJuros); var valorEsperado = jurosMock.Object.CalcularJuros(1, 1, 1); // assert Assert.Equal(valorEsperado, valorRecebido); }
public async Task <IActionResult> CalcularJuros(double valorinicial, int meses) { string urlLaunch = "https://localhost:44370/taxaJuros"; using (var client = new HttpClient()) { client.BaseAddress = new Uri(urlLaunch); using (var response = await client.GetAsync(urlLaunch)) { if (response.IsSuccessStatusCode) { Taxa _taxa = JsonConvert.DeserializeObject <Taxa>(await response.Content.ReadAsStringAsync()); _taxa.valorinicial = valorinicial; _taxa.meses = meses; return(Ok(Juros.Calcular(_taxa))); } else { return(StatusCode(500, "Internal server error - APIWEBJUROS Fora do ar.")); } } } }
public void CalculaJuros() { Mock <RepositoryJuros> mockRepository = new Mock <RepositoryJuros>(); //Arrange var juros = new Juros(); juros.QuantidadeMeses = 5; juros.ValorInicial = 100; //Act var calculo = mockRepository.Object; var resultado = Convert.ToDecimal(calculo.CalcularJurosComposto(juros)).CustomTruncate(); //Assert NUnit.Framework.Assert.NotNull(resultado); if (juros.ValorInicial == 100 && juros.QuantidadeMeses == 5) { NUnit.Framework.Assert.True(resultado == 105.10M); } }
public async void CalcularJuros(string valorinicial) { int meses = 5; using (var client = new HttpClient()) { client.BaseAddress = new Uri(urlLaunch); using (var response = await client.GetAsync(urlLaunch)) { if (response.IsSuccessStatusCode) { Taxa _taxa = JsonConvert.DeserializeObject <Taxa>(await response.Content.ReadAsStringAsync()); _taxa.valorinicial = Convert.ToDouble(100); _taxa.meses = meses; string resultado = Juros.Calcular(_taxa).ToString(); Assert.Equal(valorinicial, resultado); } else { throw new InvalidCastException("Internal server error - APIWEBJUROS Fora do ar."); } } } }
static void Main(string[] args) { Juros prod = new Juros(); Console.Clear(); //Recebendo o nome do produto; Console.WriteLine("Insira o nome do produto:"); prod.nome = Console.ReadLine(); //Recebendo o valor do produto; Console.WriteLine("Insira o valor do produto (reais R$):"); prod.vReal = float.Parse(Console.ReadLine()); //Recebendo a quantidade de prestações; Console.WriteLine("Insira a quantidade de prestações:"); prod.qPrestacao = Convert.ToInt32(Console.ReadLine()); // Processamento prod.vPrestacao = prod.vReal / prod.qPrestacao; //Valor da prestação prod.vAcrescimo = (float) (prod.vPrestacao * (0.05 * (prod.qPrestacao - 1))); //Valor do acréscimo prod.vMensal = prod.vPrestacao + prod.vAcrescimo; //Valor a ser pago mensalmente (valor da prestação + acréscimo) prod.vTotal = prod.vMensal * prod.qPrestacao; //Valor total a ser pago; //Saída Console.WriteLine($"nome do preoduto {prod.nome}"); Console.WriteLine($"valor real {prod.vReal}"); Console.WriteLine($"Valor real de cada prestação (sem acréscimo): {(prod.vReal/prod.qPrestacao)}; Console.WriteLine($"Valor do acréscimo:{prod.vAcrescimo}"); Console.WriteLine($"Valor de cada mensalidade (acréscimo incluído): {prod.vMensal}"); Console.WriteLine($"Total a ser pago: {prod.vTotal}"); }
static void Main(string[] args) { Console.WriteLine(Calculadora.somar(10, 20)); Console.WriteLine(Juros.desconto(100, 10)); Console.ReadKey(); }
public void Should_return_1051_when_interest_rate_is_1percent() { var result = new Juros(0.01); Assert.Equal(Convert.ToDecimal(105.1), result.Calcula(100, 5)); }
public override string ToString() { var result = ""; if (Aprovado) { result = $"Status: APROVADO \t| Valor total: {ValorFinal.ToString("N2")} \t| Juros: {Juros.ToString("N2")}"; } else { result = $"Empréstimo não aprovado. Motivo: {MensagemDeErro}"; } return(result); }
public void Save(Juros juros) { throw new NotImplementedException(); }
public JurosTest() { _juros = new Juros(); }