コード例 #1
0
ファイル: FieldsController.cs プロジェクト: JachuPL/Spice
        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)));
            }
        }
コード例 #2
0
ファイル: IntegrationTests.cs プロジェクト: JachuPL/Spice
        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();
        }