protected async Task <IEnumerable <PragueStockExchangeCsvRow> > GetDataWithoutExceptions(DateTime date)
        {
            string url      = GetFileUrl(date);
            string filePath = await url.DownloadFileAsync(Path.GetTempPath());

            string requiredFile    = RESULT_FILE_NAME.Replace("{DATE}", date.ToString(DATE_FORMAT));
            string destinationPath = Path.GetFullPath(Path.Combine(Path.GetTempPath(), requiredFile));

            using (ZipArchive archive = ZipFile.OpenRead(filePath))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.Name == requiredFile)
                    {
                        if (File.Exists(destinationPath))
                        {
                            continue;
                        }

                        entry.ExtractToFile(destinationPath);
                    }
                }
            }

            PragueStockExchangeCsvParser parser = new PragueStockExchangeCsvParser();

            return(parser.GetDataFromFile(destinationPath));
        }
Esempio n. 2
0
        public void TestParsingMissingFile()
        {
            string filePath = Path.Combine(Path.GetTempPath(), "blablablafile.csv");

            PragueStockExchangeCsvParser parser = new PragueStockExchangeCsvParser();
            var result = parser.GetDataFromFile(filePath);
        }
Esempio n. 3
0
        public void TestValidParsing()
        {
            // test with invariant culture
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            string filePath = "Parser/Data/valid-input.csv";

            PragueStockExchangeCsvParser parser = new PragueStockExchangeCsvParser();
            var resultList = parser.GetDataFromFile(filePath).ToList();

            Assert.AreEqual(4, resultList.Count);

            var expectedList = GetData();

            var expectedResultPairs = expectedList.Zip(resultList, (expectedRow, resultRow) => new
            {
                Expected = expectedRow,
                Result   = resultRow
            });

            foreach (var pair in expectedResultPairs)
            {
                var expected = pair.Expected;
                var result   = pair.Result;

                foreach (PropertyInfo property in expected.GetType().GetProperties())
                {
                    Assert.AreEqual(property.GetValue(expected), property.GetValue(result), $"Property: {property.Name} is not equal");
                }
            }
        }
Esempio n. 4
0
        public void TestParsingMissingDirectory()
        {
            string filePath = "/this/is/some/wrong/path";

            PragueStockExchangeCsvParser parser = new PragueStockExchangeCsvParser();
            var result = parser.GetDataFromFile(filePath);
        }
 internal PragueStockExchangeApiClient(PragueStockExchangeCsvParser parser)
 {
     _parser = parser;
 }