Пример #1
0
        public void TestMultipleRecipientsLoggedIn()
        {
            var employer = CreateEmployer();
            var jobAd    = _jobAdsCommand.PostTestJobAd(employer);

            var member = CreateMember();

            LogIn(member);

            var model = new EmailJobAdsModel
            {
                Tos = new[]
                {
                    new EmailToModel {
                        ToName = ToName, ToEmailAddress = ToEmailAddress
                    },
                    new EmailToModel {
                        ToName = ToName2, ToEmailAddress = ToEmailAddress2
                    }
                },
                JobAdIds = new List <Guid> {
                    jobAd.Id
                },
            };

            AssertJsonSuccess(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(null), JsonContentType, Serialize(model))));

            var emails = _emailServer.AssertEmailsSent(2);

            emails[0].AssertAddresses(new EmailRecipient(member.EmailAddresses[0].Address, member.FullName), Return, new EmailRecipient(ToEmailAddress, ToName));
            emails[1].AssertAddresses(new EmailRecipient(member.EmailAddresses[0].Address, member.FullName), Return, new EmailRecipient(ToEmailAddress2, ToName2));
        }
Пример #2
0
        public void TestSendEmail()
        {
            var employer = CreateEmployer();
            var jobAd    = _jobAdsCommand.PostTestJobAd(employer);

            // Get the page.

            Get(GetEmailUrl(jobAd.Id));
            AssertJobAdEmail();

            // Send the email (simulating the JavaScript).

            var model = new EmailJobAdsModel
            {
                FromName         = FromName,
                FromEmailAddress = FromEmailAddress,
                Tos = new[] { new EmailToModel {
                                  ToName = ToName, ToEmailAddress = ToEmailAddress
                              } },
                JobAdIds = new List <Guid> {
                    jobAd.Id
                }
            };

            AssertJsonSuccess(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(null), JsonContentType, Serialize(model))));

            var email = _emailServer.AssertEmailSent();

            email.AssertAddresses(new EmailRecipient(FromEmailAddress, FromName), Return, new EmailRecipient(ToEmailAddress, ToName));

            // Simulate getting the success notification.

            Get(GetEmailSentUrl(jobAd.Id));
            AssertPageContains("job was emailed successfully.");
        }
Пример #3
0
        public void TestFromNameErrors()
        {
            var employer = CreateEmployer();
            var jobAd    = _jobAdsCommand.PostTestJobAd(employer);

            // Not logged in required.

            var model = new EmailJobAdsModel {
                FromEmailAddress = FromEmailAddress, Tos = new[] { new EmailToModel {
                                                                       ToName = ToName, ToEmailAddress = ToEmailAddress
                                                                   } }
            };

            AssertJsonError(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(jobAd.Id), JsonContentType, Serialize(model))), "FromName", "Your name is required.");

            // Logged in, cannot be changed.

            var member = CreateMember();

            LogIn(member);

            model = new EmailJobAdsModel {
                Tos = new[] { new EmailToModel {
                                  ToName = ToName, ToEmailAddress = ToEmailAddress
                              } }
            };
            AssertJsonSuccess(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(jobAd.Id), JsonContentType, Serialize(model))));
        }
Пример #4
0
        private void TestToEmailAddressErrors(Guid jobAdId)
        {
            // Required.

            var model = new EmailJobAdsModel {
                FromName = FromName, FromEmailAddress = FromEmailAddress
            };

            AssertJsonErrors(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(jobAdId), JsonContentType, Serialize(model))), "Tos", "Your friend's email address is required.", "Your friend's name is required.");

            model.Tos = new[] { new EmailToModel {
                                    ToName = ToName
                                } };
            AssertJsonError(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(jobAdId), JsonContentType, Serialize(model))), "ToEmailAddress", "Your friend's email address is required.");

            model.Tos = new[] { new EmailToModel {
                                    ToName = ToName, ToEmailAddress = ToEmailAddress
                                }, new EmailToModel {
                                    ToName = ToName2
                                } };
            AssertJsonError(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(jobAdId), JsonContentType, Serialize(model))), "ToEmailAddress", "Your friend's email address is required.");

            // Bad email address.

            model.Tos = new[] { new EmailToModel {
                                    ToName = ToName, ToEmailAddress = BadEmailAddress
                                } };
            AssertJsonError(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(jobAdId), JsonContentType, Serialize(model))), "ToEmailAddress", "Your friend's email address must be valid and have less than 320 characters.");

            model.Tos = new[] { new EmailToModel {
                                    ToName = ToName, ToEmailAddress = ToEmailAddress
                                }, new EmailToModel {
                                    ToName = ToName2, ToEmailAddress = BadEmailAddress
                                } };
            AssertJsonError(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(jobAdId), JsonContentType, Serialize(model))), "ToEmailAddress", "Your friend's email address must be valid and have less than 320 characters.");

            model.Tos = new[] { new EmailToModel {
                                    ToName = ToName, ToEmailAddress = UnknownEmailAddress
                                } };
            AssertJsonError(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(jobAdId), JsonContentType, Serialize(model))), "ToEmailAddress", "Your friend's email address is not recognised.");

            model.Tos = new[] { new EmailToModel {
                                    ToName = ToName, ToEmailAddress = ToEmailAddress
                                }, new EmailToModel {
                                    ToName = ToName2, ToEmailAddress = UnknownEmailAddress
                                } };
            AssertJsonError(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(jobAdId), JsonContentType, Serialize(model))), "ToEmailAddress", "Your friend's email address is not recognised.");
        }
Пример #5
0
        public void TestUnknownJobAd()
        {
            var model = new EmailJobAdsModel
            {
                FromName         = FromName,
                FromEmailAddress = FromEmailAddress,
                Tos = new[] { new EmailToModel {
                                  ToName = ToName, ToEmailAddress = ToEmailAddress
                              } },
                JobAdIds = new List <Guid> {
                    Guid.NewGuid()
                }
            };

            AssertJsonError(Deserialize <JsonResponseModel>(Post(HttpStatusCode.NotFound, GetApiEmailUrl(null), JsonContentType, Serialize(model))), null, "400", "The job ad cannot be found.");
        }
Пример #6
0
        public ActionResult EmailJobAds(EmailJobAdsModel emailJobAdsModel)
        {
            try
            {
                // If there is a current member then it needs to come from them.

                var member = CurrentMember;
                if (member != null)
                {
                    emailJobAdsModel.FromName         = member.FullName;
                    emailJobAdsModel.FromEmailAddress = member.GetBestEmailAddress().Address;
                }

                emailJobAdsModel.Prepare();
                emailJobAdsModel.Validate();

                foreach (var jobAdId in emailJobAdsModel.JobAdIds)
                {
                    var jobAd = _jobAdsQuery.GetJobAd <JobAdEntry>(jobAdId);
                    if (jobAd == null)
                    {
                        return(JsonNotFound("job ad"));
                    }

                    // Send to each recipient.

                    foreach (var to in emailJobAdsModel.Tos)
                    {
                        var email = new SendJobToFriendEmail(to.ToEmailAddress, to.ToName,
                                                             emailJobAdsModel.FromEmailAddress, emailJobAdsModel.FromName, jobAd, null);
                        _emailsCommand.TrySend(email);
                    }
                }
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new JobAdsErrorHandler());
            }

            return(Json(new JsonResponseModel()));
        }
Пример #7
0
        private void TestToNameErrors(Guid jobAdId)
        {
            // Required.

            var model = new EmailJobAdsModel {
                FromName = FromName, FromEmailAddress = FromEmailAddress
            };

            AssertJsonErrors(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(jobAdId), JsonContentType, Serialize(model))), "Tos", "Your friend's email address is required.", "Your friend's name is required.");

            model.Tos = new[] { new EmailToModel {
                                    ToEmailAddress = ToEmailAddress
                                } };
            AssertJsonError(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(jobAdId), JsonContentType, Serialize(model))), "ToName", "Your friend's name is required.");

            model.Tos = new[] { new EmailToModel {
                                    ToName = ToName, ToEmailAddress = ToEmailAddress
                                }, new EmailToModel {
                                    ToEmailAddress = ToEmailAddress2
                                } };
            AssertJsonError(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(jobAdId), JsonContentType, Serialize(model))), "ToName", "Your friend's name is required.");
        }
Пример #8
0
        public void TestSingleRecipient()
        {
            var employer = CreateEmployer();
            var jobAd    = _jobAdsCommand.PostTestJobAd(employer);

            var model = new EmailJobAdsModel
            {
                FromName         = FromName,
                FromEmailAddress = FromEmailAddress,
                Tos = new[] { new EmailToModel {
                                  ToName = ToName, ToEmailAddress = ToEmailAddress
                              } },
                JobAdIds = new List <Guid> {
                    jobAd.Id
                }
            };

            AssertJsonSuccess(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(null), JsonContentType, Serialize(model))));

            var email = _emailServer.AssertEmailSent();

            email.AssertAddresses(new EmailRecipient(FromEmailAddress, FromName), Return, new EmailRecipient(ToEmailAddress, ToName));
        }
Пример #9
0
        public void TestFromEmailAddressErrors()
        {
            var employer = CreateEmployer();
            var jobAd    = _jobAdsCommand.PostTestJobAd(employer);

            // Not logged in required.

            var model = new EmailJobAdsModel {
                FromName = FromName, Tos = new[] { new EmailToModel {
                                                       ToName = ToName, ToEmailAddress = ToEmailAddress
                                                   } }
            };

            AssertJsonError(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(jobAd.Id), JsonContentType, Serialize(model))), "FromEmailAddress", "Your email address is required.");

            // Bad email address.

            model.FromEmailAddress = BadEmailAddress;
            AssertJsonError(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(jobAd.Id), JsonContentType, Serialize(model))), "FromEmailAddress", "Your email address must be valid and have less than 320 characters.");

            model.FromEmailAddress = UnknownEmailAddress;
            AssertJsonError(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(jobAd.Id), JsonContentType, Serialize(model))), "FromEmailAddress", "Your email address is not recognised.");

            // Logged in, cannot be changed.

            var member = CreateMember();

            LogIn(member);

            model = new EmailJobAdsModel {
                Tos = new[] { new EmailToModel {
                                  ToName = ToName, ToEmailAddress = ToEmailAddress
                              } }
            };
            AssertJsonSuccess(Deserialize <JsonResponseModel>(Post(GetApiEmailUrl(jobAd.Id), JsonContentType, Serialize(model))));
        }