Пример #1
0
        public void ShouldSendMobileVerificationCodeReminderInConfiguredHousekeepingCycle(
            int housekeepingCycleInHours,
            int sendMobileVerificationCodeReminderAfterCycles)
        {
            // Arrange.
            var mockSuccessorStrategy    = new Mock <IHousekeepingStrategy>();
            var mockCommunicationService = new Mock <ICommunicationService>();

            var strategy = new SendMobileVerificationCodeReminderStrategyBuilder()
                           .With(mockSuccessorStrategy)
                           .With(mockCommunicationService)
                           .WithHousekeepingCycleInHours(housekeepingCycleInHours)
                           .WithSendMobileVerificationCodeReminderAfterCycles(sendMobileVerificationCodeReminderAfterCycles)
                           .Build();

            var candidateId = Guid.NewGuid();
            var user        = new UserBuilder(candidateId).Build();
            var hoursAgo    = -(sendMobileVerificationCodeReminderAfterCycles * housekeepingCycleInHours);

            var candidate = new CandidateBuilder(candidateId)
                            .PhoneNumber(PhoneNumber)
                            .MobileVerificationCode(MobileVerificationCode)
                            .MobileVerificationCodeDateCreated(DateTime.UtcNow.AddHours(hoursAgo))
                            .EnableAllCommunications()
                            .Build();

            // Act.
            strategy.Handle(user, candidate);

            // Assert.
            mockSuccessorStrategy.Verify(mock => mock.Handle(user, candidate), Times.Once);

            mockCommunicationService.Verify(mock => mock.SendMessageToCandidate(
                                                candidateId, MessageTypes.SendMobileVerificationCodeReminder, It.IsAny <IEnumerable <CommunicationToken> >()), Times.Once);
        }
Пример #2
0
        public void ShouldSendWellFormedMobileVerificationCodeReminder()
        {
            // Arrange.
            var mockSuccessorStrategy    = new Mock <IHousekeepingStrategy>();
            var mockCommunicationService = new Mock <ICommunicationService>();

            var strategy = new SendMobileVerificationCodeReminderStrategyBuilder()
                           .With(mockSuccessorStrategy)
                           .With(mockCommunicationService)
                           .Build();

            var candidateId = Guid.NewGuid();

            var user = new UserBuilder(candidateId).Build();

            var candidate = new CandidateBuilder(candidateId)
                            .PhoneNumber(PhoneNumber)
                            .MobileVerificationCode(MobileVerificationCode)
                            .MobileVerificationCodeDateCreated(UtcYesterday)
                            .EnableAllCommunications()
                            .Build();

            var expectedCommunicationTokens = new[]
            {
                new CommunicationToken(CommunicationTokens.CandidateMobileNumber, PhoneNumber),
                new CommunicationToken(CommunicationTokens.MobileVerificationCode, MobileVerificationCode)
            };

            IEnumerable <CommunicationToken> actualCommunicationTokens = null;

            mockCommunicationService
            .Setup(mock => mock.SendMessageToCandidate(
                       candidateId, MessageTypes.SendMobileVerificationCodeReminder, It.IsAny <IEnumerable <CommunicationToken> >()))
            .Callback <Guid, MessageTypes, IEnumerable <CommunicationToken> >((id, code, tokens) => actualCommunicationTokens = tokens);

            // Act.
            strategy.Handle(user, candidate);

            // Assert.
            mockSuccessorStrategy.Verify(mock => mock.Handle(user, candidate), Times.Once);

            mockCommunicationService.Verify(mock => mock.SendMessageToCandidate(
                                                candidateId, MessageTypes.SendMobileVerificationCodeReminder, It.IsAny <IEnumerable <CommunicationToken> >()), Times.Once);

            actualCommunicationTokens.ShouldBeEquivalentTo(expectedCommunicationTokens);
        }
Пример #3
0
        public void ShouldSendMobileVerificationCodeReminderBasedOnCandidateCommunicationPreferences(
            string mobileVerificationCode,
            bool applicationStatusChangePreferencesEnableText,
            bool expiringApplicationPreferencesEnableText,
            bool savedSearchPreferencesEnableText,
            bool marketingPreferencesEnableText,
            bool shouldSendMobileVerificationCode)
        {
            // Arrange.
            var mockSuccessorStrategy    = new Mock <IHousekeepingStrategy>();
            var mockCommunicationService = new Mock <ICommunicationService>();

            var strategy = new SendMobileVerificationCodeReminderStrategyBuilder()
                           .With(mockSuccessorStrategy)
                           .With(mockCommunicationService)
                           .Build();

            var candidateId = Guid.NewGuid();

            var user = new UserBuilder(candidateId).Build();

            var candidate = new CandidateBuilder(candidateId)
                            .PhoneNumber(PhoneNumber)
                            .MobileVerificationCode(mobileVerificationCode)
                            .MobileVerificationCodeDateCreated(UtcYesterday)
                            .EnableApplicationStatusChangeAlertsViaText(applicationStatusChangePreferencesEnableText)
                            .EnableExpiringApplicationAlertsViaText(expiringApplicationPreferencesEnableText)
                            .EnableSavedSearchAlertsViaEmailAndText(savedSearchPreferencesEnableText)
                            .EnableMarketingViaText(marketingPreferencesEnableText)
                            .Build();

            // Act.
            strategy.Handle(user, candidate);

            // Assert.
            mockSuccessorStrategy.Verify(mock => mock.Handle(user, candidate), Times.Once);

            var callCount = shouldSendMobileVerificationCode ? 1 : 0;

            mockCommunicationService.Verify(mock => mock.SendMessageToCandidate(
                                                candidateId, MessageTypes.SendMobileVerificationCodeReminder, It.IsAny <IEnumerable <CommunicationToken> >()), Times.Exactly(callCount));
        }