public async Task Metodo_CalcularJurosCompostosAsync_Deve_Retornar_Nao_Foi_Possivel_Calcular() { var input = new JurosCompostosInput() { Meses = 5, ValorInicial = 100 }; var viewModel = new JurosCompostosViewModel() { Meses = 5, TaxaJuros = 0.01m, ValorInicial = 100, JurosCompostosCalculado = 105.10m }; var jsonResult = new JsonResultBase <JurosCompostosViewModel>() { Data = viewModel, Error = false, Messages = null }; var jurosCompostos = default(JurosCompostos); var jurosCompostosDomainServiceMock = new Mock <IJurosCompostosDomainService>(); jurosCompostosDomainServiceMock.Setup(x => x.CalcularJurosCompostosAsync(jurosCompostos)).ReturnsAsync(jurosCompostos); var jurosCompostosAppService = new JurosCompostosAppService(jurosCompostosDomainServiceMock.Object); var result = await jurosCompostosAppService.CalcularJurosCompostosAsync(input); Assert.NotNull(result); Assert.True(result.Error); }
public async Task Metodo_GetAsync_Deve_Retornar_Juros_Calculado_Com_Status_Code_400() { var input = new JurosCompostosInput() { Meses = 0, ValorInicial = 0 }; var viewModel = new JurosCompostosViewModel() { Meses = 5, TaxaJuros = 0.01m, ValorInicial = 100, JurosCompostosCalculado = 105.10m }; var jsonResult = new JsonResultBase <JurosCompostosViewModel>() { Data = viewModel, Error = true, Messages = null }; var appServiceMock = new Mock <IJurosCompostosAppService>(); appServiceMock.Setup(x => x.CalcularJurosCompostosAsync(input)).ReturnsAsync(jsonResult); var controller = new JurosCompostosController(appServiceMock.Object); var resultado = await controller.GetAsync(input); Assert.NotNull(resultado); var badRequestResult = resultado as BadRequestObjectResult; Assert.Equal(400, badRequestResult.StatusCode); }
public async Task <IActionResult> GetAsync([FromQuery] JurosCompostosInput input) { var result = await _jurosCompostosAppService.CalcularJurosCompostosAsync(input); if (result == null || (result != null && result.Error)) { return(BadRequest(result)); } return(Ok(result)); }
public async Task Metodo_CalcularJurosCompostosAsync_Deve_Retornar_Calculo_Com_Sucesso() { var input = new JurosCompostosInput() { Meses = 5, ValorInicial = 100 }; var viewModel = new JurosCompostosViewModel() { Meses = 5, TaxaJuros = 0.01m, ValorInicial = 100, JurosCompostosCalculado = 105.10m }; var jsonResult = new JsonResultBase <JurosCompostosViewModel>() { Data = viewModel, Error = false, Messages = null }; var jurosCompostos = new JurosCompostos() { Meses = 5, TaxaJuros = 0, ValorInicial = 100 }; var jurosCompostosCalculado = new JurosCompostos() { Meses = 5, TaxaJuros = 0.01m, ValorInicial = 100 }; var jurosCompostosDomainServiceMock = new Mock <IJurosCompostosDomainService>(); //jurosCompostosDomainServiceMock.Setup(x => x.ObterTaxaDeJurosApiOneAsync()).ReturnsAsync(0.01m); jurosCompostosDomainServiceMock.Setup(x => x.CalcularJurosCompostosAsync(jurosCompostos)).ReturnsAsync(jurosCompostosCalculado); var jurosCompostosAppService = new JurosCompostosAppService(jurosCompostosDomainServiceMock.Object); var result = await jurosCompostosAppService.CalcularJurosCompostosAsync(input); Assert.NotNull(result); }
public async Task <JsonResultBase <JurosCompostosViewModel> > CalcularJurosCompostosAsync(JurosCompostosInput input) { var result = new JsonResultBase <JurosCompostosViewModel>(); var validarParametros = ValidarParametrosJurosCompostos(input.ValorInicial, input.Meses); if (validarParametros.Any()) { result.Data = null; result.Error = true; result.Messages = validarParametros; return(result); } var jurosCompostos = new JurosCompostos() { TaxaJuros = 0, Meses = input.Meses, ValorInicial = input.ValorInicial }; var jurosCalculado = await _jurosCompostosDomainService.CalcularJurosCompostosAsync(jurosCompostos); if (jurosCalculado == null) { var errorMsg = new ValidationMessageBase() { Message = "Não foi possível calcular o juros." }; var listMsg = new List <ValidationMessageBase>(); listMsg.Add(errorMsg); result.Data = null; result.Error = true; result.Messages = listMsg; return(result); } var data = new JurosCompostosViewModel() { ValorInicial = input.ValorInicial, Meses = input.Meses, JurosCompostosCalculado = jurosCalculado.JurosCompostosCalculado, TaxaJuros = jurosCalculado.TaxaJuros }; result.Data = data; result.Error = false; return(result); }