public async Task DownloadNewDataFeed()
        {
            var text = TestHelper.GetEmbeddedResourceAsString("TestFiles.DataFeedSmall.json");

            var configuration = new DataFeedManagerConfiguration()
            {
                ServiceUrl        = @"http://data.fixer.io/api/latest?access_key=c2510f9a89d59e5f17e511157b0bcb41",
                StorageFolderPath = Path.Combine(Path.GetTempPath(), "ExchangeRates")
            };

            var mapper     = new DataFeedMapper();
            var repository = new Mock <IDataFeedRepository>(MockBehavior.Strict);

            repository.Setup(r => r.SaveAsync(It.IsAny <DataFeed>())).Callback((DataFeed dataFeed) =>
            {
                Assert.AreEqual(1541812746, dataFeed.Timestamp);
            }).Returns(Task.Delay(1));

            var service = new DataFeedService(repository.Object);

            var downloadClient = new Mock <IDownloadClient>(MockBehavior.Strict);

            downloadClient.Setup(c => c.DownloadAsync(configuration.ServiceUrl)).ReturnsAsync(text);

            var manager = new DataFeedManager(configuration, downloadClient.Object, mapper, service);
            await manager.DownloadAsync();
        }
Example #2
0
 public DataFeedServiceWithCache(
     DataFeedService dataFeedService,
     IMemoryCache memoryCache,
     ExchangeRateServiceConfiguration configuration)
 {
     this.dataFeedService = dataFeedService ?? throw new ArgumentNullException(nameof(dataFeedService));
     this.memoryCache     = memoryCache ?? throw new ArgumentNullException(nameof(memoryCache));
     this.configuration   = configuration ?? throw new ArgumentNullException(nameof(configuration));
 }
Example #3
0
        public async Task RunAsync()
        {
            var configuration = new DataFeedManagerConfiguration()
            {
                ServiceUrl        = @"http://data.fixer.io/api/latest?access_key=c2510f9a89d59e5f17e511157b0bcb41",
                StorageFolderPath = Path.Combine(Path.GetTempPath(), "ExchangeRates")
            };

            var mapper     = new DataFeedMapper();
            var repository = new DataFeedRepository(configuration, mapper);
            var service    = new DataFeedService(repository);

            using (var httpClient = new HttpClient())
            {
                var downloadClient = new HttpDownloadClient(httpClient);
                var manager        = new DataFeedManager(configuration, downloadClient, mapper, service);
                await manager.DownloadAsync();
            }
        }