コード例 #1
0
ファイル: TestHangmanDB.cs プロジェクト: astrandr/Hangman2
        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);
        }
コード例 #2
0
ファイル: TestHangmanDB.cs プロジェクト: astrandr/Hangman2
        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);
        }
コード例 #3
0
        public static GamesResult GetGamesResult(string username)
        {
            IHangmanRepository repository = HangmanRepositoryFactory.CreateRepository();
            int         playerID          = repository.GetPlayerID(username);
            GamesResult result            = repository.GetGamesResultForPlayer(playerID);

            return(result);
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
ファイル: TestHangmanDB.cs プロジェクト: astrandr/Hangman2
        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);
        }
コード例 #6
0
ファイル: TestHangmanDB.cs プロジェクト: astrandr/Hangman2
        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);
        }
コード例 #7
0
        public Game(int categoryID, string username)
        {
            this.categoryID = categoryID;
            repository      = HangmanRepositoryFactory.CreateRepository();
            int[] wordIDs = repository.GetWords(categoryID);
            this.playerID = repository.GetPlayerID(username);

            Random rnd = new Random();
            int    n   = rnd.Next(wordIDs.Length - 1);

            wordID = wordIDs[n];

            string[] wordInfo = repository.GetWordByID(wordID);

            Word        = wordInfo[0];
            Description = wordInfo[1];

            StringBuilder sb = new StringBuilder();

            sb.Append(Word[0]);
            for (int i = 1; i < Word.Length - 1; i++)
            {
                sb.Append("_");
            }
            sb.Append(Word[Word.Length - 1]);

            GuessedWord = sb.ToString();

            sb.Clear(); sb.Append(GuessedWord[0]);

            for (int i = 1; i < GuessedWord.Length; i++)
            {
                sb.Append(" " + GuessedWord[i]);
            }

            DisplayWord = sb.ToString();

            WrongChars = "";

            WrongCharsCount = 0;
            Status          = "";
        }
コード例 #8
0
        //[ValidateAntiForgeryToken]
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                IHangmanRepository repository = HangmanRepositoryFactory.CreateRepository();
                int playerID = repository.GetPlayerID(model.UserName);
                if (playerID != 0)
                {
                    if (repository.VerifyUser(playerID, model.UserName, model.Password))
                    {
                        var user = await UserManager.FindAsync(model.UserName, model.Password);

                        if (user != null)
                        {
                            await SignInAsync(user, model.RememberMe);

                            return(RedirectToLocal(returnUrl));
                        }
                        else
                        {
                            ModelState.AddModelError("", "Invalid username or password.");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Invalid username or password.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "No user exists with provided username.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #9
0
ファイル: TestHangmanDB.cs プロジェクト: astrandr/Hangman2
 public void TestGetPlayerID()
 {
     IHangmanRepository repository = HangmanRepositoryFactory.CreateRepository();
     int id = repository.GetPlayerID("player1");
 }