public void PutChangeItemContainerAsync_ShouldReturnExpectedHttpStatusCodeOnKnownErrors(Exception exception, int expectedStatusCode) { _itemService.ChangeItemContainerAsync(Arg.Any <NaheulbookExecutionContext>(), Arg.Any <int>(), Arg.Any <ChangeItemContainerRequest>()) .Returns(Task.FromException <Item>(exception)); Func <Task> act = () => _controller.PutChangeItemContainerAsync(_executionContext, 2, new ChangeItemContainerRequest()); act.Should().Throw <HttpErrorException>().Which.StatusCode.Should().Be(expectedStatusCode); }
public async Task <ActionResult <ItemPartialResponse> > PutChangeItemContainerAsync( [FromServices] NaheulbookExecutionContext executionContext, [FromRoute] int itemId, ChangeItemContainerRequest request ) { try { var item = await _itemService.ChangeItemContainerAsync(executionContext, itemId, request); return(_mapper.Map <ItemPartialResponse>(item)); } catch (ForbiddenAccessException ex) { throw new HttpErrorException(StatusCodes.Status403Forbidden, ex); } catch (ItemNotFoundException ex) { throw new HttpErrorException(StatusCodes.Status404NotFound, ex); } }