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 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 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 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);
        }