Exemple #1
0
        public async Task HandleAsync_GivenActiveUsers_SendOrganisationRequestToAdministrator()
        {
            var request = new OrganisationUserRequestEvent(Guid.NewGuid(), Guid.NewGuid());

            var activeUsersTrue = new List <OrganisationUser>()
            {
                A.Fake <OrganisationUser>()
            };

            A.CallTo(() => dataAccess.FetchActiveOrganisationUsers(request.OrganisationId)).Returns(activeUsersTrue);

            await handler.HandleAsync(request);

            A.CallTo(() => emailService.SendOrganisationUserRequest(A <string> ._, A <string> ._, A <string> ._)).MustHaveHappened(Repeated.Exactly.Once);
        }
        public async Task HandleAsync(OrganisationUserRequestEvent @event)
        {
            IEnumerable <OrganisationUser> activeOrganisationUsers = await dataAccess.FetchActiveOrganisationUsers(@event.OrganisationId);

            var activeUsers = false;
            var sender      = await dataAccess.FetchUser(@event.UserId.ToString());

            foreach (OrganisationUser activeOrganisationUser in activeOrganisationUsers)
            {
                activeUsers = true;
                await emailService.SendOrganisationUserRequest(activeOrganisationUser.User.Email, activeOrganisationUser.Organisation.OrganisationName, sender.FullName);
            }

            if (!activeUsers)
            {
                var organisation = await dataAccess.FetchOrganisation(@event.OrganisationId);

                foreach (var ukCompetentAuthority in await dataAccess.FetchCompetentAuthorities())
                {
                    await emailService.SendOrganisationUserRequestToEA(ukCompetentAuthority.Email, organisation.OrganisationName, sender.FullName);
                }
            }
        }