Ejemplo n.º 1
0
        public void PokerFaceMain_FileHasTwoValidCardHands_EvaluatesBothHandsAndEnds()
        {
            using (var sw = new StringWriter())
            {
                Console.SetOut(sw);

                // Arrange
                const string cardHandLine1 = "2D 3D 4D 5D 6D";
                const string cardHandLine2 = "2C 3C 4C 5C 6C";

                _cardHandsFileReader.FileExists().Returns(true);
                _cardHandsFileReader.AtEndOfFile().Returns(false, false, true);
                _cardHandsFileReader.ReadNextCardHandLine().Returns(cardHandLine1, cardHandLine2);

                var pokerFaceMain = new PokerFaceMain(_cardHandsFileReader, _pokerHandNamer);

                // Act
                var result = pokerFaceMain.EvaluateHands();

                // Assert
                Assert.AreEqual((int)Constants.ExitStatusCode.Success, result);
                _cardHandsFileReader.Received(1).CloseFile();
                Assert.AreEqual("2D 3D 4D 5D 6D => Straight flush\r\n2C 3C 4C 5C 6C => Straight flush\r\n", sw.ToString());
            }

            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()));
        }
Ejemplo n.º 2
0
        public int EvaluateHands()
        {
            if (!_cardHandsFileReader.FileExists())
            {
                Console.WriteLine(Constants.ErrorMessageInputFileNotFound);
                return((int)Constants.ExitStatusCode.InputFileNotFound);
            }

            _cardHandsFileReader.OpenFile();
            while (!_cardHandsFileReader.AtEndOfFile())
            {
                var cardHandString = _cardHandsFileReader.ReadNextCardHandLine();
                var cardHand       = MapStringToCardHand.Map(cardHandString);

                if (cardHand != null)
                {
                    var pokerHandName = _pokerHandNamer.GetPokerHandNameForCardHand(cardHand);
                    Console.WriteLine($"{cardHandString} => {pokerHandName}");
                }
                else
                {
                    Console.WriteLine($"Error: Could not construct valid card hand from line: {cardHandString}");
                }
            }

            _cardHandsFileReader.CloseFile();
            return((int)Constants.ExitStatusCode.Success);
        }