public async Task <ActionResult <int> > CreateDokumentFürVermittler(int id, [FromBody] CreateDokumentFürVermittlerCommand command) { if (id != command.VermittlerId) { return(BadRequest()); } try { return(Ok(await Mediator.Send(command))); } catch (NotFoundException ex) { return(NotFound(ex.Message)); } catch (BadRequestException ex) { return(BadRequest(ex.Message)); } catch (UnauthorizedAccessException) { return(StatusCode(StatusCodes.Status401Unauthorized)); } }
public async Task AsAnonymous_ShouldReturnUnauthorizedAccessException() { await CreateVermittlerAsync(); CreateDokumentFürVermittlerCommand command = await Create_CreateDokumentFürVermittlerCommandAsync(); FluentActions.Invoking(async() => await SendAsync(command)).Should().Throw <UnauthorizedAccessException>(); }
public async Task AsAdmin_ShouldReturnNotFoundExceptionForUnknownDokumentArtId() { RunAsAdminUser(); await CreateVermittlerAsync(); CreateDokumentFürVermittlerCommand command = await Create_CreateDokumentFürVermittlerCommandAsync(); command.DokumentArtId = 5; FluentActions.Invoking(async() => await SendAsync(command)).Should().Throw <NotFoundException>(); }
public async Task AsBearbeiter_ShouldThrowValidationException() { RunAsBearbeiterUser(); await CreateVermittlerAsync(); CreateDokumentFürVermittlerCommand command = await CreateInvalidCreateDokumentFürVermittlerCommandAsync(); Func <Task> act = async() => { await SendAsync(command); }; act.Should().Throw <ValidationException>() .Which.Errors.Count().Should().Be(6); }
public async Task AsAdmin_ShouldReturnBadRequestExceptionVermittlerAlreadyHasDokumentWithSameDokumentArt() { RunAsAdminUser(); await CreateVermittlerAsync(); CreateDokumentFürVermittlerCommand command = await Create_CreateDokumentFürVermittlerCommandAsync(); command.DokumentArtId = 1; FluentActions.Invoking(async() => await SendAsync(command)).Should().Throw <BadRequestException>(); }
public async Task AsVermittler_ShouldCreateDokumentAndSetBearbeitungsstatusZuPrüfen() { RunAsVermittlerUser(); await CreateVermittlerAsync(); CreateDokumentFürVermittlerCommand command = await Create_CreateDokumentFürVermittlerCommandAsync(); var result = await SendAsync(command); var dokumentFromRepo = await FindAsync <Dokument>(result); dokumentFromRepo.Should().NotBeNull(); dokumentFromRepo.Bearbeitungsstatus.Should() .Be(Bearbeitungsstatus.ZuPrüfen); }
public async Task AsAdmin_ShouldCreateDokumentAndReturnIdOfCorrectDokument() { RunAsAdminUser(); await CreateVermittlerAsync(); CreateDokumentFürVermittlerCommand command = await Create_CreateDokumentFürVermittlerCommandAsync(); var result = await SendAsync(command); var dokumentFromRepo = await FindAsync <Dokument>(result); dokumentFromRepo.Should().NotBeNull(); dokumentFromRepo.Bearbeitungsstatus.Should() .Be(EnumExtensions.ParseEnumFromString <Bearbeitungsstatus>(command.Bearbeitungsstatus)); dokumentFromRepo.Id.Should().Be(result); }