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); }
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 TestUpdatePlayerByID() { IHangmanRepository repository = HangmanRepositoryFactory.CreateRepository(); int id1 = repository.GetPlayerID("player1"); if (id1 == 0) { //Add player repository.AddPlayer("player1", "password"); id1 = repository.GetPlayerID("player1"); } Assert.IsTrue(id1 > 0); repository.UpdatePlayerByID(id1, "player12", "password12"); int id2 = repository.GetPlayerID("player1"); Assert.IsTrue(id2 == 0); int id3 = repository.GetPlayerID("player12"); Assert.IsTrue(id3 == id1); repository.UpdatePlayerByID(id1, "player1", "password"); int id4 = repository.GetPlayerID("player1"); Assert.IsTrue(id4 == id1); }
private void AddPlayer(string username, string password) { IHangmanRepository repository = HangmanRepositoryFactory.CreateRepository(); int playerID = repository.GetPlayerID(username); if (playerID == 0) { repository.AddPlayer(username, password); } else { repository.UpdatePlayerByID(playerID, username, password); } }
public void TestVerifyUser() { IHangmanRepository repository = HangmanRepositoryFactory.CreateRepository(); int id1 = repository.GetPlayerID("player1"); if (id1 == 0) { //Add player repository.AddPlayer("player1", "password"); id1 = repository.GetPlayerID("player1"); } Assert.IsTrue(id1 > 0); bool userVerified = repository.VerifyUser(id1, "player1", "password"); Assert.IsTrue(userVerified); bool userVerificationFailedForName = !repository.VerifyUser(id1, "player", "password"); Assert.IsTrue(userVerificationFailedForName); bool userVerificationFailedForPassword = !repository.VerifyUser(id1, "player1", "password2"); Assert.IsTrue(userVerificationFailedForPassword); }