Exemplo n.º 1
0
        public void UpdateExistingAlert()
        {
            const int legacyApplicationId = 3456789;
            const ApplicationStatuses applicationStatus = ApplicationStatuses.Unsuccessful;
            const string unsuccessfulReason             = "You do not have the required grades";

            var applicationId             = Guid.NewGuid();
            var applicationReadRepository = new Mock <IApprenticeshipApplicationReadRepository>();

            var apprenticeshipApplicationDetail = new Fixture().Build <ApprenticeshipApplicationDetail>()
                                                  .With(aad => aad.EntityId, applicationId)
                                                  .With(aad => aad.LegacyApplicationId, legacyApplicationId)
                                                  .Create();

            applicationReadRepository.Setup(r => r.Get(legacyApplicationId, true)).Returns(apprenticeshipApplicationDetail);

            var existingApplicationStatusAlert = new Fixture().Build <ApplicationStatusAlert>()
                                                 .With(asa => asa.ApplicationId, applicationId)
                                                 .With(asa => asa.Status, ApplicationStatuses.Successful)
                                                 .With(asa => asa.BatchId, null)
                                                 .With(asa => asa.SentDateTime, null)
                                                 .Create();

            var statusAlertRepository = new Mock <IApplicationStatusAlertRepository>();

            statusAlertRepository.Setup(r => r.GetForApplication(applicationId)).Returns(new List <ApplicationStatusAlert> {
                existingApplicationStatusAlert
            });

            ApplicationStatusAlert applicationStatusAlert = null;

            statusAlertRepository.Setup(r => r.Save(It.IsAny <ApplicationStatusAlert>())).Callback <ApplicationStatusAlert>(asa => { applicationStatusAlert = asa; });

            var subscriber = new ApplicationStatusChangedSubscriberBuilder().With(applicationReadRepository).With(statusAlertRepository).Build();

            var applicationStatusChanged = new Fixture().Build <ApplicationStatusChanged>()
                                           .With(asc => asc.LegacyApplicationId, legacyApplicationId)
                                           .With(asc => asc.ApplicationStatus, applicationStatus)
                                           .With(asc => asc.UnsuccessfulReason, unsuccessfulReason)
                                           .Create();

            var state = subscriber.Consume(applicationStatusChanged);

            state.Should().NotBeNull();
            state.Should().Be(ServiceBusMessageStates.Complete);

            applicationStatusAlert.EntityId.Should().Be(existingApplicationStatusAlert.EntityId);
            applicationStatusAlert.Status.Should().Be(applicationStatus);
            applicationStatusAlert.UnsuccessfulReason.Should().Be(unsuccessfulReason);
            applicationStatusAlert.BatchId.Should().Be(null);
            applicationStatusAlert.SentDateTime.Should().Be(null);
        }
Exemplo n.º 2
0
 private void QueueApplicationStatusAlertSmsMessage(
     Candidate candidate, string mobileNumber, MessageTypes messageType, ApplicationStatusAlert applicationStatusAlert)
 {
     base.HandleSmsMessage(candidate, new CommunicationRequest
     {
         MessageType = messageType,
         Tokens      = new[]
         {
             new CommunicationToken(CommunicationTokens.CandidateMobileNumber, mobileNumber),
             new CommunicationToken(CommunicationTokens.ApplicationStatusAlert, JsonConvert.SerializeObject(applicationStatusAlert))
         }
     });
 }
Exemplo n.º 3
0
        public void Mapping()
        {
            const int legacyApplicationId = 3456789;
            const ApplicationStatuses applicationStatus = ApplicationStatuses.Unsuccessful;
            const string unsuccessfulReason             = "You do not have the required grades";

            var applicationReadRepository       = new Mock <IApprenticeshipApplicationReadRepository>();
            var apprenticeshipApplicationDetail = new Fixture().Build <ApprenticeshipApplicationDetail>().With(aad => aad.LegacyApplicationId, legacyApplicationId).Create();

            applicationReadRepository.Setup(r => r.Get(legacyApplicationId, true)).Returns(apprenticeshipApplicationDetail);

            var statusAlertRepository = new Mock <IApplicationStatusAlertRepository>();

            ApplicationStatusAlert applicationStatusAlert = null;

            statusAlertRepository.Setup(r => r.Save(It.IsAny <ApplicationStatusAlert>())).Callback <ApplicationStatusAlert>(asa => { applicationStatusAlert = asa; });
            statusAlertRepository.Setup(r => r.GetForApplication(It.IsAny <Guid>())).Returns(new List <ApplicationStatusAlert>());

            var subscriber = new ApplicationStatusChangedSubscriberBuilder().With(applicationReadRepository).With(statusAlertRepository).Build();

            var applicationStatusChanged = new Fixture().Build <ApplicationStatusChanged>()
                                           .With(asc => asc.LegacyApplicationId, legacyApplicationId)
                                           .With(asc => asc.ApplicationStatus, applicationStatus)
                                           .With(asc => asc.UnsuccessfulReason, unsuccessfulReason)
                                           .Create();

            var state = subscriber.Consume(applicationStatusChanged);

            state.Should().NotBeNull();
            state.Should().Be(ServiceBusMessageStates.Complete);

            applicationStatusAlert.Should().NotBeNull();
            applicationStatusAlert.CandidateId.Should().Be(apprenticeshipApplicationDetail.CandidateId);
            applicationStatusAlert.ApplicationId.Should().Be(apprenticeshipApplicationDetail.EntityId);
            applicationStatusAlert.VacancyId.Should().Be(apprenticeshipApplicationDetail.Vacancy.Id);
            applicationStatusAlert.Title.Should().Be(apprenticeshipApplicationDetail.Vacancy.Title);
            applicationStatusAlert.EmployerName.Should().Be(apprenticeshipApplicationDetail.Vacancy.EmployerName);
            applicationStatusAlert.Status.Should().Be(applicationStatus);
            applicationStatusAlert.UnsuccessfulReason.Should().Be(unsuccessfulReason);
            // ReSharper disable once PossibleInvalidOperationException
            applicationStatusAlert.DateApplied.Should().Be(apprenticeshipApplicationDetail.DateApplied.Value);
            applicationStatusAlert.BatchId.Should().Be(null);
            applicationStatusAlert.SentDateTime.Should().Be(null);
        }
        public ServiceBusMessageStates Consume(ApplicationStatusChanged applicationStatusChanged)
        {
            var application = _apprenticeshipApplicationReadRepository.Get(applicationStatusChanged.LegacyApplicationId, _strictEtlValidation);

            if (application == null)
            {
                _logService.Warn(_strictEtlValidation, string.Format(ApplicationNotFoundMessageFormat, applicationStatusChanged.LegacyApplicationId));
                return(ServiceBusMessageStates.Complete);
            }

            var applicationStatusAlerts = _applicationStatusAlertRepository.GetForApplication(application.EntityId);
            var applicationStatusAlert  = applicationStatusAlerts.FirstOrDefault(asa => asa.BatchId == null);

            if (applicationStatusAlert == null)
            {
                applicationStatusAlert = new ApplicationStatusAlert
                {
                    CandidateId          = application.CandidateId,
                    ApplicationId        = application.EntityId,
                    VacancyId            = application.Vacancy.Id,
                    Title                = application.Vacancy.Title,
                    EmployerName         = application.Vacancy.EmployerName,
                    Status               = application.Status,
                    UnsuccessfulReason   = application.UnsuccessfulReason,
                    DateApplied          = application.DateApplied ?? new DateTime(),
                    UnSuccessfulDateTime = application.UnsuccessfulDateTime ?? new DateTime()
                };
            }

            applicationStatusAlert.Status             = applicationStatusChanged.ApplicationStatus;
            applicationStatusAlert.UnsuccessfulReason = applicationStatusChanged.UnsuccessfulReason;

            _applicationStatusAlertRepository.Save(applicationStatusAlert);

            return(ServiceBusMessageStates.Complete);
        }