public void AsAnonymous_ShouldReturnUnauthorizedAccessException()
        {
            var command = new CreateGesellschaftCommand()
            {
                Name = "Test"
            };

            FluentActions.Invoking(async() =>
                                   await SendAsync(command)).Should().Throw <UnauthorizedAccessException>();
        }
        public void AsAdmin_ShouldReturnValidationException()
        {
            RunAsAdminUser();

            var command = new CreateGesellschaftCommand()
            {
                Name = null
            };

            FluentActions.Invoking(async() =>
                                   await SendAsync(command)).Should().Throw <ValidationException>();
        }
 public async Task <ActionResult <int> > CreateGesellschafft([FromBody] CreateGesellschaftCommand command)
 {
     try
     {
         return(Ok(await Mediator.Send(command)));
     }
     catch (UnauthorizedAccessException)
     {
         return(StatusCode(StatusCodes.Status401Unauthorized));
     }
     catch (BadRequestException ex)
     {
         return(BadRequest(ex));
     }
 }
        public async Task AsAdmin_ShouldCreateGesellschaftAndReturnInt()
        {
            var user = RunAsAdminUser();

            var command = new CreateGesellschaftCommand()
            {
                Name = "Test"
            };

            var result = await SendAsync(command);

            var gesellschaft = await FindAsync <Gesellschaft>(result);

            user.IsAdmin.Should().BeTrue();
            gesellschaft.Name.Should().Be("Test");
            gesellschaft.VermittlerGesellschafften.Count.Should().Be(0);
        }
        public async Task AsAdmin_ShouldReturnBadRequestException()
        {
            RunAsAdminUser();

            await AddAsync(new Gesellschaft()
            {
                Name = "Test1"
            });

            var command = new CreateGesellschaftCommand()
            {
                Name = "Test1"
            };

            FluentActions.Invoking(async() =>
                                   await SendAsync(command)).Should().Throw <BadRequestException>();
        }