public void InformacoesDiariaFundoTest() { IList <InformacaoDiariaFundo> informacoesFundo = new List <InformacaoDiariaFundo>(); var retornoDTO = new RetornoDTO <FundoDTO>(); var fundoDTO = new FundoDTO(); var cadastroFundo = new CadastroFundo(); var filtro = new FiltroInformacaoFundoDTO { CnpjFundo = "00.017.024/0001-53" }; _integracaoCVM.Setup(x => x.ObterInformacoesFundo(filtro.CnpjFundo)).Returns(informacoesFundo); _fundosMapper.Setup(x => x.ListaInformacaoDiariaFundo_TO_ListaInformacaoDiariaFundoDTO(It.IsAny <List <InformacaoDiariaFundo> >())).Returns(new List <InformacaoDiariaFundoDTO>() { new InformacaoDiariaFundoDTO() { CnpjFundo = "" } }); FundosService fundosService = new FundosService(_integracaoCVM.Object, _fundosMapper.Object); var res = fundosService.ObterInformacoesDiariaFundo(filtro); Assert.IsNotNull(res.Retorno); Assert.IsTrue(res.Sucesso); }
public async Task DeveRetornarInvestimentosSemCache() { var mockHttpMessageHandler = new Mock <HttpMessageHandler>(); mockHttpMessageHandler.Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(new FundosServiceResponse() { Investments = new List <FundoServiceResponseItem>() { new FundoServiceResponseItem() } })), }); var client = new HttpClient(mockHttpMessageHandler.Object); _httpClientFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client); FundosService service = new FundosService(_config, _mapper, _cache.Object, _httpClientFactory.Object); var result = await service.GetInvestments(); Assert.IsTrue(result.Count == 1); }
public InvestimentosController( TesouroDiretoService tesouroDiretoService, RendaFixaService rendaFixaService, FundosService fundosService, IOptions <BasesCalculoConfig> basesCalculoConfig, IDistributedCache cache) { this.tesouroDiretoService = tesouroDiretoService; this.rendaFixaService = rendaFixaService; this.fundosService = fundosService; this.basesCalculoConfig = basesCalculoConfig; this.cache = cache; }
public async Task DeveRetornarInvestimentosComCache() { object expectedValue = new List <InvestmentDTO>() { new InvestmentDTO() }; _cache.Setup(method => method.TryGetValue(It.IsAny <object>(), out expectedValue)).Returns(true); FundosService service = new FundosService(_config, _mapper, _cache.Object, _httpClientFactory.Object); var result = await service.GetInvestments(); Assert.IsTrue(result.Count == 1); }
public void ObterFundoInvestimentoTest() { var cadastroFundo = new CadastroFundo(); var filtro = new FiltroObterFundoDTO { CnpjFundo = "00.017.024/0001-53" }; _integracaoCVM.Setup(x => x.ObterFundo(filtro.CnpjFundo)).Returns(cadastroFundo); _fundosMapper.Setup(x => x.CadastroFundo_TO_FundoDTO(It.IsAny <CadastroFundo>())).Returns(new FundoDTO()); FundosService fundosService = new FundosService(_integracaoCVM.Object, _fundosMapper.Object); var res = fundosService.ObterFundoInvestimento(filtro); Assert.IsNotNull(res.Retorno); Assert.IsTrue(res.Sucesso); }
public async Task DeveRetornarExceptionAoNaoConseguirChamarOServicoExterno() { var mockHttpMessageHandler = new Mock <HttpMessageHandler>(); mockHttpMessageHandler.Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, }); var client = new HttpClient(mockHttpMessageHandler.Object); _httpClientFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client); FundosService service = new FundosService(_config, _mapper, _cache.Object, _httpClientFactory.Object); var result = await service.GetInvestments(); }
public void ListarFundosTest() { var listaFundoDTO = new RetornoDTO <IList <FundoDTO> >(); var listaCadastroFundo = new List <CadastroFundo>(); _fundosService.Setup(x => x.ListarFundos()).Returns(listaFundoDTO); _integracaoCVM.Setup(x => x.ListarFundos()).Returns(listaCadastroFundo); _fundosMapper.Setup(x => x.ListaCadastroFundo_TO_ListaFundoDTO(It.IsAny <List <CadastroFundo> >())).Returns(new List <FundoDTO>() { new FundoDTO() { CnpjFundo = "00.017.024/0001-53" } }); FundosService fundosService = new FundosService(_integracaoCVM.Object, _fundosMapper.Object); var res = fundosService.ListarFundos(); Assert.IsNotNull(res.Retorno); Assert.IsTrue(res.Sucesso); }
public async Task DeveRetornarListaVaziaAoTomarNotFound() { var mockHttpMessageHandler = new Mock <HttpMessageHandler>(); mockHttpMessageHandler.Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.NotFound, }); var client = new HttpClient(mockHttpMessageHandler.Object); _httpClientFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client); FundosService service = new FundosService(_config, _mapper, _cache.Object, _httpClientFactory.Object); var result = await service.GetInvestments(); Assert.IsTrue(result.Count == 0); }