예제 #1
0
        public When_Employer_Aupa_Blank_Email_Function_Queue_Trigger_Fires()
        {
            var configuration = new MatchingConfiguration
            {
                SendEmailEnabled = true,
                MatchingServiceSupportEmailAddress = SupportEmailAddress
            };

            _emailService          = Substitute.For <IEmailService>();
            _functionLogRepository = Substitute.For <IRepository <FunctionLog> >();

            var employerAupaBlankEmail = new SendEmployerAupaBlankEmail
            {
                CrmId = _employerCrmId,
                Name  = EmployerName,
                Owner = EmployerOwner
            };

            var employerAupaBlankEmailFunctions = new Functions.EmployerAupaBlankEmail(configuration, _emailService, _functionLogRepository);

            employerAupaBlankEmailFunctions.SendEmployerAupaBlankEmailAsync(
                employerAupaBlankEmail,
                new ExecutionContext(),
                new NullLogger <Functions.EmployerAupaBlankEmail>()
                ).GetAwaiter().GetResult();
        }
        public async Task SendEmployerAupaBlankEmailAsync([QueueTrigger(QueueName.EmployerAupaBlankEmailQueue, Connection = "BlobStorageConnectionString")] SendEmployerAupaBlankEmail employerAupaBlankEmail,
                                                          ExecutionContext context,
                                                          ILogger logger)
        {
            if (!_matchingConfiguration.SendEmailEnabled)
            {
                return;
            }

            var stopwatch = Stopwatch.StartNew();

            var crmId = employerAupaBlankEmail.CrmId;

            try
            {
                var tokens = new Dictionary <string, string>
                {
                    { "employer_business_name", employerAupaBlankEmail.Name },
                    { "employer_owner", employerAupaBlankEmail.Owner },
                    { "crm_id", crmId.ToString() }
                };

                var matchingServiceSupportEmailAddress = _matchingConfiguration.MatchingServiceSupportEmailAddress;

                await _emailService.SendEmailAsync(EmailTemplateName.EmployerAupaBlank.ToString(), matchingServiceSupportEmailAddress, null, null, tokens, "System");
            }
            catch (Exception e)
            {
                var errorMessage = $"Error sending employer Aupa email for crm id, {crmId}. Internal Error Message {e}";

                logger.LogError(errorMessage);

                await _functionLogRepository.CreateAsync(new FunctionLog
                {
                    ErrorMessage = errorMessage,
                    FunctionName = context.FunctionName,
                    RowNumber    = -1
                });
            }

            stopwatch.Stop();

            logger.LogInformation($"Function {context.FunctionName} sent emails\n" +
                                  $"\tTime taken: {stopwatch.ElapsedMilliseconds: #,###}ms");
        }
 public async Task PushEmployerAupaBlankEmailMessageAsync(SendEmployerAupaBlankEmail employerAupaBlankEmail)
 {
     await PushMessageAsync(
         JsonConvert.SerializeObject(employerAupaBlankEmail),
         QueueName.EmployerAupaBlankEmailQueue);
 }