public CurrencyRateProviderFixture() { _dummyStream = new MemoryStream(); WebRequestExecutorMock = new Mock<IBasicHttpWebRequestExecutor>(); WebRequestExecutorMock.Setup(x => x.ExecuteAsync(It.IsAny<string>())).Returns(Task.CompletedTask); WebRequestExecutorMock.Setup(x => x.GetResponseStream()).Returns(_dummyStream); Mock<ICurrencyRateDeserializer> deserializerMock = new Mock<ICurrencyRateDeserializer>(); deserializerMock.Setup(d => d.DeserializeCurrencyRatesAsync(_dummyStream)).Returns(MakeResultTask); BasicProvider = new BasicCurrencyRateProvider(ExpectedUri, () => WebRequestExecutorMock.Object, deserializerMock.Object); }
public static void AddXch(this IServiceCollection services, string currencyServiceUri, TimeSpan currencyCacheTimoutInterval) { Func <IBasicHttpWebRequestExecutor> webRequestFactory = () => new BasicHttpWebRequestExecutor(); services.AddSingleton(webRequestFactory); ICurrencyRateDeserializer deserializer = new EcbXmlCurrencyRateDeserializer(); services.AddSingleton(deserializer); var basicProvider = new BasicCurrencyRateProvider(currencyServiceUri, webRequestFactory, deserializer); ICurrencyRateProvider cachingProvider = new CachingCurrencyRateProvider(basicProvider, currencyCacheTimoutInterval, true); services.AddSingleton(cachingProvider); }