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 PutSpeciesReturnsConflictIfResourceStateExceptionOccured() { // Given A.CallTo(() => _fakeCommand.Update(A <UpdateSpeciesModel> .Ignored)).Throws(A.Fake <ResourceStateException>()); // When HttpResponseMessage response = await Client.PutAsJsonAsync(EndPointFactory.UpdateEndpoint(), ViewModelFactory.CreateValidUpdateModel()); // Then response.StatusCode.Should().Be(HttpStatusCode.Conflict); response.Content.Headers.ContentType.ToString().Should().Be("application/json; charset=utf-8"); A.CallTo(() => _fakeCommand.Update(A <UpdateSpeciesModel> .Ignored)).MustHaveHappenedOnceExactly(); }