Esempio n. 1
0
        static void ParseDirectoryWithParser(string directory, RepositoryParser repositoryParser, bool printConverted)
        {
            var dirInfo = new DirectoryInfo(directory);

            FileInfo[] files = dirInfo.GetFiles("*.txt");

            Console.WriteLine("Parsing {0} files.", files.Length);

            int fileCounter = 0;

            foreach (FileInfo file in files)
            {
                try
                {
                    string handHistories = new StreamReader(file.OpenRead()).ReadToEnd();

                    IEnumerable <IConvertedPokerHand> convertedPokerHands =
                        repositoryParser.RetrieveAndConvert(handHistories, file.FullName);
                    if (printConverted)
                    {
                        PrintToConsole(convertedPokerHands);
                    }

                    fileCounter++;
                }
                catch (Exception excep)
                {
                    Console.WriteLine("File #{0} name is {1}", fileCounter, file.Name);
                    Console.WriteLine(excep);
                }
            }

            Console.WriteLine("Finished Files #{0}", fileCounter);
        }
Esempio n. 2
0
        public void RetrieveAndConvert_EmptyString_ThrowsUnrecognizedHandHistoryFormatException()
        {
            _parsers.Add(_mockParser.Object);

            var repositoryParser = new RepositoryParser(_parsers, _stub.Out <IConstructor <IPokerHandConverter> >());

            Assert.Throws <UnrecognizedHandHistoryFormatException>(
                () => repositoryParser.RetrieveAndConvert(string.Empty, FileName));
        }
Esempio n. 3
0
        public void RetrieveAndConvert_SameHandTwice_ReturnsConvertedPokerHands()
        {
            const int extractedGameId = 1;

            Mock <IPokerHandParser> stubParser =
                ParserThatRecognizesAndSeparatesHandsAndParseSetsAquiredHandTo(extractedGameId);

            _parsers.Add(stubParser.Object);

            Mock <IPokerHandConverter> mockConverter = ConverterThatReturnsConvertedHandWith(extractedGameId);

            var repositoryParser = new RepositoryParser(_parsers, new Constructor <IPokerHandConverter>(() => mockConverter.Object));

            repositoryParser.RetrieveAndConvert(SomeHandHistoriesString, FileName);
            IEnumerable <IConvertedPokerHand> convertedHands =
                repositoryParser.RetrieveAndConvert(SomeHandHistoriesString, FileName);

            Assert.That(convertedHands.First().GameId, Is.EqualTo(extractedGameId));
        }
Esempio n. 4
0
        public void RetrieveAndConvert_SameHandTwice_CallsConvertOnConverterOnlyOnce()
        {
            const int extractedGameId = 1;
            Expression <Func <IAquiredPokerHand, bool> > handToBeConverted = h => h.GameId == extractedGameId;
            Mock <IPokerHandParser> stubParser =
                ParserThatRecognizesAndSeparatesHandsAndParseSetsAquiredHandTo(extractedGameId);

            _parsers.Add(stubParser.Object);

            Mock <IPokerHandConverter> mockConverter = ConverterThatReturnsConvertedHandWith(extractedGameId);

            var repositoryParser = new RepositoryParser(_parsers, new Constructor <IPokerHandConverter>(() => mockConverter.Object));

            repositoryParser.RetrieveAndConvert(SomeHandHistoriesString, FileName);
            repositoryParser.RetrieveAndConvert(SomeHandHistoriesString, FileName);

            mockConverter.Verify(
                c => c.ConvertAquiredHand(It.Is(handToBeConverted)), Times.Once());
        }
Esempio n. 5
0
        public void RetrieveAndConvert_SameHandTwice_CallsParseOnParserOnlyOnce()
        {
            const string extractedHistory   = "someHistory";
            const int    extractedGameId    = 1;
            var          extractedHistories = new Dictionary <ulong, string> {
                { extractedGameId, extractedHistory }
            };

            Mock <IPokerHandParser> mockParser =
                ParserThatRecognizesHandsAndWhenExtractingHandsReturns(extractedHistories, SomeHandHistoriesString);

            _parsers.Add(mockParser.Object);

            Mock <IPokerHandConverter> stubConverter = ConverterThatReturnsConvertedHandWith(extractedGameId);

            var repositoryParser = new RepositoryParser(_parsers, new Constructor <IPokerHandConverter>(() => stubConverter.Object));

            repositoryParser.RetrieveAndConvert(SomeHandHistoriesString, FileName);
            repositoryParser.RetrieveAndConvert(SomeHandHistoriesString, FileName);

            mockParser.Verify(parser => parser.ParseHand(extractedHistory), Times.Once());
        }
Esempio n. 6
0
        public void RetrieveAndConvert_ParserSeparateHandHistoriesReturnsEmpty_DoesNotCallParseOnParser()
        {
            Mock <IPokerHandParser> mockParser =
                ParserThatRecognizesHandsButReturnsEmptyWhenExtractingHands(SomeHandHistoriesString);

            _parsers.Add(mockParser.Object);

            var repositoryParser = new RepositoryParser(_parsers, _stub.Out <IConstructor <IPokerHandConverter> >());

            repositoryParser.RetrieveAndConvert(SomeHandHistoriesString, FileName);

            mockParser.Verify(parser => parser.ParseHand(It.IsAny <string>()), Times.Never());
        }
Esempio n. 7
0
        public void RetrieveAndConvert_ParserRecognizesHandHistory_SeparatesHandHistories()
        {
            Mock <IPokerHandParser> mockParser =
                ParserThatRecognizesHandsButReturnsEmptyWhenExtractingHands(SomeHandHistoriesString);

            _parsers.Add(mockParser.Object);

            var repositoryParser = new RepositoryParser(_parsers, _stub.Out <IConstructor <IPokerHandConverter> >());

            repositoryParser.RetrieveAndConvert(SomeHandHistoriesString, FileName);

            mockParser.Verify(parser => parser.ExtractSeparateHandHistories(SomeHandHistoriesString));
        }
Esempio n. 8
0
        public void RetrieveAndConvert_NoParserRecognizesHandHistory_ThrowsUnrecognizedHandHistoryFormatException()
        {
            const bool recognizeHandHistories = false;

            _mockParser
            .Setup(parser => parser.RecognizesHandHistoriesIn(SomeHandHistoriesString))
            .Returns(recognizeHandHistories);
            _parsers.Add(_mockParser.Object);

            var repositoryParser = new RepositoryParser(_parsers, _stub.Out <IConstructor <IPokerHandConverter> >());

            Assert.Throws <UnrecognizedHandHistoryFormatException>(
                () => repositoryParser.RetrieveAndConvert(SomeHandHistoriesString, FileName));
        }
Esempio n. 9
0
        public void RetrieveAndConvert_ParserSeparateHandHistoriesReturnsEmpty_DoesNotCallConvertOnHandConverter()
        {
            Mock <IPokerHandParser> stubParser =
                ParserThatRecognizesHandsButReturnsEmptyWhenExtractingHands(SomeHandHistoriesString);

            _parsers.Add(stubParser.Object);

            var mockHandConverter = new Mock <IPokerHandConverter>();

            var repositoryParser = new RepositoryParser(_parsers, new Constructor <IPokerHandConverter>(() => mockHandConverter.Object));

            repositoryParser.RetrieveAndConvert(SomeHandHistoriesString, FileName);

            mockHandConverter.Verify(
                converter => converter.ConvertAquiredHand(It.IsAny <IAquiredPokerHand>()), Times.Never());
        }