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);
        }
Example #3
0
 public EmailController(EmailOrchestrator emailOrchestrator, IProviderCommitmentsLogger logger)
 {
     _emailOrchestrator = emailOrchestrator;
     _logger            = logger;
 }