Exemplo n.º 1
0
 public void Given_a_game_When_ApplyPlayerSelectionOnGame_is_called_Then_The_Board_Is_Successfully_Updated
 (
     GameDto someGame,
     PlayerSelectionDto playerSelection,
     Result <BoardDto> expectedResultBoard
 )
 {
     Generic_DataDrivenTests_For_ApplyPlayerSelectionOnGame(someGame, playerSelection, expectedResultBoard);
 }
Exemplo n.º 2
0
        public JsonResult ApplyPlayerSelectionOnGame(
            [FromBody] PlayerSelectionDto viewModel)
        {
            var resultGame = _repository.GetGameById(viewModel.GameId);
            var result     = resultGame
                             .OnSuccess(() => resultGame.Value.ApplyPlayerSelection(viewModel.NomPlayer, viewModel.Line, viewModel.Column))
                             .OnSuccess(() => _repository.Update(resultGame.Value))
                             .OnSuccess(() => _repository.SaveAll());

            if (result.Success)
            {
                var boardDto = Mapper.Map <BoardDto>(resultGame.Value.Board);
                _eventPublisher.Publish <BoardDto>(resultGame.Value.Id, boardDto);
                Response.StatusCode = (int)HttpStatusCode.OK;
                return(Json(boardDto));
            }
            else
            {
                _logger.LogError(result.Error);
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(result.Error));
            }
        }
Exemplo n.º 3
0
        private void Generic_DataDrivenTests_For_ApplyPlayerSelectionOnGame(
            GameDto someGame,
            PlayerSelectionDto playerSelection,
            Result <BoardDto> expectedResultBoard
            )
        {
            //Arrange
            _client.Post <GameDto>(UrlGame.CreateGameWithGrid, someGame).OnFailure((error) => throw new Exception($"Data creation failed. Error : {error}"));

            //Act
            var response =
                _client.Post <BoardDto>(UrlGame.ApplyPlayerSelectionOnGame, playerSelection);

            // Assert
            expectedResultBoard
            .OnSuccess((expectedBoard) => {
                Assert.True(response.Success, $"Erreur non attendue retournée par l'API : {response.Error}");
                Assert.Equal <BoardDto>(expectedBoard, response.Value);
            })
            .OnFailure(() => {
                Assert.True(response.Failure, $"Succès non attendu. réponse de l'API : {response.Value}");
                Assert.Equal <string>(expectedResultBoard.Error, response.Error);
            });
        }