Beispiel #1
0
        public void GuessWordNonMathingWordLengths()
        {
            string           username         = "******";
            GameSessionModel gameSessionModel = new GameSessionModel()
            {
                Guesses = 5, Score = 10, LastGuess = DateTime.Now
            };
            GuessWriteDto guess = new GuessWriteDto()
            {
                Guess = "guess"
            };

            var mockContext = new Mock <HttpContext>(MockBehavior.Strict);

            mockContext.SetupGet(hc => hc.User.Identity.Name).Returns(username);
            _gameController.ControllerContext = new ControllerContext()
            {
                HttpContext = mockContext.Object
            };

            _gameService.Setup(gs => gs.RetrieveGameSessionModelByUsername(username))
            .Returns(gameSessionModel);
            _gameService.Setup(gs => gs.GameOver(gameSessionModel)).Returns(false);
            _gameService.Setup(gs => gs.InTime(gameSessionModel)).Returns(true);
            _gameService.Setup(gs => gs.MatchingWordLengths(gameSessionModel, guess.Guess)).Returns(false);

            OkObjectResult result = _gameController.GuessWord(guess) as OkObjectResult;

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual("Your guessed word and the current word do not match in length.", result.Value);
        }
Beispiel #2
0
        public void GuessWordHappyTest()
        {
            //prep auth
            string username = "******";

            GameSessionModel gameSession = new GameSessionModel()
            {
                Currentword = "word", Guesses = 3, LastGuess = DateTime.Now, Player = new UserModel(), Score = 5
            };

            GuessWriteDto guessWrite = new GuessWriteDto()
            {
                Guess = "word"
            };

            int newWordLength = 5;


            var mockContext = new Mock <HttpContext>(MockBehavior.Strict);

            mockContext.SetupGet(hc => hc.User.Identity.Name).Returns(username);
            _gameController.ControllerContext = new ControllerContext()
            {
                HttpContext = mockContext.Object
            };

            _gameService.Setup(gs => gs.RetrieveGameSessionModelByUsername(username)).Returns(gameSession);
            _gameService.Setup(gs => gs.GameOver(gameSession)).Returns(false);
            _gameService.Setup(gs => gs.InTime(gameSession)).Returns(true);
            _gameService.Setup(gs => gs.MatchingWordLengths(gameSession, "word")).Returns(true);
            _gameService.Setup(gs => gs.AttemptGuess(gameSession, guessWrite.Guess)).Returns(new List <List <char> >()
            {
                new List <char>()
                {
                    'a', 'a'
                }, new List <char>()
                {
                    'a', 'a'
                }
            });
            _gameService.Setup(gs => gs.CorrectGuess(new List <char>()
            {
                'a', 'a'
            })).Returns(true);
            _gameService.Setup(gs => gs.GetNewWordForGame(gameSession)).Returns(newWordLength);

            OkObjectResult result = _gameController.GuessWord(guessWrite) as OkObjectResult;


            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual($"Congratulations you've correctly guessed the word! a new {newWordLength} letter word has been selected.", result.Value);
        }
Beispiel #3
0
        public IActionResult GuessWord(GuessWriteDto guessWrite)
        {
            // verify if all valid preconditions are met
            GameSessionModel userGame = _gameService.RetrieveGameSessionModelByUsername(User.Identity.Name);

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (userGame == null)
            {
                return(Conflict("User doesn't currently have any game."));
            }
            string score = $"\n You're score this game was {userGame.Score}";

            if (_gameService.GameOver(userGame))
            {
                return(Ok("You've reached the maximum ammount of guesses please create a new game and try again." + score));
            }
            if (!_gameService.InTime(userGame))
            {
                if (_gameService.IncrementGuessCounter(userGame))
                {
                    return(Ok("You've waited too long your guess counter got incremented to the max ammount of guesses please create a new game" + score));
                }
                return(Ok("You've waited too long your guess counter has been incremented please try again."));
            }
            if (!_gameService.MatchingWordLengths(userGame, guessWrite.Guess))
            {
                return(Ok("Your guessed word and the current word do not match in length."));
            }

            //progress the actual guess verification here.
            List <List <char> > results = _gameService.AttemptGuess(userGame, guessWrite.Guess);

            if (_gameService.CorrectGuess(results[1]))
            {
                return(Ok($"Congratulations you've correctly guessed the word! a new {_gameService.GetNewWordForGame(userGame)} letter word has been selected."));
            }

            if (!_gameService.CorrectGuess(results[1]))
            {
                return(Ok(results));
            }

            return(BadRequest());
        }