public void AsAdmin_ShouldReturnValidationException() { RunAsAdminUser(); var command = new UpdateGesellschaftCommand() { Name = null }; FluentActions.Invoking(async() => await SendAsync(command)).Should().Throw <ValidationException>(); }
public async Task AsAnonymous_ShouldReturnUnauthorizedAccessException() { await CreateGesellschaftAsync(); var command = new UpdateGesellschaftCommand() { Id = 1, Name = "Test" }; FluentActions.Invoking(async() => await SendAsync(command)).Should().Throw <UnauthorizedAccessException>(); }
public async Task AsAdmin_GesellschaftNotExists_ShouldReturnNotFoundException() { RunAsAdminUser(); await CreateGesellschaftAsync(); var command = new UpdateGesellschaftCommand() { Id = -1, Name = "Test1" }; FluentActions.Invoking(async() => await SendAsync(command)).Should().Throw <NotFoundException>(); }
public async Task AsAdmin_ShouldUpdateGesellschaft() { var user = RunAsAdminUser(); await CreateGesellschaftAsync(); var command = new UpdateGesellschaftCommand() { Id = 1, Name = "Test1" }; await SendAsync(command); var gesellschaft = await FindAsync <Gesellschaft>(1); user.IsAdmin.Should().BeTrue(); gesellschaft.Name.Should().Be("Test1"); }
public async Task <ActionResult> CreateGesellschafft([FromBody] UpdateGesellschaftCommand command, int gesellschaftId) { if (gesellschaftId != command.Id) { return(BadRequest("Url Id does not match command ID.")); } try { await Mediator.Send(command); return(NoContent()); } catch (UnauthorizedAccessException) { return(StatusCode(StatusCodes.Status401Unauthorized)); } catch (NotFoundException exception) { return(NotFound(exception)); } }