Example #1
0
        public async Task <ActionResult> SearchGame(string userName)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(userName))
                {
                    new Exception(GameMessage.ReceivedDataError);
                }

                SearchGameStartView view = await _startService.SearchGame(userName);

                if (view.IsGameExist)
                {
                    return(RedirectToAction("Initialize", new { view.GameId, userName }));
                }

                return(RedirectToAction("CreateGame", new { userName }));
            }
            catch (Exception exception)
            {
                string message = exception.ToString();
                _logger.Error(message);
                return(RedirectToAction("Display", "Error", new { message = GameMessage.PlayerAuthorizationError }));
            }
        }
Example #2
0
        public void SearchGameTestForGameNotExist()
        {
            string userName = "******";
            Game   game     = null;

            _mockGameRepository = new Mock <IGameRepository>(MockBehavior.Strict);
            _mockGameRepository.Setup(p => p.GetByHumanName(userName)).Returns(Task.FromResult(game));

            _startService = new StartService(_mockGameRepository.Object, null, null, null);
            SearchGameStartView result = _startService.SearchGame(userName).Result;

            Assert.That(result.IsGameExist, Is.EqualTo(false));
        }
Example #3
0
        public async Task <SearchGameStartView> SearchGame(string name)
        {
            Game game = await _gameRepository.GetByHumanName(name);

            SearchGameStartView view = new SearchGameStartView();

            view.IsGameExist = false;

            if (game != null)
            {
                view.IsGameExist = true;
                view.GameId      = game.Id;
            }

            return(view);
        }
Example #4
0
        public async Task <IHttpActionResult> SearchGame(string userName)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(userName))
                {
                    new Exception(GameMessage.ReceivedDataError);
                }

                SearchGameStartView view = await _startService.SearchGame(userName);

                return(Ok(view));
            }
            catch (Exception exception)
            {
                string message = exception.ToString();
                _logger.Error(message);
                return(BadRequest(GameMessage.PlayerAuthorizationError));
            }
        }