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); }
public void ProcessChar(char c) { bool foundChar = false; StringBuilder sb = new StringBuilder(); sb.Append(GuessedWord[0]); for (int i = 1; i < GuessedWord.Length - 1; i++) { if (GuessedWord[i] == '_') { if (Word.ToUpper()[i] == c) { sb.Append(Word[i]); foundChar = true; } else { sb.Append("_"); } } else { sb.Append(GuessedWord[i]); } } sb.Append(GuessedWord[GuessedWord.Length - 1]); GuessedWord = sb.ToString(); if (!foundChar) { WrongChars += " " + c; WrongCharsCount++; } sb.Clear(); sb.Append(GuessedWord[0]); for (int i = 1; i < GuessedWord.Length; i++) { sb.Append(" " + GuessedWord[i]); } DisplayWord = sb.ToString(); Status = GuessedWord.IndexOf("_") == -1 ? "Success" : (WrongCharsCount > 5 ? "Failed" : ""); if (Status != "") { repository.RecordGame(playerID, wordID, WrongCharsCount, 0, Status == "Success"); } }