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

            var organisation         = Organisation.CreateRegisteredCompany("company", "12345678");
            var activeUsersFalse     = new List <OrganisationUser>();
            var competentAuthorities = new List <UKCompetentAuthority>()
            {
                new UKCompetentAuthority(Guid.NewGuid(), "name", "abb", A.Fake <Country>(), "email1", null),
                new UKCompetentAuthority(Guid.NewGuid(), "name", "abb", A.Fake <Country>(), "email2", null)
            };

            A.CallTo(() => dataAccess.FetchCompetentAuthorities()).Returns(competentAuthorities);
            A.CallTo(() => dataAccess.FetchActiveOrganisationUsers(request.OrganisationId)).Returns(activeUsersFalse);
            A.CallTo(() => dataAccess.FetchOrganisation(A <Guid> ._)).Returns(organisation);

            await handler.HandleAsync(request);

            A.CallTo(() => emailService.SendOrganisationUserRequestToEA("email1", organisation.Name, A <string> ._)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => emailService.SendOrganisationUserRequestToEA("email2", organisation.Name, 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);
                }
            }
        }