Example #1
0
        public void TestRemovePlayerByID()
        {
            IHangmanRepository repository = HangmanRepositoryFactory.CreateRepository();
            int         playerID          = repository.GetPlayerID("player1");
            GamesResult gamesResult;

            if (playerID == 0)
            {
                //Add player
                repository.AddPlayer("player1", "password");
                playerID = repository.GetPlayerID("player1");
            }

            gamesResult = repository.GetGamesResultForPlayer(playerID);
            if (gamesResult.NumberOfGames == 0)
            {
                int wordID = repository.GetWords(1)[0];
                repository.RecordGame(playerID, wordID, 3, 3, true);
                gamesResult = repository.GetGamesResultForPlayer(playerID);
            }
            Assert.IsTrue(gamesResult.NumberOfGames > 0);
            Assert.IsTrue(gamesResult.NumberOfSuccess > 0);

            Assert.IsTrue(playerID > 0);

            repository.RemovePlayerByID(playerID);

            int id2 = repository.GetPlayerID("player1");

            gamesResult = repository.GetGamesResultForPlayer(playerID);
            Assert.IsTrue(id2 == 0);
            Assert.IsTrue(gamesResult.NumberOfGames == 0);
        }
Example #2
0
        public void TestAddPlayer()
        {
            IHangmanRepository repository = HangmanRepositoryFactory.CreateRepository();
            int id = repository.GetPlayerID("player1");

            if (id != 0)
            {
                repository.RemovePlayerByID(id);
            }
            bool firstTimeAdded  = repository.AddPlayer("player1", "password");
            bool secondTimeAdded = repository.AddPlayer("player1", "password");

            Assert.IsTrue(firstTimeAdded = id > 0 ? true : false);
            Assert.IsFalse(secondTimeAdded);
        }