public async Task <ActionResult> Put(Guid id, [FromBody] UpdateFieldViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { UpdateFieldModel updateFieldModel = _mapper.Map <UpdateFieldModel>(model); updateFieldModel.Id = id; Field field = await _commands.Update(updateFieldModel); if (field is null) { return(NotFound()); } return(Ok(_mapper.Map <FieldDetailsViewModel>(field))); } catch (Exception ex) when(ex is ResourceStateException) { return(Conflict(new ErrorViewModel(ex))); } }
public async Task PutFieldReturnsConflictIfResourceStateExceptionOccured() { // Given A.CallTo(() => _fakeCommand.Update(A <UpdateFieldModel> .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 <UpdateFieldModel> .Ignored)).MustHaveHappenedOnceExactly(); }