public async Task CreateGame_CreateGameSuccessfully()
        {
            //Arrange
            var parameters = _fixture.Create <CreateGameParameters>();
            var gameId     = Guid.NewGuid();

            var card = Card.CreateNew(
                Guid.NewGuid(),
                gameId);

            var newGame = Game.CreateNew(
                id: Guid.NewGuid(),
                name: parameters.Name,
                card: card,
                numberOfCards: parameters.NumberOfCards.GetValueOrDefault());

            _mockGameRepository
            .Setup(exec =>
                   exec.CreateGameAsync(
                       It.IsAny <Game>()))
            .Returns(Task.CompletedTask);

            _mockGameRepository
            .Setup(exec =>
                   exec.CompleteAsync())
            .Returns(Task.FromResult(2));

            //Act
            var result = await _gameController
                         .CreateGame(parameters) as OkObjectResult;

            //Assert
            _mockGameRepository
            .Verify(exec =>
                    exec.CreateGameAsync(It.IsAny <Game>()),
                    Times.Once);

            _mockGameRepository
            .Verify(exec =>
                    exec.CompleteAsync(),
                    Times.Once);

            result
            .Should()
            .NotBeNull();

            result.StatusCode
            .Should()
            .Be((int)HttpStatusCode.OK);

            var gameResult = result.Value as GetGameResults;

            gameResult.Name
            .Should()
            .Be(newGame.Name);
        }
Ejemplo n.º 2
0
        public void Start()
        {
            var games = new GamesController();
            var loop  = true;

            while (loop)
            {
                UI.PrintMainMenu();
                var input = Console.ReadKey(true).Key;

                switch (input)
                {
                case ConsoleKey.D1:
                    games.CreateGame();
                    break;

                case ConsoleKey.D2:
                    games.RemoveGame();
                    break;

                case ConsoleKey.D3:
                    games.PrintGameList();
                    break;

                case ConsoleKey.D4:
                    games.EditGame();
                    break;

                case ConsoleKey.D5:
                    loop = false;
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        public void CreateGame_should_create_game()
        {
            //Act
            var actionResult = _gamesController.CreateGame(new AddGameModel());

            //Assert
            actionResult.Should().BeOfType <OkNegotiatedContentResult <string> >();
        }
        internal void Start()
        {
            var games = new GamesController();
            var shows = new TVShowController();

            var loop = true;

            while (loop)
            {
                UI.PrintMainMenu();
                var input = Console.ReadKey(true).Key;

                switch (input)
                {
                    case ConsoleKey.D1:
                        games.CreateGame();
                        break;

                    case ConsoleKey.D2:
                        games.RemoveGame();
                        break;

                    case ConsoleKey.D3:
                        games.PrintGameList();
                        break;

                    case ConsoleKey.D4:
                        games.EditGame();
                        break;

                    case ConsoleKey.D5:
                        shows.CreateShow();
                        break;

                    case ConsoleKey.D6:
                        shows.RemoveShow();
                        break;

                    case ConsoleKey.D7:
                        shows.PrintShowList();
                        break;

                    case ConsoleKey.D8:
                        shows.EditShow();
                        break;

                    case ConsoleKey.D9:
                        loop = false;
                        break;

                }
            }

        }
        private GameModel TestGameCreate()
        {
            GamesController controller = new GamesController();

            var result = controller.GetGames();

            Assert.IsInstanceOfType(result, typeof(GetGameListType));

            var gameList = ((GetGameListType)result).Content;

            long nextExpectedGameId = 1;

            if (gameList.Count != 0)
            {
                nextExpectedGameId = gameList[gameList.Count - 1].Id + 1;
            }

            // test that nextExpectedGameId does not yet exist
            result = controller.GetGame(nextExpectedGameId);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));

            // verify that all others in gamelist can be found
            foreach (GameModel game in gameList)
            {
                result = controller.GetGame(game.Id);
                Assert.IsInstanceOfType(result, typeof(GetGameType));
                Assert.AreEqual(game, ((GetGameType)result).Content);
            }

            var player = TestHelpers.TestData.getAuthorizedPlayers()[0];

            // Test Game Create and verify you can get it
            result = controller.CreateGame();

            // Need to provide authorization to create a game
            Assert.IsInstanceOfType(result, typeof(UnauthorizedResult));

            // Add Authorization
            var context = new HttpControllerContext();
            var request = new HttpRequestMessage();

            request.Headers.Add("Authorization", player.AuthCode);

            controller.ControllerContext = context;
            controller.Request           = request;

            result = controller.CreateGame();
            Assert.IsInstanceOfType(result, typeof(PostGameType));

            GameModel newGame = ((PostGameType)result).Content;

            Assert.AreEqual(player.PlayerName, newGame.Hostname);
            Assert.AreEqual(nextExpectedGameId, newGame.Id);

            // Test that game can now be found
            // test that nextExpectedGameId does not yet exist
            result = controller.GetGame(newGame.Id);
            Assert.IsInstanceOfType(result, typeof(GetGameType));

            return(newGame);
        }