public async Task ShouldReturnUnauthorizedAccessException()
        {
            RegisterOrUpdateVermittlerCommand command = await Create_RegisterOrUpdateVermittlerCommandAsync(null);

            FluentActions.Invoking(async() =>
                                   await SendAsync(command)).Should().Throw <UnauthorizedAccessException>();
        }
        public async Task AsVermittler_ShouldAddVermittlerToDbAndGenerateAutomaticValues()
        {
            RunAsNewVermittler();

            var einladecode = await CreateEinladenderVermittlerAsync();

            await CreateGesellschaften();

            RegisterOrUpdateVermittlerCommand command =
                await Create_RegisterOrUpdateVermittlerCommandAsync(einladecode.Code);

            var result = await SendAsync(command);

            var vermittler = await FindVermittlerAsync(result);

            vermittler.User.Adresse.Land.Id.Should().Be(1);
            vermittler.AbschlussProvisionssatz.Should().Be(60.0f);
            vermittler.BestandsProvisionssatz.Should().Be(60.0f);
            vermittler.VermittlerRegistrierungsstatus.Should().Be(VermittlerRegistrierungsstatus.NeuerVermittler);
            vermittler.EinladecodeVermittler.Should().NotBeNull().And.NotBe("");
            vermittler.EinladecodeVermittler.VermittlerId.Should().Be(vermittler.Id);
            vermittler.EingeladenVonVermittlerEinladecodeId.Should().Be(5);
            vermittler.VermittlerGesellschafften.Count.Should().Be(2);

            foreach (var vermittlerGesellschafft in vermittler.VermittlerGesellschafften)
            {
                vermittlerGesellschafft.VermittlerId.Should().Be(vermittler.Id);
            }
        }
        public void ShouldThrowValidationException()
        {
            RegisterOrUpdateVermittlerCommand command =
                new RegisterOrUpdateVermittlerCommand();

            Func <Task> act = async() => { await SendAsync(command); };

            act.Should().Throw <ValidationException>()
            .Which.Errors.Count().Should().Be(25);
        }
        public async Task AsVermittler_UnexistingLand_ReturnNotFoundException()
        {
            RunAsVermittlerUser();

            RegisterOrUpdateVermittlerCommand command =
                await Create_RegisterOrUpdateVermittlerCommandAsync(null);

            command.StaatsangehörigkeitId = -1;

            FluentActions.Invoking(async() =>
                                   await SendAsync(command)).Should().Throw <NotFoundException>()
            .WithMessage("Entity Land (-1) was not found.");
        }
        public async Task AsVermittler_NotIntAesMessage_ShouldReturnVermittlerWithEinnladecodeNull()
        {
            RunAsNewVermittler();

            RegisterOrUpdateVermittlerCommand command =
                await Create_RegisterOrUpdateVermittlerCommandAsync("yGeknLRHbugIBwracz5cgg==");

            var result = await SendAsync(command);

            var vermittler = await FindVermittlerAsync(result);

            vermittler.EingeladenVonVermittlerEinladecodeId.Should().BeNull();
        }
        public async Task AsVermittler_VermittlerInEinladecodeNotExists_ShouldReturnVermittlerWithEinladecodeNull()
        {
            RunAsNewVermittler();

            RegisterOrUpdateVermittlerCommand command =
                await Create_RegisterOrUpdateVermittlerCommandAsync("Pvm8SyluQacisQ28HIDr4Q==");

            var result = await SendAsync(command);

            var vermittler = await FindVermittlerAsync(result);

            vermittler.EingeladenVonVermittlerEinladecodeId.Should().BeNull();
            vermittler.EingeladenVon.Should().BeNull();
        }
        public async Task AsVermittler_WithoutEinladecode_ShouldAddVermittlerToDbAndGenerateAutomaticValues()
        {
            RunAsNewVermittler();

            RegisterOrUpdateVermittlerCommand command =
                await Create_RegisterOrUpdateVermittlerCommandAsync("null");

            var result = await SendAsync(command);

            var vermittler = await FindVermittlerAsync(result);

            vermittler.User.Adresse.Land.Id.Should().Be(1);
            vermittler.AbschlussProvisionssatz.Should().Be(60.0f);
            vermittler.BestandsProvisionssatz.Should().Be(60.0f);
            vermittler.VermittlerRegistrierungsstatus.Should().Be(VermittlerRegistrierungsstatus.NeuerVermittler);
            vermittler.EinladecodeVermittler.Should().NotBeNull().And.NotBe("");
            vermittler.EinladecodeVermittler.VermittlerId.Should().Be(vermittler.Id);
            vermittler.EingeladenVonVermittlerEinladecodeId.Should().BeNull();
        }
 public async Task <ActionResult <int> > RegisterOrUpdateVermittler(
     [FromBody] RegisterOrUpdateVermittlerCommand command)
 {
     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 AsVermittler_EinladeCodeDoesNotPartseTo_ShouldUpdateVermittlerData()
        {
            await CreateVermittlerAsync();

            var vermittler = await FindVermittlerAsync(2);

            RunAsPassedInVermittler(vermittler);

            RegisterOrUpdateVermittlerCommand command =
                await Create_RegisterOrUpdateVermittlerCommandAsync(null);

            var vermittlerIdAfterUpdate = await SendAsync(command);

            var vermittlerAfterUpdate = await FindVermittlerAsync(vermittlerIdAfterUpdate);

            vermittler.Id.Should().Be(vermittlerIdAfterUpdate);
            vermittler.User.Nachname.Should().NotBeSameAs(vermittlerAfterUpdate.User.Nachname);
            vermittler.User.Vorname.Should().NotBeSameAs(vermittlerAfterUpdate.User.Vorname);
            vermittler.IhkRegistrierungsnummer.Should().NotBeSameAs(vermittlerAfterUpdate.IhkRegistrierungsnummer);
            vermittlerAfterUpdate.EingeladenVonVermittlerEinladecodeId.Should().BeNull();
        }
        public async Task AsVermittler_VermittlerUpdateWithEinladeCode_ShouldUpdateVermittlerData()
        {
            var einladecodeVermittler = await CreateEinladenderVermittlerAsync();

            await CreateVermittlerAsync();

            var vermittler = await FindVermittlerAsync(1);

            RunAsPassedInVermittler(vermittler);

            RegisterOrUpdateVermittlerCommand command =
                await Create_RegisterOrUpdateVermittlerCommandAsync(einladecodeVermittler.Code);

            var vermittlerIdAfterUpdate = await SendAsync(command);

            var vermittlerAfterUpdate = await FindVermittlerAsync(vermittlerIdAfterUpdate);

            vermittler.Id.Should().Be(vermittlerIdAfterUpdate);
            vermittler.User.Nachname.Should().NotBeSameAs(vermittlerAfterUpdate.User.Nachname);
            vermittler.User.Vorname.Should().NotBeSameAs(vermittlerAfterUpdate.User.Vorname);
            vermittler.IhkRegistrierungsnummer.Should().NotBeSameAs(vermittlerAfterUpdate.IhkRegistrierungsnummer);
            vermittlerAfterUpdate.EingeladenVonVermittlerEinladecodeId.Should().Be(5);
        }