Esempio n. 1
0
        public async Task <ActionResult> UpdateDokumentFürVermittler(int id, int dokumentId,
                                                                     [FromBody] SoftDeleteDokumentFürVermittlerCommand command)
        {
            if (id != command.VermittlerId)
            {
                return(BadRequest());
            }

            if (dokumentId != command.DokumentId)
            {
                return(BadRequest());
            }

            try
            {
                await Mediator.Send(command);

                return(NoContent());
            }
            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();

            SoftDeleteDokumentFürVermittlerCommand command = new SoftDeleteDokumentFürVermittlerCommand
            {
                VermittlerId = 1,
                DokumentId   = 1
            };

            FluentActions.Invoking(async() =>
                                   await SendAsync(command)).Should().Throw <UnauthorizedAccessException>();
        }
        public async Task AsAdmin_VermittlerNotExists_ShouldThrowNotFoundException()
        {
            var user = RunAsAdminUser();

            await CreateVermittlerAsync();

            var command = new SoftDeleteDokumentFürVermittlerCommand
            {
                VermittlerId = -1,
                DokumentId   = 1
            };

            user.IsAdmin.Should().BeTrue();
            FluentActions.Invoking(async() =>
                                   await SendAsync(command)).Should().Throw <NotFoundException>()
            .WithMessage("Entity Vermittler (-1) was not found.");
        }
        public async Task AsBearbeiter_ShouldSoftDeleteDokumentAndPutDokumentIntoHistory()
        {
            var user = RunAsBearbeiterUser();

            await CreateVermittlerAsync();

            var command = new SoftDeleteDokumentFürVermittlerCommand
            {
                VermittlerId = 1,
                DokumentId   = 1
            };

            var result = await SendAsync(command);

            var vermittler = await FindVermittlerAsync(1);

            user.IsBearbeiter.Should().BeTrue();
            result.Should().Be(Unit.Value);
            vermittler.RegistrierungsDokumente.Count().Should().Be(0);
            vermittler.RegistrierungsDokumenteHistorie.Count().Should().Be(1);
        }