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 RendaFixaServiceResponse() { Investments = new List <RendaFixaServiceResponseItem>() { new RendaFixaServiceResponseItem() } })), }); var client = new HttpClient(mockHttpMessageHandler.Object); _httpClientFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client); RendaFixaService service = new RendaFixaService(_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); RendaFixaService service = new RendaFixaService(_config, _mapper, _cache.Object, _httpClientFactory.Object); var result = await service.GetInvestments(); Assert.IsTrue(result.Count == 1); }
public RendaFixaService GetService() { if (_service is null) { Mocker.Use <HttpClient>(new HttpClient()); Mocker.Use <IOptions <ApplicationOptions> >(Options.Create(new ApplicationOptions { BaseAddress = "http://www.mocky.io", RendaFixaEndpoint = "5e3429a33000008c00d96336" })); _service = Mocker.CreateInstance <RendaFixaService>(); } return(_service); }
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); RendaFixaService service = new RendaFixaService(_config, _mapper, _cache.Object, _httpClientFactory.Object); var result = await service.GetInvestments(); }
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); RendaFixaService service = new RendaFixaService(_config, _mapper, _cache.Object, _httpClientFactory.Object); var result = await service.GetInvestments(); Assert.IsTrue(result.Count == 0); }