private void LogSendMessageResult(bool sendMessage, CommunicationChannels communicationChannel, Candidate candidate, CommunicationRequest communicationRequest)
 {
     _logService.Info(
         "{0} send message type '{1}' via channel '{2}' to candidate '{3}' email '{4}' mobile number '{5}' with preferences '{6}'",
         sendMessage ? "Will" : "Will NOT",
         communicationRequest.MessageType,
         communicationChannel,
         candidate.EntityId,
         candidate.RegistrationDetails.EmailAddress,
         candidate.RegistrationDetails.PhoneNumber,
         JsonConvert.SerializeObject(candidate.CommunicationPreferences));
 }
예제 #2
0
        public void ShouldSendMandatoryMobileVerificationCodeViaSmsOnly(
            CommunicationChannels communicationChannel, MessageTypes messageType, bool expectedResult)
        {
            // Arrange.
            var candidate = new CandidateBuilder(Guid.NewGuid())
                            .EnableAllCommunications(false)
                            .Build();

            // Act.
            var result = candidate.ShouldSendMessageViaChannel(
                communicationChannel, messageType);

            // Assert.
            result.Should().Be(expectedResult);
        }
예제 #3
0
        public void ShouldHonourSendSavedSearchAlertsViaTextCommunicationPreference(
            CommunicationChannels communicationChannel, bool preference, bool expectedResult)
        {
            // Arrange.
            var candidate = new CandidateBuilder(Guid.NewGuid())
                            .EnableAllCommunications()
                            .EnableSavedSearchAlertsViaEmail(false)
                            .EnableSavedSearchAlertsViaText(preference)
                            .Build();

            // Act.
            var result = candidate.ShouldSendMessageViaChannel(
                communicationChannel, MessageTypes.SavedSearchAlert);

            // Assert.
            result.Should().Be(expectedResult);
        }
예제 #4
0
        public void ShouldHonourSendApplicationStatusChangesPreferenceViaSms(
            CommunicationChannels communicationChannel,
            MessageTypes messageType,
            bool sendApplicationStatusChangesViaText,
            bool expectedResult)
        {
            // Arrange.
            var candidate = new CandidateBuilder(Guid.NewGuid())
                            .EnableAllCommunications()
                            .EnableApplicationStatusChangeAlertsViaText(sendApplicationStatusChangesViaText)
                            .Build();

            // Act.
            var result = candidate.ShouldSendMessageViaChannel(
                communicationChannel, messageType);

            // Assert.
            result.Should().Be(expectedResult);
        }
예제 #5
0
        public void ShouldHonourSendApplicationSubmittedCommunicationPreference(
            CommunicationChannels communicationChannel, bool preference, bool expectedResult)
        {
            // Arrange.
            var candidate = new CandidateBuilder(Guid.NewGuid())
                            .EnableAllCommunications()
                            .Build();

            // Act.
            var sendApprenticeshipApplicationSubmitted = candidate.ShouldSendMessageViaChannel(
                communicationChannel, MessageTypes.ApprenticeshipApplicationSubmitted);

            var sendTraineeshipApplicationSubmitted = candidate.ShouldSendMessageViaChannel(
                communicationChannel, MessageTypes.TraineeshipApplicationSubmitted);

            // Assert.
            sendApprenticeshipApplicationSubmitted.Should().Be(expectedResult);
            sendTraineeshipApplicationSubmitted.Should().Be(expectedResult);
        }
예제 #6
0
        public void TestMarketingMappings(
            bool enableApplicationStatusChangeAlerts,
            bool enableExpiringApplicationAlerts,
            bool sendMarketingCommunications,
            bool sendSavedSearchAlerts,
            CommunicationChannels channel)
        {
            var candidateId = Guid.NewGuid();
            var candidate   = new CandidateBuilder(candidateId)
                              .EnableApplicationStatusChangeAlertsViaEmail(enableApplicationStatusChangeAlerts && channel == CommunicationChannels.Email)
                              .EnableApplicationStatusChangeAlertsViaText(enableApplicationStatusChangeAlerts && channel == CommunicationChannels.Sms)
                              .EnableExpiringApplicationAlertsViaEmail(enableExpiringApplicationAlerts && channel == CommunicationChannels.Email)
                              .EnableExpiringApplicationAlertsViaText(enableExpiringApplicationAlerts && channel == CommunicationChannels.Sms)
                              .EnableMarketingViaEmail(sendMarketingCommunications && channel == CommunicationChannels.Email)
                              .EnableMarketingViaText(sendMarketingCommunications && channel == CommunicationChannels.Sms)
                              .EnableSavedSearchAlertsViaEmail(sendSavedSearchAlerts && channel == CommunicationChannels.Email)
                              .EnableSavedSearchAlertsViaText(sendSavedSearchAlerts && channel == CommunicationChannels.Sms)
                              .Build();

            var candidateService = new Mock <ICandidateService>();

            candidateService.Setup(cs => cs.GetCandidate(candidateId)).Returns(candidate);

            var provider  = new AccountProviderBuilder().With(candidateService).Build();
            var viewModel = provider.GetSettingsViewModel(candidateId);

            viewModel.Should().NotBeNull();

            viewModel.EnableApplicationStatusChangeAlertsViaEmail.Should().Be(enableApplicationStatusChangeAlerts && channel == CommunicationChannels.Email);
            viewModel.EnableApplicationStatusChangeAlertsViaText.Should().Be(enableApplicationStatusChangeAlerts && channel == CommunicationChannels.Sms);

            viewModel.EnableExpiringApplicationAlertsViaEmail.Should().Be(enableExpiringApplicationAlerts && channel == CommunicationChannels.Email);
            viewModel.EnableExpiringApplicationAlertsViaText.Should().Be(enableExpiringApplicationAlerts && channel == CommunicationChannels.Sms);

            viewModel.EnableMarketingViaEmail.Should().Be(sendMarketingCommunications && channel == CommunicationChannels.Email);
            viewModel.EnableMarketingViaText.Should().Be(sendMarketingCommunications && channel == CommunicationChannels.Sms);

            viewModel.EnableSavedSearchAlertsViaEmail.Should().Be(sendSavedSearchAlerts && channel == CommunicationChannels.Email);
            viewModel.EnableSavedSearchAlertsViaText.Should().Be(sendSavedSearchAlerts && channel == CommunicationChannels.Sms);
        }
예제 #7
0
        public void ShouldHonourDailyDigestPreferencesViaEmail(
            CommunicationChannels communicationChannel,
            MessageTypes messageType,
            bool sendApplicationStatusChangesViaEmail,
            bool sendApprenticeshipApplicationsExpiringViaEmail,
            bool expectedResult)
        {
            // Arrange.
            var candidate = new CandidateBuilder(Guid.NewGuid())
                            .EnableAllCommunications()
                            .EnableApplicationStatusChangeAlertsViaEmail(sendApplicationStatusChangesViaEmail)
                            .EnableApplicationStatusChangeAlertsViaText(true)
                            .EnableExpiringApplicationAlertsViaEmail(sendApprenticeshipApplicationsExpiringViaEmail)
                            .EnableExpiringApplicationAlertsViaText(true)
                            .Build();

            // Act.
            var result = candidate.ShouldSendMessageViaChannel(
                communicationChannel, messageType);

            // Assert.
            result.Should().Be(expectedResult);
        }
        public static bool ShouldSendMessageViaChannel(
            this Candidate candidate, CommunicationChannels communicationChannel, MessageTypes messageType)
        {
            var communicationPreferences = candidate.CommunicationPreferences;

            switch (messageType)
            {
            case MessageTypes.SendActivationCode:
            case MessageTypes.SendPasswordResetCode:
            case MessageTypes.SendAccountUnlockCode:
            case MessageTypes.PasswordChanged:
            case MessageTypes.SendPendingUsernameCode:
            case MessageTypes.SendActivationCodeReminder:
            case MessageTypes.SendDormantAccountReminder:
                // Currently sent via email only, candidate cannot opt out of these mandatory communications.
                return(communicationChannel == CommunicationChannels.Email);

            case MessageTypes.SendMobileVerificationCode:
            case MessageTypes.SendMobileVerificationCodeReminder:
            case MessageTypes.SendEmailReminder:
                return(communicationChannel == CommunicationChannels.Sms);

            case MessageTypes.DailyDigest:
                // Daily digests are sent via email only, candidate can opt out of application status alerts
                // and expiring draft notifications individually.
                return(communicationChannel == CommunicationChannels.Email &&
                       (communicationPreferences.ApplicationStatusChangePreferences.EnableEmail ||
                        communicationPreferences.ExpiringApplicationPreferences.EnableEmail));

            case MessageTypes.ApprenticeshipApplicationSuccessful:
            case MessageTypes.ApprenticeshipApplicationUnsuccessful:
            case MessageTypes.ApprenticeshipApplicationsUnsuccessfulSummary:
                // These individual application status alerts are sent via SMS only, candidate can opt out.
                // The email version is sent as an aggregate via the daily digest so that check is done above
                return(communicationChannel == CommunicationChannels.Sms &&
                       communicationPreferences.VerifiedMobile &&
                       communicationPreferences.ApplicationStatusChangePreferences.EnableText);

            case MessageTypes.ApprenticeshipApplicationExpiringDraft:
            case MessageTypes.ApprenticeshipApplicationExpiringDraftsSummary:
                // These expiring draft notifications are sent via SMS only, candidate can opt out.
                return(communicationChannel == CommunicationChannels.Sms &&
                       communicationPreferences.VerifiedMobile &&
                       communicationPreferences.ExpiringApplicationPreferences.EnableText);

            case MessageTypes.ApprenticeshipApplicationSubmitted:
            case MessageTypes.TraineeshipApplicationSubmitted:
                // Application submitted notifications are sent via email only and candidate cannot opt out.
                return(communicationChannel == CommunicationChannels.Email);

            case MessageTypes.SavedSearchAlert:
                // Saved search alerts may be sent via email and SMS, candidate can opt out of each channel separately.
                return((communicationChannel == CommunicationChannels.Email &&
                        communicationPreferences.SavedSearchPreferences.EnableEmail) ||
                       (communicationChannel == CommunicationChannels.Sms &&
                        communicationPreferences.VerifiedMobile &&
                        communicationPreferences.SavedSearchPreferences.EnableText));
            }

            // Do not allow any communications to be sent implicitly.
            return(false);
        }
        public void ShouldMapCommunicationPreferences(string phoneNumber, CommunicationChannels communicationChannel, bool verifiedMobile)
        {
            // Arrange.
            var candidateId      = Guid.NewGuid();
            var candidateService = new Mock <ICandidateService>();

            candidateService.Setup(cs => cs.GetCandidate(candidateId)).Returns(new CandidateBuilder(candidateId).PhoneNumber(phoneNumber).VerifiedMobile(verifiedMobile).Build);

            var viewModel = new SettingsViewModelBuilder()
                            .PhoneNumber(phoneNumber)
                            .EnableApplicationStatusChangeAlertsViaEmail(communicationChannel == CommunicationChannels.Email)
                            .EnableApplicationStatusChangeAlertsViaText(communicationChannel == CommunicationChannels.Sms)
                            .EnableExpiringApplicationAlertsViaEmail(communicationChannel == CommunicationChannels.Email)
                            .EnableExpiringApplicationAlertsViaText(communicationChannel == CommunicationChannels.Sms)
                            .EnableMarketingViaEmail(communicationChannel == CommunicationChannels.Email)
                            .EnableMarketingViaText(communicationChannel == CommunicationChannels.Sms)
                            .EnableSavedSearchAlertsViaEmail(communicationChannel == CommunicationChannels.Email)
                            .EnableSavedSearchAlertsViaText(communicationChannel == CommunicationChannels.Sms)
                            .Build();

            var provider = new AccountProviderBuilder().With(candidateService).Build();

            Candidate candidate;

            // Act.
            var result = provider.TrySaveSettings(candidateId, viewModel, out candidate);

            // Assert.
            result.Should().BeTrue();

            candidate.RegistrationDetails.Should().NotBeNull();
            candidate.RegistrationDetails.PhoneNumber.Should().Be(phoneNumber);

            candidate.CommunicationPreferences.Should().NotBeNull();

            {
                var preferences = candidate.CommunicationPreferences.ApplicationStatusChangePreferences;

                preferences.Should().NotBeNull();
                preferences.EnableEmail.Should().Be(communicationChannel == CommunicationChannels.Email);
                preferences.EnableText.Should().Be(communicationChannel == CommunicationChannels.Sms);
            }

            {
                var preferences = candidate.CommunicationPreferences.ExpiringApplicationPreferences;

                preferences.Should().NotBeNull();
                preferences.EnableEmail.Should().Be(communicationChannel == CommunicationChannels.Email);
                preferences.EnableText.Should().Be(communicationChannel == CommunicationChannels.Sms);
            }

            {
                var preferences = candidate.CommunicationPreferences.MarketingPreferences;

                preferences.Should().NotBeNull();
                preferences.EnableEmail.Should().Be(communicationChannel == CommunicationChannels.Email);
                preferences.EnableText.Should().Be(communicationChannel == CommunicationChannels.Sms);
            }

            {
                var preferences = candidate.CommunicationPreferences.SavedSearchPreferences;

                preferences.Should().NotBeNull();
                preferences.EnableEmail.Should().Be(communicationChannel == CommunicationChannels.Email);
                preferences.EnableText.Should().Be(communicationChannel == CommunicationChannels.Sms);
            }

            candidate.CommunicationPreferences.VerifiedMobile.Should().Be(verifiedMobile);
        }
예제 #10
0
파일: Package.cs 프로젝트: ekolis/FrEee
        public override string ToString()
        {
            var items = new List <string>();

            if (TreatyClauses.Any())
            {
                if (TreatyClauses.Count == 1)
                {
                    items.Add(TreatyClauses.Single().ToString());
                }
                else
                {
                    items.Add(TreatyClauses.Count + " treaty clauses");
                }
            }
            if (Planets.Any())
            {
                if (Planets.Count == 1)
                {
                    items.Add(Planets.Single().ToString());
                }
                else
                {
                    items.Add(Planets.Count + " planets");
                }
            }
            if (Vehicles.Any())
            {
                if (Vehicles.Count == 1)
                {
                    items.Add(Vehicles.Single().ToString());
                }
                else
                {
                    items.Add(Vehicles.Count + " vehicles");
                }
            }
            if (Resources.Any(kvp => kvp.Value != 0))
            {
                items.Add(Resources.ToString());
            }
            if (Technology.Any())
            {
                if (Technology.Count == 1)
                {
                    var kvp = Technology.Single();
                    items.Add(kvp.Key + " to level " + kvp.Value);
                }
                else
                {
                    items.Add(Technology.Count + " technologies");
                }
            }
            if (StarCharts.Any())
            {
                if (StarCharts.Count == 1)
                {
                    items.Add("the star chart for " + StarCharts.Single().ToString());
                }
                else
                {
                    items.Add(StarCharts.Count + " star charts");
                }
            }
            if (CommunicationChannels.Any())
            {
                if (CommunicationChannels.Count == 1)
                {
                    items.Add("comm channels to " + CommunicationChannels.Single().ToString());
                }
                else
                {
                    items.Add(CommunicationChannels.Count + " comm channels");
                }
            }
            if (!items.Any())
            {
                return("nothing");
            }
            return(string.Join(", ", items.ToArray()));
        }