Exemplo n.º 1
0
        public async Task <GameDTO> GetGame(Guid gameId)
        {
            var query  = new GetGameQuery(gameId);
            var result = await this.mediator.Send(query);

            return(result);
        }
Exemplo n.º 2
0
        public async Task <ActionResult <GameFollowResponse> > GetGameAsync(Guid gameId)
        {
            var query = new GetGameQuery(gameId);
            var game  = await _getGameQueryHandler.HandleAsync(query);

            return(Ok(game));
        }
Exemplo n.º 3
0
        public async Task <ActionResult <MinesweeperApi.Models.Minesweeper> > PostStartNewGame(NewGameRequest gameRequest)
        {
            var createNewGameCommand = new CreateNewGameCommand()
            {
                Width         = gameRequest.Width,
                Height        = gameRequest.Height,
                NumberOfMines = gameRequest.NumberOfMines
            };

            var createGameResponse = await _mediator.Send(createNewGameCommand);

            if (createGameResponse.Success)
            {
                var getGameQuery = new GetGameQuery()
                {
                    GameID = createGameResponse.Value
                };
                var getGameResponse = await _mediator.Send(getGameQuery);

                return(getGameResponse.Success ?
                       new ActionResult <MinesweeperApi.Models.Minesweeper>(getGameResponse.Value) :
                       new BadRequestObjectResult(getGameResponse.Error));
            }
            else
            {
                return(new BadRequestObjectResult(createGameResponse.Error));
            }
        }
Exemplo n.º 4
0
        public async Task <ActionResult <GameFollowResponse> > PutGoalAsync(Guid goalId, UpsertGoalRequest request)
        {
            var command = new UpsertGoalCommand(goalId, request);
            await _upsertGoalCommandHandler.HandleAsync(command);

            var query = new GetGameQuery(request.GameId);
            var game  = await _getGameQueryHandler.HandleAsync(query);

            return(Ok(game));
        }
Exemplo n.º 5
0
        public async Task <ActionResult <MinesweeperApi.Models.Minesweeper> > GetGame(string gameID)
        {
            var getGameQuery = new GetGameQuery()
            {
                GameID = gameID
            };
            var getGameResponse = await _mediator.Send(getGameQuery);

            return(getGameResponse.Success ?
                   new ActionResult <MinesweeperApi.Models.Minesweeper>(getGameResponse.Value) :
                   new BadRequestObjectResult(getGameResponse.Error));
        }
Exemplo n.º 6
0
        public async Task ShouldGetStatusOfExistingGame()
        {
            // Arrage
            var manager          = new GameRepository();
            var game             = manager.Create("my game", new[] { Guid.NewGuid().ToString() });
            var searchUsersQuery = SetupHelpers.SetupUserRepository(game.PlayerUserIds);

            var query   = new GetGameQuery(game.Id);
            var handler = new GetGameQueryHandler(manager, searchUsersQuery);

            // Act
            var result = await handler.Handle(query, CancellationToken.None);

            // Assert
            Assert.Equal(game.Id, result.Id);
            Assert.Equal(game.Title, result.Title);
            Assert.All(game.PlayerUserIds, p => result.UserScores.Any(p2 => p2.User.UserId == p));
            Assert.Equal(game.Scores, game.Scores);
        }