Esempio n. 1
0
        public async Task Update(int id, UpdateGameDTO game)
        {
            var updateCommand = _Mapper.Map <UpdateGameCommand>(game);

            updateCommand.Id = id;
            await _Bus.SendCommand(updateCommand);
        }
Esempio n. 2
0
        public async Task Put_GivenGame_WhenAuthorized_ThenAcceptResponse()
        {
            // Arrage
            var token = await GetToken();

            _client.DefaultRequestHeaders.Clear();
            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            var responseGame = await _client.GetAsync("/gtracker/game/2");

            var game = JsonConvert.DeserializeObject <GameDTO>(await responseGame.Content.ReadAsStringAsync());

            UpdateGameDTO gameUpdated = new UpdateGameDTO
            {
                AcquisicionDate = game.AcquisicionDate,
                Kind            = game.Kind,
                Name            = game.Name,
                Observation     = "Ajsutando observação de atualização desse game"
            };

            var myContent   = JsonConvert.SerializeObject(gameUpdated, Formatting.Indented);
            var buffer      = Encoding.UTF8.GetBytes(myContent);
            var byteContent = new ByteArrayContent(buffer);

            byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            // Act
            var response = await _client.PutAsync("/gtracker/game/2", byteContent);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Accepted);
        }
Esempio n. 3
0
        public async Task <ActionResult> UpdatePartial([FromRoute] int id, [FromBody] JsonPatchDocument <UpdateGameDTO> patchGameDTO)
        {
            Game game = await _gameRepository.FindByIdAsync(id);

            if (game.IsNull())
            {
                return(NotFound());
            }

            UpdateGameDTO gameDTO = _mapper.Map <UpdateGameDTO>(game);

            if (!TryValidateModel(gameDTO))
            {
                return(ValidationProblem(ModelState));
            }
            await ValidateGameModelForeignKeysOnPatch(patchGameDTO, gameDTO);

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

            patchGameDTO.ApplyTo(gameDTO);
            _mapper.Map(gameDTO, game);
            await _gameRepository.UpdateAsync(game);

            return(NoContent());
        }
Esempio n. 4
0
        public IActionResult Put(int id, [FromBody] UpdateGameDTO updateGameDTO)
        {
            var valid = _gameValidator.Validate(updateGameDTO);

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

            Game game = _gameRepository.GetGame(id);

            if (game == null)
            {
                return(NotFound());
            }

            game.Name   = updateGameDTO.name;
            game.Status = updateGameDTO.status;

            if (_gameRepository.SaveGame() > 0)
            {
                return(Ok());
            }
            return(BadRequest());
        }
 public void Update(UpdateGameDTO model)
 {
     if (model != null)
     {
         var game = _mapper.Map <UpdateGameCommand>(model);
         _bus.SendCommand(game);
     }
 }
Esempio n. 6
0
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            IPlatformRepository platformRepository = (IPlatformRepository)context.HttpContext.RequestServices.GetService(typeof(IPlatformRepository));
            UpdateGameDTO       gameDTO            = (UpdateGameDTO)context.ActionArguments["gameDTO"];

            if (gameDTO.PlatformId == 0 || !await platformRepository.ExistsAsync(gameDTO.PlatformId))
            {
                context.ModelState.AddModelError("PlatformId", "The given platform id does not correspond to an existing Platform");
            }

            await next();
        }
Esempio n. 7
0
        public async Task <IActionResult> Put([FromRoute] int id, [FromBody] UpdateGameDTO game)
        {
            try
            {
                await _gameService.Update(id, game);

                return(Accepted());
            }
            catch (Exception e)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
            }
        }
Esempio n. 8
0
        public async Task <ActionResult> Update([FromRoute] int id, [FromBody] UpdateGameDTO gameDTO)
        {
            Game game = await _gameRepository.FindByIdAsync(id);

            if (game.IsNull())
            {
                return(NotFound());
            }

            _mapper.Map(gameDTO, game);
            await _gameRepository.UpdateAsync(game);

            return(NoContent());
        }
Esempio n. 9
0
 public ActionResult Put([FromBody] UpdateGameDTO updateGameDTO)
 {
     try
     {
         _gameService.Update(updateGameDTO);
         return(Ok());
     }
     catch (Exception e)
     {
         string errors = e.Message;
         return(ValidationProblem(new ValidationProblemDetails()
         {
             Type = "Model Validation Error",
             Detail = errors
         }));
     }
 }
Esempio n. 10
0
        public async Task Put_GivenGame_WhenInvalid_ThenBadRequestResponse(string acquisicionDate, int kind, string name, string observation, int qntErrors)
        {
            // Arrage
            var token = await GetToken();

            _client.DefaultRequestHeaders.Clear();
            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            DateTime result;
            DateTime?finalDate = null;

            if (DateTime.TryParse(acquisicionDate, out result))
            {
                finalDate = result;
            }

            UpdateGameDTO gameUpdated = new UpdateGameDTO
            {
                AcquisicionDate = finalDate,
                Kind            = kind,
                Name            = name,
                Observation     = observation
            };

            var myContent   = JsonConvert.SerializeObject(gameUpdated, Formatting.Indented);
            var buffer      = Encoding.UTF8.GetBytes(myContent);
            var byteContent = new ByteArrayContent(buffer);

            byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            // Act
            var response = await _client.PutAsync("/gtracker/game/2", byteContent);

            var notifications = JsonConvert.DeserializeObject <List <DomainNotification> >(await response.Content.ReadAsStringAsync());

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
            notifications.Should().HaveCount(qntErrors);
        }
Esempio n. 11
0
        public async Task Put_GivenGame_WhenNoToken_ThenAcceptResponse()
        {
            // Arrage
            UpdateGameDTO gameUpdated = new UpdateGameDTO
            {
                AcquisicionDate = DateTime.Now,
                Kind            = 1,
                Name            = "Tentativa de atualizar nome",
                Observation     = "Ajsutando observação de atualização desse game"
            };

            var myContent   = JsonConvert.SerializeObject(gameUpdated, Formatting.Indented);
            var buffer      = Encoding.UTF8.GetBytes(myContent);
            var byteContent = new ByteArrayContent(buffer);

            byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            // Act
            var response = await _client.PutAsync("/gtracker/game/2", byteContent);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
        }
Esempio n. 12
0
 private async Task ValidateGameModelForeignKeysOnPatch(JsonPatchDocument <UpdateGameDTO> patchGameDTO, UpdateGameDTO gameDTO)
 {
     if (patchGameDTO.Operations.Any(op => op.path.ToLower() == "platformid") && !await _platformRepository.ExistsAsync(gameDTO.PlatformId))
     {
         ModelState.AddModelError("PlatformId", "The given platform's id does not corresponds to an existing platform");
     }
 }