public CohortAssignedToEmployerEventHandlerTestsFixture()
            {
                _autoFixture = new Fixture();
                _mediator    = new Mock <IMediator>();

                _cohortSummary = _autoFixture.Create <GetCohortSummaryQueryResult>();
                _cohortSummary.ChangeOfPartyRequestId = null;
                _mediator.Setup(x => x.Send(It.IsAny <GetCohortSummaryQuery>(),
                                            It.IsAny <CancellationToken>()))
                .ReturnsAsync(() => _cohortSummary);

                _cohortReference          = _autoFixture.Create <string>();
                _employerEncodedAccountId = _autoFixture.Create <string>();
                _encodingService          = new Mock <IEncodingService>();
                _encodingService.Setup(x => x.Encode(It.Is <long>(id => id == _cohortSummary.CohortId),
                                                     EncodingType.CohortReference)).Returns(_cohortReference);
                _encodingService.Setup(x => x.Encode(It.Is <long>(id => id == _cohortSummary.AccountId),
                                                     EncodingType.AccountId)).Returns(_employerEncodedAccountId);

                _handler = new CohortAssignedToEmployerEventHandler(_mediator.Object, _encodingService.Object);

                _messageHandlerContext = new Mock <IMessageHandlerContext>();
                _pipelineContext       = _messageHandlerContext.As <IPipelineContext>();

                _event = _autoFixture.Create <CohortAssignedToEmployerEvent>();
            }
        private ProviderEmailRequest BuildEmailRequest(GetCohortSummaryQueryResult cohortSummary)
        {
            var request = new ProviderEmailRequest();

            request.ExplicitEmailAddresses = new List <string>();
            request.Tokens = new Dictionary <string, string>();

            if (!string.IsNullOrWhiteSpace(cohortSummary.LastUpdatedByProviderEmail))
            {
                request.ExplicitEmailAddresses.Add(cohortSummary.LastUpdatedByProviderEmail);
            }

            request.Tokens.Add("cohort_reference", cohortSummary.CohortReference);
            request.Tokens.Add("type", cohortSummary.LastAction == LastAction.Approve ? "approval" : "review");

            if (cohortSummary.IsFundedByTransfer)
            {
                request.TemplateId = "ProviderTransferCommitmentNotification";
                request.Tokens.Add("employer_name", cohortSummary.LegalEntityName);
            }
            else
            {
                request.TemplateId = "ProviderCommitmentNotification";
            }

            return(request);
        }
            public CohortTransferApprovalRequestedEventHandlerTestsFixture()
            {
                _autoFixture = new Fixture();

                _messageHandlerContext = new Mock <IMessageHandlerContext>();
                _pipelineContext       = _messageHandlerContext.As <IPipelineContext>();

                _cohortReference          = _autoFixture.Create <string>();
                _employerEncodedAccountId = _autoFixture.Create <string>();
                _encodingService          = new Mock <IEncodingService>();
                _encodingService.Setup(x => x.Encode(It.Is <long>(id => id == _cohortSummary.CohortId),
                                                     EncodingType.CohortReference)).Returns(_cohortReference);
                _encodingService.Setup(x => x.Encode(It.Is <long>(id => id == _cohortSummary.AccountId),
                                                     EncodingType.AccountId)).Returns(_employerEncodedAccountId);

                _mediator = new Mock <IMediator>();
                _mediator.Setup(x => x.Send(It.IsAny <AddTransferRequestCommand>(), It.IsAny <CancellationToken>()))
                .ReturnsAsync(new Unit());

                _cohortSummary = _autoFixture.Create <GetCohortSummaryQueryResult>();
                _mediator.Setup(x => x.Send(It.IsAny <GetCohortSummaryQuery>(),
                                            It.IsAny <CancellationToken>()))
                .ReturnsAsync(_cohortSummary);

                _handler = new CohortTransferApprovalRequestedEventHandler(_mediator.Object, _encodingService.Object);

                _event = new CohortTransferApprovalRequestedEvent(_autoFixture.Create <long>(),
                                                                  _autoFixture.Create <DateTime>(), _autoFixture.Create <Party>()
                                                                  );
            }
Beispiel #4
0
            public CohortWithChangeOfPartyCreatedEventHandlerForEmailTestsFixture()
            {
                _autoFixture      = new Fixture();
                _mediator         = new Mock <IMediator>();
                UnitOfWorkContext = new UnitOfWorkContext();

                _db = new ProviderCommitmentsDbContext(new DbContextOptionsBuilder <ProviderCommitmentsDbContext>()
                                                       .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                       .Options);

                _cohortSummary = _autoFixture.Create <GetCohortSummaryQueryResult>();
                _mediator.Setup(x => x.Send(It.IsAny <GetCohortSummaryQuery>(),
                                            It.IsAny <CancellationToken>()))
                .ReturnsAsync(() => _cohortSummary);

                _apprenticeship = new Apprenticeship
                {
                    Id        = _autoFixture.Create <long>(),
                    FirstName = _autoFixture.Create <string>(),
                    LastName  = _autoFixture.Create <string>(),
                    Cohort    = new Cohort
                    {
                        AccountLegalEntity = new AccountLegalEntity()
                    },
                    ReservationId = _autoFixture.Create <Guid>()
                };

                _changeOfPartyRequest = new ChangeOfPartyRequest(_apprenticeship, ChangeOfPartyRequestType.ChangeProvider, Party.Employer, _autoFixture.Create <long>(), null, null, null, _autoFixture.Create <UserInfo>(), DateTime.Now);
                _apprenticeship.Cohort.ChangeOfPartyRequestId = _changeOfPartyRequest.Id;

                _db.ChangeOfPartyRequests.Add(_changeOfPartyRequest);
                _db.Apprenticeships.Add(_apprenticeship);
                _db.SaveChanges();

                _expectedApprenticeName         = _apprenticeship.LastName.EndsWith("s") ? $"{_apprenticeship.FirstName} {_apprenticeship.LastName}'" : $"{_apprenticeship.FirstName} {_apprenticeship.LastName}'s";
                _expectedSubjectDetailsRequired = $"{_cohortSummary.LegalEntityName} has requested that you add details on their behalf";
                _expectedSubjectForReview       = $"{_cohortSummary.LegalEntityName} has added details for you to review";
                _expectedRequestUrl             = $"{_cohortSummary.ProviderId}/apprentices/{_cohortSummary.CohortReference}/details";

                _cohortReference          = _autoFixture.Create <string>();
                _employerEncodedAccountId = _autoFixture.Create <string>();
                _encodingService          = new Mock <IEncodingService>();
                _encodingService.Setup(x => x.Encode(It.Is <long>(id => id == _cohortSummary.CohortId),
                                                     EncodingType.CohortReference)).Returns(_cohortReference);
                _encodingService.Setup(x => x.Encode(It.Is <long>(id => id == _cohortSummary.AccountId),
                                                     EncodingType.AccountId)).Returns(_employerEncodedAccountId);

                _handler = new CohortWithChangeOfPartyCreatedEventHandlerForEmail(new Lazy <ProviderCommitmentsDbContext>(() => _db),
                                                                                  _mediator.Object,
                                                                                  _encodingService.Object,
                                                                                  Mock.Of <ILogger <CohortWithChangeOfPartyCreatedEventHandlerForEmail> >());

                _messageHandlerContext = new TestableMessageHandlerContext();

                _event = new CohortWithChangeOfPartyCreatedEvent(_cohortSummary.CohortId, _changeOfPartyRequest.Id, Party.Employer, DateTime.Now, _autoFixture.Create <UserInfo>());
            }
        public CohortAssignedToProviderEventHandlerTestsFixture SetupChangeOfProviderCohort()
        {
            GetCohortSummaryQueryResult = DataFixture.Build <GetCohortSummaryQueryResult>()
                                          .With(p => p.ChangeOfPartyRequestId, 1000).Create();

            Mediator.Setup(x => x.Send(It.IsAny <GetCohortSummaryQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(GetCohortSummaryQueryResult);

            return(this);
        }
        public ApprovedCohortReturnedToProviderEventHandlerTestsFixture()
        {
            var autoFixture = new Fixture();

            Mediator = new Mock <IMediator>();
            MessageHandlerContext       = new Mock <IMessageHandlerContext>();
            LegacyTopicMessagePublisher = new Mock <ILegacyTopicMessagePublisher>();

            Sut = new ApprovedCohortReturnedToProviderEventHandler(Mediator.Object, LegacyTopicMessagePublisher.Object, Mock.Of <ILogger <ApprovedCohortReturnedToProviderEventHandler> >());
            ApprovedCohortReturnedToProviderEvent = autoFixture.Create <ApprovedCohortReturnedToProviderEvent>();

            GetCohortSummaryQueryResult = autoFixture.Build <GetCohortSummaryQueryResult>().Create();

            Mediator.Setup(x => x.Send(It.IsAny <GetCohortSummaryQuery>(),
                                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(GetCohortSummaryQueryResult);
        }
Beispiel #7
0
        private async Task SendEmployerEmail(IMessageHandlerContext context, GetCohortSummaryQueryResult cohortSummary)
        {
            var tokens = new Dictionary <string, string>
            {
                { "provider_name", cohortSummary.ProviderName },
                { "employer_hashed_account", _encodingService.Encode(cohortSummary.AccountId, EncodingType.AccountId) },
                { "cohort_reference", _encodingService.Encode(cohortSummary.CohortId, EncodingType.CohortReference) }
            };

            var templateName = cohortSummary.LevyStatus == Types.ApprenticeshipEmployerType.Levy
                ? TemplateApproveNewEmployerDetailsLevy
                : TemplateApproveNewEmployerDetailsNonLevy;

            await context.Send(new SendEmailToEmployerCommand(cohortSummary.AccountId,
                                                              templateName,
                                                              tokens));

            _logger.LogInformation($"Sent SendEmailToEmployerCommand with template: {templateName}");
        }
Beispiel #8
0
        private async Task SendProviderEmail(CohortWithChangeOfPartyCreatedEvent message, IMessageHandlerContext context, GetCohortSummaryQueryResult cohortSummary)
        {
            var changeOfPartyRequest = await _dbContext.Value.GetChangeOfPartyRequestAggregate(message.ChangeOfPartyRequestId, default);

            var apprenticeNamePossessive = await GetApprenticeNamePossessive(changeOfPartyRequest.ApprenticeshipId);

            var tokens = new Dictionary <string, string>
            {
                { "Subject", $"{cohortSummary.LegalEntityName} {(cohortSummary.IsCompleteForEmployer ? "has added details for you to review" : "has requested that you add details on their behalf")}" },
                { "TrainingProviderName", cohortSummary.ProviderName },
                { "EmployerName", cohortSummary.LegalEntityName },
                { "ApprenticeNamePossessive", apprenticeNamePossessive },
                { "RequestUrl", $"{cohortSummary.ProviderId}/apprentices/{cohortSummary.CohortReference}/details" }
            };

            await context.Send(new SendEmailToProviderCommand(cohortSummary.ProviderId.Value, "ProviderApprenticeshipChangeOfProviderRequested", tokens));

            _logger.LogInformation($"Sent SendEmailToProviderCommand with template: ProviderApprenticeshipChangeOfProviderRequested");
        }