public async Task <ActionResult> PostAcceptInviteAsync( [FromServices] NaheulbookExecutionContext executionContext, [FromRoute] int groupId, [FromRoute] int characterId ) { try { await _groupService.AcceptInviteAsync(executionContext, groupId, characterId); return(new NoContentResult()); } catch (ForbiddenAccessException ex) { throw new HttpErrorException(StatusCodes.Status403Forbidden, ex); } catch (InviteNotFoundException ex) { throw new HttpErrorException(StatusCodes.Status404NotFound, ex); } catch (CharacterAlreadyInAGroupException ex) { throw new HttpErrorException(StatusCodes.Status400BadRequest, ex); } }
public void PostAcceptInviteAsync_ShouldReturnExpectedHttpStatusCodeOnKnownErrors(Exception exception, int expectedStatusCode) { _groupService.AcceptInviteAsync(_executionContext, Arg.Any <int>(), Arg.Any <int>()) .Returns(Task.FromException <GroupInvite>(exception)); Func <Task> act = () => _controller.PostAcceptInviteAsync(_executionContext, 8, 12); act.Should().Throw <HttpErrorException>().Which.StatusCode.Should().Be(expectedStatusCode); }