Example #1
0
        public void WhenUserGuessNo_ThenItShouldBeTheWinner()
        {
            const int expectedGuessNo      = 5;
            const int expectedWinnerUserId = 2;
            var       gameFixture          = new GameFixture();
            const int noOfRounds           = 3;
            var       game = gameFixture.CreateGame(expectedGuessNo);

            var usersForGame = new List <int> {
                1, expectedWinnerUserId, 3
            };

            game.Start(noOfRounds, 100, usersForGame);

            var expectedNonWinner = new UserInGame(1, expectedGuessNo);
            var expectedWinner    = new UserInGame(expectedWinnerUserId, expectedGuessNo - 4);
            var usersInGame       = new List <UserInGame>()
            {
                expectedNonWinner,
                expectedWinner,
                new UserInGame(3, expectedGuessNo + 44)
            };

            game.Run(usersInGame);
            expectedNonWinner.Number = expectedGuessNo + 22;
            expectedWinner.Number    = expectedGuessNo;

            game.Run(usersInGame);
            game.Run(usersInGame);

            var actualGameWinner = game.GameWinnerId;

            Assert.Equal(expectedWinner.UserId, actualGameWinner);
        }
Example #2
0
        public void WhenRunTheGame_ThenCurrentRoundShouldIncrease()
        {
            var gameFixture = new GameFixture();
            var game        = gameFixture.CreateGame();

            gameFixture.StartAnyGame();

            game.Run(gameFixture.GetUsersInGame());

            Assert.Equal(1, game.CurrentRound);
        }
Example #3
0
        public void WhenLastRoundOfGame_ShouldLastPropertyFalse()
        {
            var gameFixture = new GameFixture();
            var game        = gameFixture.CreateGame();

            gameFixture.StartAnyGame(2);

            var round1 = game.Run(gameFixture.GetUsersInGame());

            Assert.False(round1.LastRound);

            var round2 = game.Run(gameFixture.GetUsersInGame());

            Assert.True(round2.LastRound);
        }
Example #4
0
        public void WhenGameFinish_ThenRunShouldThrowGameOver()
        {
            var gameFixture = new GameFixture();
            var game        = gameFixture.CreateGame();

            gameFixture.StartAnyGame(1);

            var anonymousUsersInGame = new List <UserInGame> {
                new UserInGame(1, 1)
            };

            game.Run(anonymousUsersInGame);

            Assert.Throws <GameOverException>(() => game.Run(anonymousUsersInGame));
        }
Example #5
0
        public void WhenUserGuessesNumberInOneRound_ThenItShouldWinTheGame()
        {
            var       gameFixture          = new GameFixture();
            const int expectedGuessNo      = 5;
            const int expectedWinnerUserId = 1;
            var       usersForGame         = new List <int> {
                expectedWinnerUserId, 2
            };

            var game = gameFixture.CreateGame();

            game.Start(1, 100, usersForGame);

            var usersInGame = new List <UserInGame>
            {
                new UserInGame(expectedWinnerUserId, expectedGuessNo),
                new UserInGame(2, expectedGuessNo + 50)
            };

            game.Run(usersInGame);

            Assert.Equal(expectedWinnerUserId, game.GameWinnerId);
        }