public async Task <ActionResult> Put(Guid id, [FromBody] UpdateSpeciesViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { UpdateSpeciesModel updateSpeciesModel = _mapper.Map <UpdateSpeciesModel>(model); updateSpeciesModel.Id = id; Species species = await _commands.Update(updateSpeciesModel); if (species is null) { return(NotFound()); } return(Ok(_mapper.Map <SpeciesDetailsViewModel>(species))); } catch (Exception ex) when(ex is ResourceStateException) { return(Conflict(new ErrorViewModel(ex))); } }
public async Task PutSpeciesReturnsBadRequestAndCorrectContentType() { // Given UpdateSpeciesViewModel 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"); }