Exemple #1
0
        public void SendGeoFirstTimeDataSubmissionEmail(string year, string organisationName, string postedDate, string url)
        {
            foreach (string emailAddress in Global.GeoDistributionList)
            {
                // This personalisation Dictionary should be created separately for each recipient (i.e. inside the foreach loop)
                // This ensures each recipient gets a separate instance of the Dictionary
                // This allows each Dictionary to be modified independently without affecting each other
                // Passing in the same Dictionary caused bug GPG-570
                var personalisation = new Dictionary <string, dynamic>
                {
                    { "year", year },
                    { "organisationName", organisationName },
                    { "postedDate", postedDate },
                    { "url", url },
                };

                var notifyEmail = new NotifyEmail
                {
                    EmailAddress    = emailAddress,
                    TemplateId      = EmailTemplates.SendGeoFirstTimeDataSubmissionEmail,
                    Personalisation = personalisation
                };

                AddEmailToQueue(notifyEmail);
            }
        }
        public void POST_Verification_Email_Is_Sent_After_Creating_User_Account()
        {
            // Arrange
            var requestFormValues = new Dictionary <string, StringValues>();

            requestFormValues.Add("GovUk_Text_EmailAddress", "*****@*****.**");
            requestFormValues.Add("GovUk_Text_ConfirmEmailAddress", "*****@*****.**");
            requestFormValues.Add("GovUk_Text_FirstName", "Test");
            requestFormValues.Add("GovUk_Text_LastName", "Example");
            requestFormValues.Add("GovUk_Text_JobTitle", "Tester");
            requestFormValues.Add("GovUk_Text_Password", "Pa55word");
            requestFormValues.Add("GovUk_Text_ConfirmPassword", "Pa55word");
            requestFormValues.Add("GovUk_Checkbox_SendUpdates", "true");
            requestFormValues.Add("GovUk_Checkbox_AllowContact", "false");

            var controllerBuilder = new ControllerBuilder <AccountCreationController>();
            var controller        = controllerBuilder
                                    .WithRequestFormValues(requestFormValues)
                                    .WithMockUriHelper()
                                    .Build();

            // Act
            var response = (ViewResult)controller.CreateUserAccountPost(new CreateUserAccountViewModel());

            // Assert
            Assert.AreEqual("ConfirmEmailAddress", response.ViewName);

            Assert.AreEqual(1, controllerBuilder.EmailsSent.Count);
            NotifyEmail emailSent = controllerBuilder.EmailsSent[0];

            Assert.AreEqual("*****@*****.**", emailSent.EmailAddress);
            Assert.AreEqual(EmailTemplates.AccountVerificationEmail, emailSent.TemplateId);
        }
Exemple #3
0
        public void SendGeoOrganisationRegistrationRequestEmail(string contactName, string reportingOrg, string reportingAddress, string url)
        {
            foreach (string emailAddress in Global.GeoDistributionList)
            {
                // This personalisation Dictionary should be created separately for each recipient (i.e. inside the foreach loop)
                // This ensures each recipient gets a separate instance of the Dictionary
                // This allows each Dictionary to be modified independently without affecting each other
                // Passing in the same Dictionary caused bug GPG-570
                var personalisation = new Dictionary <string, dynamic>
                {
                    { "name", contactName },
                    { "org2", reportingOrg },
                    { "address", reportingAddress },
                    { "url", url },
                };

                var notifyEmail = new NotifyEmail
                {
                    EmailAddress    = emailAddress,
                    TemplateId      = EmailTemplates.SendGeoOrganisationRegistrationRequestEmail,
                    Personalisation = personalisation
                };

                AddEmailToQueue(notifyEmail);
            }
        }
        public void POST_Email_Is_Sent_When_Password_Is_Successfully_Updated()
        {
            // Arrange
            User user = new UserBuilder().WithPassword("password").Build();

            var requestFormValues = new Dictionary <string, StringValues>();

            requestFormValues.Add("GovUk_Text_CurrentPassword", "password");
            requestFormValues.Add("GovUk_Text_NewPassword", "NewPassword1");
            requestFormValues.Add("GovUk_Text_ConfirmNewPassword", "NewPassword1");

            var controllerBuilder = new ControllerBuilder <ChangePasswordController>();
            var controller        = controllerBuilder
                                    .WithLoggedInUser(user)
                                    .WithRequestFormValues(requestFormValues)
                                    .WithDatabaseObjects(user)
                                    .WithMockUriHelper()
                                    .Build();

            // Act
            controller.ChangePasswordPost(new ChangePasswordViewModel());

            // Assert
            // Assert that exactly one email is sent
            Assert.AreEqual(1, controllerBuilder.EmailsSent.Count);

            NotifyEmail userEmail = controllerBuilder.EmailsSent.FirstOrDefault();

            // Assert that the email sent has the correct email address and template
            Assert.NotNull(userEmail);
            Assert.AreEqual(user.EmailAddress, userEmail.EmailAddress);
            Assert.AreEqual(EmailTemplates.SendChangePasswordCompletedEmail, userEmail.TemplateId, $"Expected the correct templateId to be in the email send queue, expected {EmailTemplates.SendChangePasswordCompletedEmail}");
        }
Exemple #5
0
        public void SendReminderEmail(
            string emailAddress,
            string deadlineDate,
            int daysUntilDeadline,
            string organisationNames,
            bool organisationIsSingular,
            bool organisationIsPlural,
            string sectorType)
        {
            var personalisation = new Dictionary <string, dynamic>
            {
                { "DeadlineDate", deadlineDate },
                { "DaysUntilDeadline", daysUntilDeadline },
                { "OrganisationNames", organisationNames },
                { "OrganisationIsSingular", organisationIsSingular },
                { "OrganisationIsPlural", organisationIsPlural },
                { "SectorType", sectorType },
            };

            var notifyEmail = new NotifyEmail
            {
                EmailAddress    = emailAddress,
                TemplateId      = EmailTemplates.ReminderEmail,
                Personalisation = personalisation
            };

            SendEmailDirectly(notifyEmail);
        }
Exemple #6
0
        private void SendEmail(NotifyEmail notifyEmail)
        {
            if (!Config.IsProduction())
            {
                notifyEmail.EmailAddress = Global.TestEnvironmentEmailRecipient;
            }

            govNotifyApi.SendEmail(notifyEmail);
        }
Exemple #7
0
        private static void AddEnvironmentDetailsToEmail(NotifyEmail notifyEmail)
        {
            if (notifyEmail.Personalisation == null)
            {
                notifyEmail.Personalisation = new Dictionary <string, dynamic>();
            }

            notifyEmail.Personalisation.Add("Environment", GetEnvironmentNameAndRecipientEmailAddressForTestEnvironments(notifyEmail));
        }
Exemple #8
0
        public void SendChangeEmailCompletedNotificationEmail(string emailAddress)
        {
            var notifyEmail = new NotifyEmail
            {
                EmailAddress = emailAddress,
                TemplateId   = EmailTemplates.SendChangeEmailCompletedNotificationEmail,
            };

            AddEmailToQueue(notifyEmail);
        }
Exemple #9
0
        public void SendCloseAccountCompletedEmail(string emailAddress)
        {
            var notifyEmail = new NotifyEmail
            {
                EmailAddress = emailAddress,
                TemplateId   = EmailTemplates.SendCloseAccountCompletedEmail,
            };

            AddEmailToQueue(notifyEmail);
        }
Exemple #10
0
        public void SendResetPasswordCompletedEmail(string emailAddress)
        {
            var notifyEmail = new NotifyEmail
            {
                EmailAddress = emailAddress,
                TemplateId   = EmailTemplates.SendResetPasswordCompletedEmail,
            };

            AddEmailToQueue(notifyEmail);
        }
Exemple #11
0
        public void POST_Closing_Account_Removes_User_From_Organisations_And_Emails_GEO_For_Orphans()
        {
            // Arrange
            Organisation organisation1 = new OrganisationBuilder().WithOrganisationId(1).Build();
            Organisation organisation2 = new OrganisationBuilder().WithOrganisationId(2).Build();

            User standardUser = new UserBuilder()
                                .WithUserId(1)
                                .WithOrganisation(organisation1)
                                .Build();

            User userToDelete = new UserBuilder()
                                .WithUserId(2)
                                .WithPassword("password")
                                .WithOrganisation(organisation1)
                                .WithOrganisation(organisation2)
                                .Build();

            var requestFormValues = new Dictionary <string, StringValues>();

            requestFormValues.Add("GovUk_Text_Password", "password");

            var controllerBuilder = new ControllerBuilder <WebUI.Controllers.Account.CloseAccountController>();
            var controller        = controllerBuilder
                                    .WithLoggedInUser(userToDelete)
                                    .WithRequestFormValues(requestFormValues)
                                    .WithDatabaseObjects(organisation1, organisation2, standardUser, userToDelete)
                                    .Build();

            // Act
            controller.CloseAccountPost(new CloseAccountViewModel());

            // Assert
            // Assert that organisation1 doesn't have userToDelete associated with it, but is not an orphan
            Assert.IsEmpty(organisation1.UserOrganisations.Where(uo => uo.User.Equals(userToDelete)));
            Assert.IsFalse(organisation1.GetIsOrphan());

            // Assert that organisation2 is now an orphan
            Assert.IsTrue(organisation2.GetIsOrphan());

            // Assert that there are two emails: 1 'Close Account' email to the user, 1 'Orphan Organisation' email to GEO
            Assert.AreEqual(2, controllerBuilder.EmailsSent.Count);

            NotifyEmail userEmail = controllerBuilder.EmailsSent.SingleOrDefault(ne => ne.EmailAddress == userToDelete.EmailAddress);

            Assert.NotNull(userEmail);
            Assert.AreEqual(EmailTemplates.SendCloseAccountCompletedEmail, userEmail.TemplateId, $"Expected the correct templateId to be in the email send queue, expected {EmailTemplates.SendCloseAccountCompletedEmail}");

            NotifyEmail geoEmail = controllerBuilder.EmailsSent.SingleOrDefault(ne => ne.EmailAddress == Global.GeoDistributionList[0]);

            Assert.NotNull(geoEmail);
            Assert.AreEqual(EmailTemplates.SendGeoOrphanOrganisationEmail, geoEmail.TemplateId, $"Expected the correct templateId to be in the email send queue, expected {EmailTemplates.SendGeoOrphanOrganisationEmail}");
        }
 private void SendNotifyEmailAction(NotifyEmail notifyEmail)
 {
     try
     {
         emailSendingService.SendEmailFromQueue(notifyEmail);
     }
     catch (Exception ex)
     {
         CustomLogger.Error(
             "EMAIL FAILURE: Notify email failed to send queued email",
             new { NotifyEmail = notifyEmail, Error = ex });
         throw;
     }
 }
Exemple #13
0
        public void SendScopeChangeOutEmail(string emailAddress, string organisationName)
        {
            var personalisation = new Dictionary <string, dynamic>
            {
                { "OrganisationName", organisationName },
            };

            var notifyEmail = new NotifyEmail
            {
                EmailAddress = emailAddress, TemplateId = EmailTemplates.ScopeChangeOutEmail, Personalisation = personalisation
            };

            AddEmailToQueue(notifyEmail);
        }
Exemple #14
0
        private void AddEmailToQueue(NotifyEmail notifyEmail)
        {
            AddEnvironmentDetailsToEmail(notifyEmail);

            try
            {
                backgroundJobsApi.AddEmailToQueue(notifyEmail);

                CustomLogger.Information("Successfully queued Notify email", new { notifyEmail });
            }
            catch (Exception ex)
            {
                CustomLogger.Error("Failed to queue Notify email", new { Exception = ex });
            }
        }
Exemple #15
0
        public void SendUserAddedToOrganisationEmail(string emailAddress, string organisationName, string username)
        {
            var personalisation = new Dictionary <string, dynamic>
            {
                { "OrganisationName", organisationName },
                { "Username", username },
            };

            var notifyEmail = new NotifyEmail
            {
                EmailAddress = emailAddress, TemplateId = EmailTemplates.UserAddedToOrganisationEmail, Personalisation = personalisation
            };

            AddEmailToQueue(notifyEmail);
        }
Exemple #16
0
        public void SendResetPasswordVerificationEmail(string emailAddress, string url)
        {
            var personalisation = new Dictionary <string, dynamic>
            {
                { "url", url },
            };

            var notifyEmail = new NotifyEmail
            {
                EmailAddress    = emailAddress,
                TemplateId      = EmailTemplates.SendResetPasswordVerificationEmail,
                Personalisation = personalisation
            };

            AddEmailToQueue(notifyEmail);
        }
Exemple #17
0
        public void SendOrganisationRegistrationApprovedEmail(string emailAddress, string url)
        {
            var personalisation = new Dictionary <string, dynamic>
            {
                { "url", url },
            };

            var notifyEmail = new NotifyEmail
            {
                EmailAddress    = emailAddress,
                TemplateId      = EmailTemplates.SendOrganisationRegistrationApprovedEmail,
                Personalisation = personalisation
            };

            AddEmailToQueue(notifyEmail);
        }
Exemple #18
0
        public void SendOrganisationRegistrationDeclinedEmail(string emailAddress, string reason)
        {
            var personalisation = new Dictionary <string, dynamic>
            {
                { "reason", reason },
            };

            var notifyEmail = new NotifyEmail
            {
                EmailAddress    = emailAddress,
                TemplateId      = EmailTemplates.SendOrganisationRegistrationDeclinedEmail,
                Personalisation = personalisation
            };

            AddEmailToQueue(notifyEmail);
        }
Exemple #19
0
        public async Task SendToEmailQueueAsync(NotifyEmail message)
        {
            // to access hosting environment i have to bring in all that IHostingEnvironment crap form ASP.NET,
            // just sticking to config library! --
            bool isDev     = _configuration["ASPNETCORE_ENVIRONMENT"] == "Development";
            bool isStg     = _configuration["ASPNETCORE_ENVIRONMENT"] == "Staging";
            bool isSandbox = _configuration["ASPNETCORE_ENVIRONMENT"] == "Sandbox";

            if (isDev) // testing
            {
                message.To      = "*****@*****.**";
                message.Subject = message.Subject + " [test]";
                if (!string.IsNullOrWhiteSpace(message.Cc))
                {
                    message.Cc = "*****@*****.**";
                }
                if (!string.IsNullOrWhiteSpace(message.Bcc))
                {
                    message.Bcc = "*****@*****.**";
                }
            }

            if (isStg) // staging
            {
                message.To      = "*****@*****.**";
                message.Subject = message.Subject + " [test-stg]";
                if (!string.IsNullOrWhiteSpace(message.Cc))
                {
                    message.Cc = "*****@*****.**";
                }
                if (!string.IsNullOrWhiteSpace(message.Bcc))
                {
                    message.Bcc = "*****@*****.**";
                }
            }

            if (isSandbox) // sandbox
            {
                message.Subject = message.Subject + " [sandbox]";
            }

            CloudQueue queue = await GetQueue("notify-email");

            var msg = new CloudQueueMessage(JsonConvert.SerializeObject(message));
            await queue.AddMessageAsync(msg);
        }
Exemple #20
0
        public void SendAccountVerificationEmail(string emailAddress, string verificationUrl)
        {
            var personalisation = new Dictionary <string, dynamic>
            {
                { "TimeWithUnits", "7 days" },
                { "VerificationUrl", verificationUrl },
            };

            var notifyEmail = new NotifyEmail
            {
                EmailAddress    = emailAddress,
                TemplateId      = EmailTemplates.AccountVerificationEmail,
                Personalisation = personalisation
            };

            AddEmailToQueue(notifyEmail);
        }
Exemple #21
0
        public void SendRemovedUserFromOrganisationEmail(string emailAddress, string organisationName, string removedUserName)
        {
            var personalisation = new Dictionary <string, dynamic>
            {
                { "OrganisationName", organisationName },
                { "RemovedUser", removedUserName },
            };

            var notifyEmail = new NotifyEmail
            {
                EmailAddress    = emailAddress,
                TemplateId      = EmailTemplates.RemovedUserFromOrganisationEmail,
                Personalisation = personalisation
            };

            AddEmailToQueue(notifyEmail);
        }
Exemple #22
0
        public void SendAccountRetirementNotificationEmail(string emailAddress, string userFullName, string daysRemaining)
        {
            var personalisation = new Dictionary <string, dynamic>
            {
                { "UserFullName", userFullName },
                { "EmailAddress", emailAddress }, // We do need to send the email address in the personalisation - because it appears in the body of the email
                { "DaysRemaining", daysRemaining },
            };

            var notifyEmail = new NotifyEmail
            {
                EmailAddress    = emailAddress,
                TemplateId      = EmailTemplates.SendAccountRetirementNotificationEmail,
                Personalisation = personalisation
            };

            AddEmailToQueue(notifyEmail);
        }
Exemple #23
0
        public static Task ResetPasswordAsync(this IEmailQueueSender emailSender, ApplicationUser user, string callbackUrl)
        {
            var msgIn = new NotifyEmail
            {
                Name      = $"{user.FirstName} {user.LastName}",
                To        = user.Email,
                Subject   = "password reset",
                Message   = null,
                Template  = "password-reset",
                FieldDict = new Dictionary <string, string>
                {
                    { "firstName", user.FirstName },
                    { "lastName", user.LastName },
                    { "resetLink", callbackUrl },
                },
            };

            return(emailSender.SendToEmailQueueAsync(msgIn));
        }
Exemple #24
0
        public static Task EmailConfirmationAsync(this IEmailQueueSender emailSender, ApplicationUser user, string link)
        {
            var msgIn = new NotifyEmail
            {
                Name      = $"{user.FirstName} {user.LastName}",
                To        = user.Email,
                Subject   = "email verification",
                Message   = null,
                Template  = "email-verification",
                FieldDict = new Dictionary <string, string>
                {
                    { "firstName", user.FirstName },
                    { "lastName", user.LastName },
                    { "confirmLink", link },
                },
            };

            return(emailSender.SendToEmailQueueAsync(msgIn));
        }
        public Response RunBusinessRuleEngine(PaymentType type)
        {
            switch (type)
            {
            case PaymentType.PHYSICAL_PRODUCT:
            {
                var createCommissionPayment = new ProcessCommissionPayment();
                var packingSlip             = new PhysicalProductPackingSlip(createCommissionPayment);
                return(packingSlip.Process());
            }

            case PaymentType.BOOK:
            {
                var createCommissionPayment = new ProcessCommissionPayment();
                var GeneratePackingSlipForRoyaltyDepartment = new CreateDuplicateSlipForRoyaldepartment(createCommissionPayment);
                return(GeneratePackingSlipForRoyaltyDepartment.Process());
            }

            case PaymentType.MEMBERSHIP_ACTIVATE:
            {
                var sendEmailNotifification = new NotifyEmail();
                var activateMemberShip      = new ActivateMemeberShip(sendEmailNotifification);
                return(activateMemberShip.Process());
            }

            case PaymentType.MEMBERSHIP_UPGRADE:
            {
                var sendEmailNotifification = new NotifyEmail();
                var applyUpgrade            = new UpgradeMembership(sendEmailNotifification);
                return(applyUpgrade.Process());
            }

            case PaymentType.VIDEO:
            {
                var addFirstAidVideo = new AddFirstAidVideo();
                var packingSlip      = new PhysicalProductPackingSlip(addFirstAidVideo);
                return(packingSlip.Process());
            }

            default:
                return(new Response((int)Status.FAIL, "payment type is not found"));
            }
        }
Exemple #26
0
        public async Task Process(NotifyEmail msg)
        {
            string body = msg.Message;

            if (!string.IsNullOrWhiteSpace(msg.Template))
            {
                var path = Path.Combine("EmailTemplates", $"{msg.Template}.html");

                string template = File.ReadAllText(path);

                // extract all fields from templates
                var fields = ExtractFieilds(template);

                // fill out from a dictionary --
                body = InserValues(template, fields, msg.FieldDict);

                //await _log.WriteAsync(body);
            }

            await _mailer.SendEmailAsync(msg.To, msg.Name, msg.Subject, body, msg.Cc);
        }
Exemple #27
0
        public void SendSuccessfulSubmissionEmail(string emailAddress,
                                                  string organisationName,
                                                  string submittedOrUpdated,
                                                  string reportingPeriod,
                                                  string reportLink)
        {
            var personalisation = new Dictionary <string, dynamic>
            {
                { "OrganisationName", organisationName },
                { "SubmittedOrUpdated", submittedOrUpdated },
                { "ReportingPeriod", reportingPeriod },
                { "ReportLink", reportLink },
            };

            var notifyEmail = new NotifyEmail
            {
                EmailAddress    = emailAddress,
                TemplateId      = EmailTemplates.SendSuccessfulSubmissionEmail,
                Personalisation = personalisation
            };

            AddEmailToQueue(notifyEmail);
        }
 public void SendNotifyEmail(NotifyEmail notifyEmail)
 {
     JobHelpers.RunAndLogJob(() => SendNotifyEmailAction(notifyEmail), nameof(SendNotifyEmail), JobErrorsLogged.Manually);
 }
Exemple #29
0
 public EmailNotificationResponse SendEmail(NotifyEmail notifyEmail)
 {
     return(new EmailNotificationResponse {
         id = "MOCK_RESPONSE_ID"
     });
 }
 public void AddEmailToQueue(NotifyEmail notifyEmail)
 {
     BackgroundJob.Enqueue <SendNotifyEmailJob>(
         j => j.SendNotifyEmail(notifyEmail));
 }