Exemplo n.º 1
0
 public EmailMemberNewsletterTask(IEmailsCommand emailsCommand, ISettingsQuery settingsQuery, IMemberCommunicationsQuery memberCommunicationsQuery, IMembersQuery membersQuery)
     : base(EventSource, emailsCommand)
 {
     _settingsQuery             = settingsQuery;
     _definition                = _settingsQuery.GetDefinition(typeof(MemberNewsletterEmail).Name);
     _memberCommunicationsQuery = memberCommunicationsQuery;
     _membersQuery              = membersQuery;
 }
Exemplo n.º 2
0
        private void CreateDefinition(Guid campaignId)
        {
            // check whether it exists.

            var name       = "Campaign:" + campaignId;
            var definition = _settingsQuery.GetDefinition(name);

            if (definition != null)
            {
                return;
            }

            var category = _settingsQuery.GetCategory("Campaign");

            _settingsCommand.CreateDefinition(new Definition {
                Name = name, CategoryId = category.Id
            });
        }
Exemplo n.º 3
0
        private Employer CreateEmployer(int index, Guid creditId, DateTime expiryDate, int?quantity, DateTime?lastSentTime)
        {
            var employer = _employerAccountsCommand.CreateTestEmployer(index, _organisationsCommand.CreateTestOrganisation(index));

            // Allocate credits to the employer.

            _allocationsCommand.CreateAllocation(new Allocation {
                OwnerId = employer.Id, CreditId = creditId, ExpiryDate = expiryDate, InitialQuantity = quantity
            });

            if (lastSentTime != null)
            {
                var definition = _settingsQuery.GetDefinition(typeof(ExpiringCreditsEmail).Name);
                _settingsCommand.SetLastSentTime(employer.Id, definition.Id, lastSentTime);
            }

            return(employer);
        }
Exemplo n.º 4
0
        public void TestLastRunTime()
        {
            var definition = _settingsQuery.GetDefinition("JobSearchAlertEmail");
            var employer   = CreateEmployer();
            var jobAd1     = PostJobAd(employer, DateTime.Now.AddDays(-5));
            var jobAd2     = PostJobAd(employer, DateTime.Now.AddDays(-3));
            var jobAd3     = PostJobAd(employer, DateTime.Now.AddDays(-1));

            // Create member.

            var member = CreateMember(0);

            // Create a job search, last run 2 days ago.

            var criteria = new JobAdSearchCriteria
            {
                AdTitle = BusinessAnalyst,
            };
            var search = new JobAdSearch {
                Criteria = criteria
            };

            _jobAdSearchAlertsCommand.CreateJobAdSearchAlert(member.Id, search, DateTime.Now.AddDays(-6));

            // Get the email.

            var email = ExecuteTask();

            email.AssertHtmlViewContains("<strong>3 new jobs</strong>");
            AssertJobAds(email, jobAd1, jobAd2, jobAd3);

            _jobAdSearchAlertsCommand.UpdateLastRunTime(search.Id, DateTime.Now.AddDays(-4));
            _settingsCommand.SetLastSentTime(member.Id, definition.Id, null);

            email = ExecuteTask();
            email.AssertHtmlViewContains("<strong>2 new jobs</strong>");
            AssertJobAds(email, jobAd2, jobAd3);

            _jobAdSearchAlertsCommand.UpdateLastRunTime(search.Id, DateTime.Now.AddDays(-2));
            _settingsCommand.SetLastSentTime(member.Id, definition.Id, null);

            email = ExecuteTask();
            email.AssertHtmlViewContains("<strong>1 new job</strong>");
            AssertJobAds(email, jobAd3);

            _jobAdSearchAlertsCommand.UpdateLastRunTime(search.Id, DateTime.Now);
            _settingsCommand.SetLastSentTime(member.Id, definition.Id, null);

            email = ExecuteTask();
            Assert.IsNull(email);
        }
Exemplo n.º 5
0
        protected Campaign CreateCampaign(Administrator administrator)
        {
            var campaign = new Campaign
            {
                Id       = new Guid("{B3DAC669-5BEF-4C76-93F5-BD06F6C1AFB2}"),
                Category = CampaignCategory.Member,
                Name     = "Member Reengagement",
                Query    = null,
                Status   = CampaignStatus.Draft,
                CommunicationCategoryId   = _settingsQuery.GetCategory("Campaign").Id,
                CommunicationDefinitionId = _settingsQuery.GetDefinition("ReengagementEmail").Id,
                CreatedBy = administrator.Id,
            };

            _campaignsCommand.CreateCampaign(campaign);
            return(campaign);
        }
Exemplo n.º 6
0
        private Campaign CreateCampaign()
        {
            var campaign = new Campaign
            {
                Id       = new Guid("{83B9911D-0AE8-4550-B64A-F0D2A97B2380}"),
                Category = CampaignCategory.Employer,
                Name     = "iOS Launch",
                Query    = null,
                Status   = CampaignStatus.Draft,
                CommunicationCategoryId   = _settingsQuery.GetCategory("Campaign").Id,
                CommunicationDefinitionId = _settingsQuery.GetDefinition("IosLaunchEmail").Id,
                CreatedBy = new Guid("2E7D03B6-37E2-4D12-89F3-FFB36B939509"),
            };

            _campaignsCommand.CreateCampaign(campaign);
            return(campaign);
        }
Exemplo n.º 7
0
        private Definition GetDefinition(string definitionName, IDictionary <string, Definition> definitions)
        {
            if (string.IsNullOrEmpty(definitionName))
            {
                return(null);
            }

            Definition definition;

            if (!definitions.TryGetValue(definitionName, out definition))
            {
                definition = _settingsQuery.GetDefinition(definitionName) ?? new Definition {
                    Name = definitionName
                };
                definitions[definitionName] = definition;
            }

            return(definition);
        }
Exemplo n.º 8
0
        private Member CreateMember(int index, Frequency?frequency, DateTime?lastSent, bool enabled, bool activated, DateTime joined)
        {
            var member = _memberAccountsCommand.CreateTestMember(string.Format(EmailAddressFormat, index));

            member.IsEnabled   = enabled;
            member.IsActivated = activated;
            member.CreatedTime = joined;
            _memberAccountsCommand.UpdateMember(member);

            var definition = _settingsQuery.GetDefinition(typeof(MemberNewsletterEmail).Name);

            if (frequency != null)
            {
                _settingsCommand.SetFrequency(member.Id, definition.CategoryId, frequency.Value);
            }
            if (lastSent != null)
            {
                _settingsCommand.SetLastSentTime(member.Id, definition.Id, lastSent.Value);
            }

            return(member);
        }
Exemplo n.º 9
0
        protected void GetBodyEnd(TemplateEmail email, ICommunicationUser to, StringBuilder sb)
        {
            sb.AppendLine("      </div>");

            if (to != null)
            {
                if (to is Member)
                {
                    sb.AppendLine("      <div class=\"signature\" style=\"padding-left: 9px; font-family: Arial, Helvetica, sans-serif; color: gray; font-size: 9pt; padding-top:1em;\">");
                    GetMemberSignature(email, sb);
                    sb.AppendLine("      </div>");
                    sb.AppendLine();
                }
                else if (to is IEmployer)
                {
                    sb.AppendLine("      <div class=\"signature\" style=\"padding-left: 9px; font-family: Arial, Helvetica, sans-serif; color: gray; font-size: 9pt; padding-top:1em;\">");
                    GetClientSignature(email, sb);
                    sb.AppendLine("      </div>");
                }
                else if (to is Custodian)
                {
                    sb.AppendLine("      <div class=\"signature\" style=\"padding-left: 9px; font-family: Arial, Helvetica, sans-serif; color: gray; font-size: 9pt; padding-top:1em;\">");
                    GetCommunitySignature(sb);
                    sb.AppendLine("      </div>");
                }
            }

            string category   = null;
            var    definition = _settingsQuery.GetDefinition(email.Definition);

            if (definition != null)
            {
                category = _settingsQuery.GetCategory(definition.CategoryId).Name;
            }

            if (category != null && to is Member && to.FirstName != null)
            {
                sb.AppendLine("      <div class=\"unsubscribe\" style=\"padding-left: 9px; font-family: Arial, Helvetica, sans-serif; color: gray; font-size: 8pt; padding-top:1em; margin-left: 20px;\">");
                sb.AppendLine("        <p>");
                sb.AppendLine("          Receiving too many emails?");
                sb.AppendLine("          <br />");
                sb.AppendLine("          <a href=\"" + GetTinyUrl(email, true, "~/members/settings") + "\">");
                sb.AppendLine("            Log in");
                sb.AppendLine("          </a>");
                sb.AppendLine("          to choose the emails you receive from us.");
                sb.AppendLine("        </p>");
                sb.AppendLine("        <p>");
                sb.AppendLine("          Alternatively, you can");
                sb.AppendLine("          <a href=\"" + GetTinyUrl(email, false, "~/accounts/settings/unsubscribe", "userId", to.Id.ToString("n"), "category", category) + "\">");
                sb.AppendLine("            unsubscribe");
                sb.AppendLine("          </a>");
                sb.AppendLine("          from this type of email entirely.");
                sb.AppendLine("        </p>");
                sb.AppendLine("      </div>");
                sb.AppendLine();
            }

            sb.AppendLine("    </div>");
            sb.AppendLine("    <img src=\"" + GetTrackingPixelUrl(email) + "\" width=\"1\" height=\"1\" />");
            sb.AppendLine("  </body>");
            sb.AppendLine("</html>");
        }
Exemplo n.º 10
0
        private void ClearEmployer(IHasId <Guid> employer)
        {
            var definition = _settingsQuery.GetDefinition(typeof(EmployerUsageEmail).Name);

            _settingsCommand.SetLastSentTime(employer.Id, definition.Id, null);
        }
Exemplo n.º 11
0
        public void TestMemberNewsletterEmailLinks()
        {
            var member = _memberAccountsCommand.CreateTestMember(0);

            // Send the email.

            _emailsCommand.TrySend(new MemberNewsletterEmail(member));
            _settingsCommand.SetLastSentTime(member.Id, _settingsQuery.GetDefinition("MemberNewsletterEmail").Id, null);

            // Check the email.

            var email      = _emailServer.AssertEmailSent();
            var links      = GetUpdateLinks(email.GetHtmlView().Body);
            var definition = typeof(MemberNewsletterEmail).Name;

            Assert.AreEqual(21, links.Count);

            // First link is in the intro.

            var currentLink = 0;

            // Resource link that is not working?
            currentLink++;
            //AssertLink(definition, new ReadOnlyUrl("www.redstarresume.com"), links[currentLink++]);

            // Talent 2 link
            currentLink++;

            AssertLink(definition, member, _profileUrl, links[currentLink++]);

            // Resource link that is not working?

            currentLink++;
            AssertLink(definition, _resourcesUrl, links[currentLink++]);

            // Balance recruitment and resource links.
            currentLink++;
            currentLink++;

            AssertLink(definition, HomeUrl, links[currentLink++]);
            AssertLink(definition, member, _profileUrl, links[currentLink++]);

            // Resource links.
            currentLink++;
            currentLink++;
            currentLink++;
            currentLink++;
            currentLink++;
            currentLink++;

            // Facebook and twitter.

            currentLink++;
            currentLink++;
            currentLink++;

            AssertLink(definition, HomeUrl, links[currentLink++]);
            AssertLink(definition, member, _memberSettingsUrl, links[currentLink++]);
            AssertLink(definition, GetUnsubscribeUrl(member.Id.ToString(), "MemberUpdate"), links[currentLink]);

            // Check the tracking pixel.

//            var link = GetUpdateImageLinks(email.GetHtmlView().Body).Last();
//            AssertTrackingLink(link);
        }