public async Task GetHistoricalDataShouldReturnListOfExchangeRates() { var httpClientFactory = new Mock <IHttpClientFactory>(); var options = new Mock <IOptions <ExchangeRatesResourceConfiguration> >(); var json = "{}"; var httpClient = HttpClientMockHelper.CreateHttpClient(json); var from = "USD"; var to = "TRY"; var configuration = new ExchangeRatesResourceConfiguration { Endpoint = "https://gogle.com", AppId = "12345" }; options.Setup(t => t.Value).Returns(configuration); httpClientFactory .Setup(t => t.CreateClient(It.IsAny <string>())) .Returns(httpClient); IExchangeRatesResource exchangeRate = new ExchangeRatesResource( httpClientFactory.Object, options.Object); var targetDate = new DateTime(2017, 1, 15); // Actions var historicalData = await exchangeRate.GetHistorical( targetDate, from, new[] { to }); // Assertsions historicalData.Should().NotBeNull(); }
public ExchangeRatesResource(IHttpClientFactory httpClientFactory, IOptions <ExchangeRatesResourceConfiguration> options) { _configuration = options.Value ?? throw new ArgumentNullException(nameof(options)); if (httpClientFactory == null) { throw new ArgumentNullException(nameof(httpClientFactory)); } _httpClient = httpClientFactory.CreateClient(); _httpClient.BaseAddress = new Uri(_configuration.Endpoint); }