public async Task Setup()
        {
            _ukprn          = 228987165;
            _emailAddresses = new List <string>
            {
                "*****@*****.**",
                "*****@*****.**"
            };
            _templateId = Guid.NewGuid().ToString();
            _tokens     = new Dictionary <string, string>();
            _tokens.Add("key1", "value1");
            _tokens.Add("key2", "value2");

            _accountOrchestrator = new Mock <IAccountOrchestrator>();
            _mediator            = new Mock <IMediator>();
            _configuration       = new ProviderApprenticeshipsServiceConfiguration {
                CommitmentNotification = new ProviderNotificationConfiguration()
            };

            _accountOrchestrator
            .Setup(x => x.GetAccountUsers(_ukprn))
            .ReturnsAsync(_emailAddresses.Select(x => new User {
                EmailAddress = x, ReceiveNotifications = false
            }));

            _request = new ProviderEmailRequest
            {
                TemplateId = _templateId,
                Tokens     = _tokens
            };

            _sut = new EmailOrchestrator(_accountOrchestrator.Object, _mediator.Object, Mock.Of <IProviderCommitmentsLogger>());
            await _sut.SendEmailToAllProviderRecipients(_ukprn, _request);
        }
        public async Task ShouldOnlySendNotificationForNormaUser(bool explicitListIsNull)
        {
            _request.ExplicitEmailAddresses = explicitListIsNull ? null : new List <string>();

            _sut = new EmailOrchestrator(_accountOrchestrator.Object, _mediator.Object, Mock.Of <IProviderCommitmentsLogger>());
            await _sut.SendEmailToAllProviderRecipients(_ukprn, _request);

            _mediator.Verify(x => x.Send(It.Is <SendNotificationCommand>(c => c.Email.RecipientsAddress == "*****@*****.**"), It.IsAny <CancellationToken>()), Times.Once);
            _mediator.Verify(x => x.Send(It.Is <SendNotificationCommand>(c => c.Email.RecipientsAddress == "*****@*****.**"), It.IsAny <CancellationToken>()), Times.Never);
        }
Beispiel #3
0
        public async Task <IHttpActionResult> SendEmailToAllProviderRecipients(long ukprn, ProviderEmailRequest request)
        {
            try
            {
                await _emailOrchestrator.SendEmailToAllProviderRecipients(ukprn, request);

                _logger.Info($"Email template '{request?.TemplateId}' sent to Provider recipients successfully", ukprn);
                return(Ok());
            }
            catch (Exception e)
            {
                _logger.Error(e, $"Error sending email template '{request?.TemplateId}' to Provider recipients", ukprn);
                throw;
            }
        }