Пример #1
0
        private async Task SendEmailToTemplateRecipients(EmailTemplateSummary emailTemplateSummary, dynamic personalisationTokens)
        {
            var recipients = emailTemplateSummary.Recipients.Split(';').Select(x => x.Trim());

            foreach (var recipient in recipients)
            {
                await SendEmailViaNotificationsApi(recipient, emailTemplateSummary.TemplateId, emailTemplateSummary.TemplateName, personalisationTokens);
            }
        }
        public void Arrange()
        {
            EpaOrganisation = new EpaOrganisation
            {
                Id             = Guid.NewGuid(),
                OrganisationId = "EPA0001"
            };

            _eMailTemplateSummary = new EmailTemplateSummary
            {
                TemplateName = "EmailTemplate"
            };

            _eMailTemplateQueryRepository = new Mock <IEMailTemplateQueryRepository>();
            _eMailTemplateQueryRepository.Setup(c => c.GetEmailTemplate(It.IsAny <string>()))
            .ReturnsAsync(_eMailTemplateSummary);

            _mediator = new Mock <IMediator>();

            _mediator.Setup(c => c.Send(
                                It.Is <GetAssessmentOrganisationRequest>(p => p.OrganisationId == EpaOrganisation.OrganisationId),
                                It.IsAny <CancellationToken>()))
            .ReturnsAsync(EpaOrganisation);

            _firstLiveContact = new ContactIncludePrivilegesResponse()
            {
                Contact = new ContactResponse
                {
                    Email       = "*****@*****.**",
                    DisplayName = "First Live Person",
                    Status      = ContactStatus.Live
                }
            };
            _firstLiveContact.Privileges.Add(new PrivilegeResponse
            {
                Key = ChangeOrganisationDetailsContactsPrivilege.Privilege.Key
            });

            _secondLiveContact = new ContactIncludePrivilegesResponse()
            {
                Contact = new ContactResponse
                {
                    Email       = "*****@*****.**",
                    DisplayName = "Second Live Person",
                    GivenNames  = "Second Live",
                    Status      = ContactStatus.Live
                }
            };
            _secondLiveContact.Privileges.Add(new PrivilegeResponse
            {
                Key = ChangeOrganisationDetailsContactsPrivilege.Privilege.Key
            });
            _secondLiveContact.Privileges.Add(new PrivilegeResponse
            {
                Key = ManageUsersContactsPrivilege.Privilege.Key
            });

            _thirdLiveContact = new ContactIncludePrivilegesResponse()
            {
                Contact = new ContactResponse
                {
                    Email       = "thirdliveorganisation.com",
                    DisplayName = "Third Live Person",
                    GivenNames  = "Third Live",
                    Status      = ContactStatus.Live
                }
            };
            _thirdLiveContact.Privileges.Add(new PrivilegeResponse
            {
                Key = ManageUsersContactsPrivilege.Privilege.Key
            });

            _firstPendingContact = new ContactIncludePrivilegesResponse()
            {
                Contact = new ContactResponse
                {
                    Email       = "*****@*****.**",
                    DisplayName = "First Pending Person",
                    GivenNames  = "First Pending",
                    Status      = ContactStatus.InvitePending
                }
            };
            _firstPendingContact.Privileges.Add(new PrivilegeResponse
            {
                Key = ManageUsersContactsPrivilege.Privilege.Key
            });

            _mediator.Setup(c => c.Send(
                                It.IsAny <GetAllContactsIncludePrivilegesRequest>(),
                                It.IsAny <CancellationToken>())
                            )
            .ReturnsAsync(new List <ContactIncludePrivilegesResponse>
            {
                _firstLiveContact,
                _secondLiveContact,
                _thirdLiveContact,
                _firstPendingContact
            });

            EditorCommon = _thirdLiveContact.Contact.DisplayName;

            _logger = new Mock <ILogger <SendOrganisationDetailsAmendedEmailHandler> >();

            // this callback is being used to capture the send email requests which are later
            // compared; this is done like this due to the anonymous object for Tokens
            // which cannot be verified in the normal style - NOTE: also the
            // Returns(Task.CompletedTask) which is necessary for a null returning async
            // Mock which is handled by a callback to avoid a NullReferenceException
            // during testing
            _emailRequestsSent = new List <string>();
            _mediator
            .Setup(c =>
                   c.Send(
                       It.IsAny <SendEmailRequest>(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(new Unit())
            .Callback <IRequest, CancellationToken>((request, token) =>
            {
                var sendEmailRequest = request as SendEmailRequest;
                _emailRequestsSent.Add(JsonConvert.SerializeObject(new
                {
                    sendEmailRequest.Email,
                    EmailTemplate = sendEmailRequest.EmailTemplateSummary.TemplateName,
                    sendEmailRequest.Tokens
                }));
            });

            _sut = new SendOrganisationDetailsAmendedEmailHandler(
                _eMailTemplateQueryRepository.Object, _mediator.Object, _logger.Object);
        }
 public SendEmailRequest(string email, EmailTemplateSummary emailTemplateSummary, dynamic tokens)
 {
     EmailTemplateSummary = emailTemplateSummary;
     Email  = email;
     Tokens = tokens;
 }