public async Task SaveDataFeed()
        {
            var mapper        = new DataFeedMapper();
            var configuration = new Mock <IDataFeedRepositoryConfiguration>();

            configuration.Setup(c => c.StorageFolderPath).Returns(storageFolderPath);
            var repository = new DataFeedRepository(configuration.Object, mapper);

            var dataFeed = new DataFeed()
            {
                Base      = "EUR",
                Success   = true,
                Timestamp = 1541819346,
                Rates     = new Dictionary <string, decimal>()
                {
                    { "ETB", 31.813406m },
                    { "EUR", 1m },
                    { "GBP", 0.873592m }
                }
            };

            await repository.SaveAsync(dataFeed);

            var fileName = Directory.GetFiles(storageFolderPath).FirstOrDefault(f => f.EndsWith("ExchangeRate_20181110140906.json"));

            Assert.IsNotNull(fileName);
            Assert.IsTrue(new FileInfo(fileName).Length > 0, "File size is zero");
        }
示例#2
0
        public async Task DownloadNewDataFeed()
        {
            await new Startup().RunAsync();
            var mapper        = new DataFeedMapper();
            var configuration = new Mock <IDataFeedRepositoryConfiguration>();

            configuration.Setup(c => c.StorageFolderPath).Returns(Path.Combine(Path.GetTempPath(), "ExchangeRates"));
            var repository = new DataFeedRepository(configuration.Object, mapper);
            var dataFeed   = await repository.LoadAsync();

            Assert.IsNotNull(dataFeed, "Should load DataFeed");
        }
示例#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();
            }
        }
        public async Task ReadLatestDataFeed()
        {
            var mapper        = new DataFeedMapper();
            var configuration = new Mock <IDataFeedRepositoryConfiguration>();

            configuration.Setup(c => c.StorageFolderPath).Returns(storageFolderPath);
            var repository = new DataFeedRepository(configuration.Object, mapper);

            var dataFeed1 = new DataFeed()
            {
                Base      = "EUR",
                Success   = true,
                Timestamp = 1541819346,
                Rates     = new Dictionary <string, decimal>()
                {
                    { "ETB", 31.813406m },
                    { "EUR", 1m },
                    { "GBP", 0.873592m }
                }
            };

            await repository.SaveAsync(dataFeed1);

            var dataFeed2 = new DataFeed()
            {
                Base      = "EUR",
                Success   = true,
                Timestamp = 1541819446,
                Rates     = new Dictionary <string, decimal>()
                {
                    { "ETB", 31.813406m },
                    { "EUR", 1m },
                    { "GBP", 0.873592m }
                }
            };

            await repository.SaveAsync(dataFeed2);

            var dataFeed = await repository.LoadAsync();

            Assert.AreEqual(dataFeed2.Timestamp, dataFeed.Timestamp, "Should load latest DataFeed");
        }