public async Task HandleAsync_WithNonInternalAccess_ThrowsSecurityException(AuthorizationBuilder.UserType userType)
        {
            IWeeeAuthorization            authorization = AuthorizationBuilder.CreateFromUserType(userType);
            UserManager <ApplicationUser> userManager   = A.Fake <UserManager <ApplicationUser> >();

            CreateOrganisationAdminHandler handler = new CreateOrganisationAdminHandler(authorization, this.dataAccess, this.context);

            Func <Task> action = async() => await handler.HandleAsync(A.Dummy <CreateOrganisationAdmin>());

            await Assert.ThrowsAsync <SecurityException>(action);
        }
        public async Task HandleAsync_WithNonInternalAdminRole_ThrowsSecurityException()
        {
            IWeeeAuthorization authorization = new AuthorizationBuilder()
                                               .AllowInternalAreaAccess()
                                               .DenyRole(Roles.InternalAdmin)
                                               .Build();

            UserManager <ApplicationUser> userManager = A.Fake <UserManager <ApplicationUser> >();

            CreateOrganisationAdminHandler handler = new CreateOrganisationAdminHandler(authorization, this.dataAccess, this.context);

            Func <Task> action = async() => await handler.HandleAsync(A.Dummy <CreateOrganisationAdmin>());

            await Assert.ThrowsAsync <SecurityException>(action);
        }
        public async Task HandleAsync_OrganisationTypeNotSet_ThrowsNotImplementedException()
        {
            CreateOrganisationAdmin request = new CreateOrganisationAdmin()
            {
                BusinessName = "Business",
                Address      = A.Dummy <AddressData>()
            };

            Guid organisationId = Guid.NewGuid();

            CreateOrganisationAdminHandler handler = new CreateOrganisationAdminHandler(authorization, this.dataAccess, this.context);

            Func <Task> action = async() => await handler.HandleAsync(request);

            await Assert.ThrowsAsync <NotImplementedException>(action);
        }
        public async Task HandleAsync_Partnership_CreatesOrganisation()
        {
            CreateOrganisationAdmin request = new CreateOrganisationAdmin()
            {
                BusinessName     = "Business",
                Address          = CreateAddress(),
                OrganisationType = Core.Organisations.OrganisationType.Partnership
            };

            Guid organisationId = Guid.NewGuid();

            CreateOrganisationAdminHandler handler = new CreateOrganisationAdminHandler(authorization, this.dataAccess, this.context);

            A.CallTo(() => dataAccess.Add <Organisation>(A <Organisation> .That.Matches(p => p.OrganisationName == request.BusinessName))).Returns(organisationId);

            Guid result = await handler.HandleAsync(request);

            A.CallTo(() => dataAccess.Add <Organisation>(A <Organisation> .That.Matches(p => p.OrganisationName == request.BusinessName))).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => dataAccess.Add <Address>(A <Address> .That.Matches(p => p.Address1 == request.Address.Address1))).MustHaveHappened(Repeated.Exactly.Once);

            result.Should().Be(organisationId);
        }