public async Task <ActionResult> Put([FromRoute] Guid plantId, Guid id, [FromBody] UpdatePlantEventViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { UpdatePlantEventModel updateEventModel = _mapper.Map <UpdatePlantEventModel>(model); updateEventModel.Id = id; Event @event = await _commands.Update(plantId, updateEventModel); if (@event is null) { return(NotFound()); } return(Ok(_mapper.Map <PlantEventDetailsViewModel>(@event))); } catch (Exception ex) when(ex is ResourceNotFoundException) { return(NotFound(new ErrorViewModel(ex))); } catch (Exception ex) when(ex is ResourceStateException) { return(Conflict(new ErrorViewModel(ex))); } }
public async Task PutPlantEventReturnsBadRequestAndCorrectContentType() { // Given UpdatePlantEventViewModel model = ViewModelFactory.CreateInvalidUpdateModel(); // When HttpResponseMessage response = await Client.PutAsJsonAsync(EndPointFactory.UpdateEndpoint(), model); // Then response.StatusCode.Should().Be(HttpStatusCode.BadRequest); response.Content.Headers.ContentType.ToString().Should().Be("application/problem+json; charset=utf-8"); }