Esempio n. 1
0
        public void PrintListWithScore_ShouldReturnCorrectScore()
        {
            //Arrange
            Mock <IDiceHolder> mockDiceHolder     = new Mock <IDiceHolder>();
            Mock <GameHelper>  mockGameHelper     = new Mock <GameHelper>();
            ScoreParserFactory scoreParserFactory = new ScoreParserFactory();
            GamePresenter      gamePresenter      = new GamePresenter(mockDiceHolder.Object, mockGameHelper.Object, scoreParserFactory);

            Dictionary <string, int> scoreList = new Dictionary <string, int>();

            scoreList.Add("Ones", 4);
            scoreList.Add("Twos", 6);
            scoreList.Add("Threes", 3);
            scoreList.Add("Fours", 8);
            scoreList.Add("Fives", 15);
            scoreList.Add("Sixes", 6);
            scoreList.Add("ThreeOfAKind", 9);
            scoreList.Add("FourOfAKind", 12);
            scoreList.Add("FullHouse", 25);
            scoreList.Add("Straight", 20);
            scoreList.Add("Yatzy", 50);
            scoreList.Add("Chance", 10);
            mockGameHelper.Setup(x => x.GetScoreList()).Returns(scoreList);

            StringBuilder expectedListOutPut = new StringBuilder();

            foreach (KeyValuePair <string, int> score in scoreList)
            {
                expectedListOutPut.Append(score.Key + " " + score.Value + "\n");
            }

            //Act && Assert:

            Assert.AreEqual(expectedListOutPut.ToString(), gamePresenter.PrintListWithScore());
        }
Esempio n. 2
0
        public void GetBoringScoreParser_ShouldReturnBoringScoreParser()
        {
            string             typeOfParser       = "BoringScoreParser";
            ScoreParserFactory scoreParserFactory = new ScoreParserFactory();
            Mock <IDiceHolder> mockDiceHolder     = GetMockDiceHolder(1, 2, 3, 4, 5);

            IScoreParser      actual   = scoreParserFactory.GetScoreParser(typeOfParser, mockDiceHolder.Object);
            BoringScoreParser expected = new BoringScoreParser(mockDiceHolder.Object);

            actual.Should().NotBeNull();
            actual.Should().BeEquivalentTo(expected);
        }
Esempio n. 3
0
        public void PrintDice_ShouldReturnDiceWithTheirScore(int inputDiceOne, int inputDiceTwo, int inputDiceThree, int inputDiceFour, int inputDiceFive)
        {
            //Arrange
            string             expected           = "Dice1: [" + inputDiceOne + "] Dice2: [" + inputDiceTwo + "] Dice3: [" + inputDiceThree + "] Dice4: [" + inputDiceFour + "] Dice5: [" + inputDiceFive + "]";
            Mock <IDiceHolder> mockDiceHolder     = GetMockDiceHolder(inputDiceOne, inputDiceTwo, inputDiceThree, inputDiceFour, inputDiceFive);
            Mock <GameHelper>  mockGameHelper     = new Mock <GameHelper>();
            ScoreParserFactory scoreParserFactory = new ScoreParserFactory();
            GamePresenter      gamePresenter      = new GamePresenter(mockDiceHolder.Object, mockGameHelper.Object, scoreParserFactory);

            //Act & Assert
            Assert.AreEqual(expected, gamePresenter.PrintDice());
        }
Esempio n. 4
0
        public void StartGame()
        {
            _gameHelper         = new GameHelper();
            _scoreParserFactory = new ScoreParserFactory();
            Die die1 = new Die();
            Die die2 = new Die();
            Die die3 = new Die();
            Die die4 = new Die();
            Die die5 = new Die();

            List <IDie> diceList = new List <IDie>
            {
                die1,
                die2,
                die3,
                die4,
                die5
            };

            _diceHolder = new DiceHolder(diceList);
            _presenter  = new GamePresenter(_diceHolder, _gameHelper, _scoreParserFactory);

            Console.WriteLine("Lets play some Yatzy! What rules do you want to play? write 'Fun' for the fun rules, and 'Boring' for the boring ones!");
            string scoreParserToUse = Console.ReadLine();

            _presenter.ChooseScoreParser(scoreParserToUse);

            int [] initialDiceToSave = new int[0];
            while (!_gameHelper.IsGameFinished)
            {
                _presenter.Roll(initialDiceToSave);

                //Simulates one Round with two rethrows
                for (int i = 0; i < 2; i++)
                {
                    Console.WriteLine("Rethrow " + (i + 1) + " Save the die by typing the die-numbers separated by a comma. E.g '4,1' saves the first and fourth die.\n" + _presenter.PrintDice());
                    string rerollDiceToSave = Console.ReadLine();
                    int[]  diceToSave       = _presenter.ParseDieSelection(rerollDiceToSave);

                    _presenter.Roll(diceToSave);
                }

                Console.WriteLine("Time to save the score: see the current list here, and type in what to save.");
                Console.WriteLine(_presenter.PrintDice());
                Console.WriteLine(_presenter.PrintListWithScore());

                string scoreToSave = Console.ReadLine();
                _presenter.SaveScore(scoreToSave);
                Console.WriteLine("Score saved: ");
                Console.WriteLine(_presenter.PrintListWithScore());
            }
            Console.WriteLine("Well done! Final score is: " + _gameHelper.Score);
        }
Esempio n. 5
0
        public void ParseDieSelection_ShouldCorrectlyUseDelimiterOrThrow()
        {
            //Arrange
            Mock <IDiceHolder> mockDiceHolder     = new Mock <IDiceHolder>();
            Mock <GameHelper>  mockGameHelper     = new Mock <GameHelper>();
            ScoreParserFactory scoreParserFactory = new ScoreParserFactory();
            GamePresenter      gamePresenter      = new GamePresenter(mockDiceHolder.Object, mockGameHelper.Object, scoreParserFactory);
            string             input = "5,4,3";

            int[] expected = new int[] { 5, 4, 3 };

            //Act & Assert
            Assert.AreEqual(expected, gamePresenter.ParseDieSelection(input));
        }
Esempio n. 6
0
        public void SaveScore_ShouldSaveScoreInGameHelper(string chosenScoring, int inputDiceOne, int inputDiceTwo, int inputDiceThree, int inputDiceFour, int inputDiceFive, int expectedScore)
        {
            //Arrange
            Mock <IDiceHolder> mockDiceHolder     = GetMockDiceHolder(inputDiceOne, inputDiceTwo, inputDiceThree, inputDiceFour, inputDiceFive);
            Mock <GameHelper>  mockGameHelper     = new Mock <GameHelper>();
            ScoreParserFactory scoreParserFactory = new ScoreParserFactory();
            GamePresenter      gamePresenter      = new GamePresenter(mockDiceHolder.Object, mockGameHelper.Object, scoreParserFactory);

            gamePresenter.ChooseScoreParser("Fun");

            //Act
            gamePresenter.SaveScore(chosenScoring);

            //Assert
            mockGameHelper.Verify(x => x.SaveScore(chosenScoring, expectedScore), Times.Once);
        }
Esempio n. 7
0
        public void NewGame_ShouldResetAndNotHaveScoreParser()
        {
            //Arrange
            GameHelper         gamehelper         = new GameHelper();
            ScoreParserFactory scoreParserFactory = new ScoreParserFactory();
            DiceHolder         diceHolder         = new DiceHolder();


            //Act
            GamePresenter gamePresenter = new GamePresenter(diceHolder, gamehelper, scoreParserFactory);

            Assert.AreEqual(gamehelper, gamePresenter.GameHelper);


            //Assert
            gamePresenter.NewGame();
            Assert.AreNotEqual(gamehelper, gamePresenter.GameHelper);
            Assert.IsNull(gamePresenter.ScoreParser);
        }
Esempio n. 8
0
        public void Roll_ShouldLockAndRollUnlockedDice()
        {
            //Arrange
            int[] diceToRoll = new int[2];
            diceToRoll[0] = 1;
            diceToRoll[1] = 4;

            Mock <IDie> mockDie1 = new Mock <IDie>();
            Mock <IDie> mockDie2 = new Mock <IDie>();
            Mock <IDie> mockDie3 = new Mock <IDie>();
            Mock <IDie> mockDie4 = new Mock <IDie>();
            Mock <IDie> mockDie5 = new Mock <IDie>();

            List <IDie> diceList = new List <IDie>
            {
                mockDie1.Object,
                mockDie2.Object,
                mockDie3.Object,
                mockDie4.Object,
                mockDie5.Object,
            };

            mockDie1.Setup(x => x.IsLocked).Returns(true);
            mockDie4.Setup(x => x.IsLocked).Returns(true);


            IDiceHolder        diceholder         = new DiceHolder(diceList);
            Mock <GameHelper>  mockGameHelper     = new Mock <GameHelper>();
            ScoreParserFactory scoreParserFactory = new ScoreParserFactory();
            GamePresenter      gamePresenter      = new GamePresenter(diceholder, mockGameHelper.Object, scoreParserFactory);


            //Act
            gamePresenter.Roll(diceToRoll);

            //assert
            mockDie1.Verify(x => x.Roll(), Times.Never());
            mockDie2.Verify(x => x.Roll(), Times.Once());
            mockDie3.Verify(x => x.Roll(), Times.Once());
            mockDie4.Verify(x => x.Roll(), Times.Never());
            mockDie5.Verify(x => x.Roll(), Times.Once());
        }
Esempio n. 9
0
 public GamePresenter(IDiceHolder diceHolder, GameHelper gameHelper, ScoreParserFactory scoreParserFactory)
 {
     _diceHolder         = diceHolder;
     GameHelper          = gameHelper;
     _scoreParserFactory = scoreParserFactory;
 }