public void ParseCsv_FileDoesNotExist_RaisesException()
        {
            string        testFilePath = "ThisFileDoesn'tExist";
            IFrameFactory frameFactory = new FrameFactory();
            IGameFactory  gameFactory  = new GameFactory(frameFactory);
            IStringParser stringParser = new StringParser(gameFactory);

            ICsvParser csvParser = new CsvParser(stringParser);

            csvParser.GetGamesInCsv(testFilePath);
        }
        public void ParseCsv_FileContentsOutOfRange_RaiseException()
        {
            string testString   = "10,10,10,10,10,99999,10,10,10,10,10,10";
            string tempFilePath = Path.Join(tempFolderPath, "PerfectGames.csv");

            using (StreamWriter streamWriter = new StreamWriter(tempFilePath))
            {
                streamWriter.WriteLine(testString);
            }

            IFrameFactory frameFactory = new FrameFactory();
            IGameFactory  gameFactory  = new GameFactory(frameFactory);
            IStringParser stringParser = new StringParser(gameFactory);

            ICsvParser           csvParser    = new CsvParser(stringParser);
            List <List <IGame> > parsedResult = csvParser.GetGamesInCsv(tempFilePath);
        }
예제 #3
0
        static void RunFileParser(string filePath)
        {
            IFrameFactory frameFactory = new FrameFactory();
            IGameFactory  gameFactory  = new GameFactory(frameFactory);
            IStringParser stringParser = new StringParser(gameFactory);

            try
            {
                ICsvParser           csvParser   = new CsvParser(stringParser);
                List <List <IGame> > rowsOfGames = csvParser.GetGamesInCsv(filePath);
                for (int i = 0; i < rowsOfGames.Count; i++)
                {
                    Console.WriteLine($"CSV File Line {i + 1}");
                    PrintGameScores(rowsOfGames[i]);
                }
            }
            catch (Exception ex) when(ex is ArgumentOutOfRangeException || ex is FileNotFoundException || ex is FormatException)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public void ParseCsv_FileExists_ReturnsParsedList()
        {
            string testString   = "10,10,10,10,10,10,10,10,10,10,10,10\n10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10";
            string tempFilePath = Path.Join(tempFolderPath, "PerfectGames.csv");

            using (StreamWriter streamWriter = new StreamWriter(tempFilePath))
            {
                streamWriter.WriteLine(testString);
            }

            IFrameFactory frameFactory = new FrameFactory();
            IGameFactory  gameFactory  = new GameFactory(frameFactory);
            IStringParser stringParser = new StringParser(gameFactory);

            ICsvParser           csvParser    = new CsvParser(stringParser);
            List <List <IGame> > parsedResult = csvParser.GetGamesInCsv(tempFilePath);

            Assert.AreEqual(2, parsedResult.Count);
            Assert.AreEqual(1, parsedResult[0].Count);
            Assert.AreEqual(2, parsedResult[1].Count);
        }