public async Task SendCreateCommitmentNotification(CommitmentView commitment) { if (!_configuration.CommitmentNotification.SendEmail) { Logger.Info("Sending email notifications disabled by config."); return; } var emailMessage = new EmailMessage { TemplateId = "CreateCommitmentNotification", Tokens = new Dictionary <string, string> { { "cohort_reference", commitment.Reference }, { "employer_name", commitment.LegalEntityName }, { "ukprn", commitment.ProviderId.ToString() } } }; Logger.Info($"Sending email to all provider recipients for Provider {commitment.ProviderId}, template {emailMessage.TemplateId}"); await _providerEmailService.SendEmailToAllProviderRecipients( commitment.ProviderId.GetValueOrDefault(), commitment.ProviderLastUpdateInfo?.EmailAddress ?? string.Empty, emailMessage); }
private async Task AssertAutoReservationEnabled(CommitmentView commitment) { if (!await _reservationsService.IsAutoReservationEnabled(commitment.EmployerAccountId, commitment.TransferSender?.Id)) { throw new HttpException((int)HttpStatusCode.Forbidden, "Current account is not authorized for automatic reservations"); } }
public void ThenShouldLogInfoForMissingFields(string header) { var logger = new Mock <IProviderCommitmentsLogger>(); logger.Setup(x => x.Info(It.IsAny <string>(), It.IsAny <long?>(), It.IsAny <long?>(), It.IsAny <long?>())).Verifiable(); logger.Setup(x => x.Error(It.IsAny <Exception>(), It.IsAny <string>(), It.IsAny <long?>(), It.IsAny <long?>(), It.IsAny <long?>())).Verifiable(); var commitment = new CommitmentView { Id = 456 }; _sut = new BulkUploadFileParser(logger.Object); var inputData = $"{header}" + @" Abba123,1113335559,Froberg,Chris,1998-12-08,SE123321C,25,,,2,2120-08,2125-08,1500,,Employer ref,Provider ref"; _file = new Mock <HttpPostedFileBase>(); _file.Setup(m => m.FileName).Returns("APPDATA-20051030-213855.csv"); _file.Setup(m => m.ContentLength).Returns(inputData.Length); var textStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(inputData)); _file.Setup(m => m.InputStream).Returns(textStream); var result = _sut.CreateViewModels(123, commitment, inputData); var errors = result.Errors.ToList(); Assert.AreEqual(1, errors.Count); Assert.AreEqual("Some mandatory fields are incomplete. Please check your file and upload again.", errors.First().Message); logger.Verify(x => x.Info(It.IsAny <string>(), It.IsAny <long?>(), It.IsAny <long?>(), It.IsAny <long?>()), Times.Once); logger.Verify(x => x.Error(It.IsAny <Exception>(), It.IsAny <string>(), It.IsAny <long?>(), It.IsAny <long?>(), It.IsAny <long?>()), Times.Never); }
public async Task SendSenderApprovedOrRejectedCommitmentNotification(CommitmentView commitment, Commitments.Api.Types.TransferApprovalStatus newTransferApprovalStatus) { if (!_configuration.CommitmentNotification.SendEmail) { Logger.Info("Sending email notifications disabled by config."); return; } Logger.Info($"Sending notification to provider {commitment.ProviderId} that sender has {newTransferApprovalStatus} cohort {commitment.Id}"); var tokens = new Dictionary <string, string> { { "cohort_reference", commitment.Reference }, { "ukprn", commitment.ProviderId.ToString() } }; await _providerEmailService.SendEmailToAllProviderRecipients( commitment.ProviderId.GetValueOrDefault(), commitment.ProviderLastUpdateInfo?.EmailAddress ?? string.Empty, new EmailMessage { TemplateId = GenerateSenderApprovedOrRejectedTemplateId(newTransferApprovalStatus, RecipientType.Provider), Tokens = tokens }); }
private void AssertIsNotChangeOfParty(CommitmentView commitment) { if (commitment.IsLinkedToChangeOfPartyRequest) { throw new HttpException((int)HttpStatusCode.Forbidden, "Cohort is linked to a ChangeOfParty Request - apprentices cannot be added to it"); } }
private ApprenticeshipUploadModel MapTo(CsvRecord record, CommitmentView commitment) { var dateOfBirth = GetValidDate(record.DateOfBirth, "yyyy-MM-dd"); var learnerStartDate = GetValidDate(record.StartDate, "yyyy-MM"); var learnerEndDate = GetValidDate(record.EndDate, "yyyy-MM"); var courseCode = record.ProgType == "25" ? record.StdCode : $"{record.FworkCode}-{record.ProgType}-{record.PwayCode}"; var apprenticeshipViewModel = new ApprenticeshipViewModel { AgreementStatus = AgreementStatus.NotAgreed, PaymentStatus = PaymentStatus.Active, ULN = record.ULN, FirstName = record.GivenNames, LastName = record.FamilyName, DateOfBirth = new DateTimeViewModel(dateOfBirth), Cost = record.TotalPrice, ProviderRef = record.ProviderRef, StartDate = new DateTimeViewModel(learnerStartDate), EndDate = new DateTimeViewModel(learnerEndDate), ProgType = record.ProgType.TryParse(), CourseCode = courseCode, IsPaidForByTransfer = commitment.IsTransfer() }; return(new ApprenticeshipUploadModel { ApprenticeshipViewModel = apprenticeshipViewModel, CsvRecord = record }); }
public void Arrange() { _commitmentView = new CommitmentView { EditStatus = EditStatus.ProviderOnly, AgreementStatus = AgreementStatus.NotAgreed }; _mediator = new Mock <IMediator>(); _mediator.Setup(x => x.Send(It.IsAny <GetCommitmentQueryRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(() => new GetCommitmentQueryResponse { Commitment = _commitmentView }); _reservationsService = new Mock <IReservationsService>(); _reservationsService.Setup(rs => rs.IsAutoReservationEnabled(It.IsAny <long>(), It.IsAny <long?>())).ReturnsAsync(true); var bulkUploader = new BulkUploader(_mediator.Object, Mock.Of <IBulkUploadValidator>(), Mock.Of <IBulkUploadFileParser>(), Mock.Of <IProviderCommitmentsLogger>()); _bulkUploadOrchestrator = new BulkUploadOrchestrator( _mediator.Object, bulkUploader, Mock.Of <IHashingService>(), new BulkUploadMapper(_mediator.Object), Mock.Of <IProviderCommitmentsLogger>(), Mock.Of <IBulkUploadFileParser>(), _reservationsService.Object ); }
public void Arrange() { _commitmentView = new CommitmentView(); _commitmentsApi = new Mock <IEmployerCommitmentApi>(); _commitmentsApi.Setup(x => x.GetEmployerApprenticeship(It.IsAny <long>(), It.IsAny <long>())) .ReturnsAsync(new Apprenticeship()); _commitmentsApi.Setup(x => x.GetEmployerCommitment(It.IsAny <long>(), It.IsAny <long>())) .ReturnsAsync(_commitmentView); _commitmentsApi.Setup(x => x.DeleteEmployerApprenticeship(It.IsAny <long>(), It.IsAny <long>(), It.IsAny <DeleteRequest>())) .Returns(Task.FromResult <object>(null)); _providerEmailNotificationService = new Mock <IProviderEmailNotificationService>(); _providerEmailNotificationService .Setup(x => x.SendProviderTransferRejectedCommitmentEditNotification(It.IsAny <CommitmentView>())) .Returns(() => Task.CompletedTask); _validator = new Mock <IValidator <DeleteApprenticeshipCommand> >(); _validator.Setup(x => x.Validate(It.IsAny <DeleteApprenticeshipCommand>())) .Returns(new ValidationResult()); _handler = new DeleteApprenticeshipCommandHandler(_commitmentsApi.Object, _validator.Object, _providerEmailNotificationService.Object); }
public void Setup() { _validCommand = new SubmitCommitmentCommand { EmployerAccountId = 12L, CommitmentId = 2L, UserDisplayName = "Test User", UserEmailAddress = "*****@*****.**", UserId = "externalUserId" }; _repositoryCommitment = new CommitmentView { ProviderId = 456L, EmployerAccountId = 12L, AgreementStatus = AgreementStatus.NotAgreed, Reference = CohortReference }; _mockCommitmentApi = new Mock <IEmployerCommitmentApi>(); _mockCommitmentApi.Setup(x => x.GetEmployerCommitment(It.IsAny <long>(), It.IsAny <long>())) .ReturnsAsync(_repositoryCommitment); var config = new EmployerCommitmentsServiceConfiguration { CommitmentNotification = new CommitmentNotificationConfiguration { SendEmail = true } }; _mockEmailService = new Mock <IProviderEmailService>(); _handler = new SubmitCommitmentCommandHandler(_mockCommitmentApi.Object, config, Mock.Of <ILog>(), _mockEmailService.Object); }
public void Setup() { _validCommand = new SubmitCommitmentCommand { EmployerAccountId = 12L, CommitmentId = 2L, UserDisplayName = "Test User", UserEmailAddress = "*****@*****.**", UserId = "externalUserId" }; _repositoryCommitment = new CommitmentView { ProviderId = 456L, EmployerAccountId = 12L, AgreementStatus = AgreementStatus.NotAgreed }; _mockCommitmentApi = new Mock <IEmployerCommitmentApi>(); _mockCommitmentApi.Setup(x => x.GetEmployerCommitment(It.IsAny <long>(), It.IsAny <long>())) .ReturnsAsync(_repositoryCommitment); _mockMediator = new Mock <IMediator>(); var config = new EmployerApprenticeshipsServiceConfiguration { CommitmentNotification = new CommitmentNotificationConfiguration { SendEmail = true } }; _mockEmailLookup = new Mock <IProviderEmailLookupService>(); _mockEmailLookup.Setup(m => m.GetEmailsAsync(It.IsAny <long>(), It.IsAny <string>())).ReturnsAsync(new List <string>()); _handler = new SubmitCommitmentCommandHandler(_mockCommitmentApi.Object, _mockMediator.Object, config, _mockEmailLookup.Object, Mock.Of <ILogger>()); }
public void Arrange() { _configuration = new EmployerCommitmentsServiceConfiguration { CommitmentNotification = new CommitmentNotificationConfiguration { SendEmail = true } }; _providerEmailService = new Mock <IProviderEmailService>(); _providerEmailService.Setup(x => x.SendEmailToAllProviderRecipients(It.IsAny <long>(), It.IsAny <string>(), It.IsAny <EmailMessage>())) .Callback <long, string, EmailMessage>((l, s, m) => _sentEmailMessage = m) .Returns(Task.CompletedTask); _providerEmailNotificationService = new ProviderEmailNotificationService(_providerEmailService.Object, Mock.Of <ILog>(), Mock.Of <IHashingService>(), _configuration); _exampleCommitmentView = new CommitmentView { ProviderId = 1, ProviderLastUpdateInfo = new LastUpdateInfo { EmailAddress = "LastUpdateEmail" }, LegalEntityName = "Legal Entity Name", Reference = "Cohort Reference" }; _act = async() => await _providerEmailNotificationService.SendProviderTransferRejectedCommitmentEditNotification( _exampleCommitmentView); }
public void OfApprovedApprenticeshipThenIsEndDateLockedForUpdateShouldBeSetCorrectly(bool expected, bool unchanged, bool dataLockSuccess, bool isStartDateInFuture, bool isAfterLastAcademicYearFundingPeriod, AcademicYearValidationResult academicYearValidationResult) { AcademicYearValidator.Setup(m => m.IsAfterLastAcademicYearFundingPeriod).Returns(isAfterLastAcademicYearFundingPeriod); AcademicYearValidator.Setup(m => m.Validate(It.IsAny <DateTime>())).Returns(academicYearValidationResult); var apprenticeship = new Apprenticeship { PaymentStatus = PaymentStatus.Active, HasHadDataLockSuccess = dataLockSuccess, StartDate = _now.AddMonths(isStartDateInFuture ? 1 : -1) }; var commitment = new CommitmentView { AgreementStatus = AgreementStatus.BothAgreed }; var viewModel = Sut.MapToApprenticeshipViewModel(apprenticeship, commitment); Assert.AreEqual(expected, viewModel.IsEndDateLockedForUpdate); if (unchanged) { Assert.AreEqual(viewModel.IsLockedForUpdate, viewModel.IsEndDateLockedForUpdate); } }
public void ThenShouldNotLogInfoWhenNoHeaderRecord() { var logger = new Mock <IProviderCommitmentsLogger>(); logger.Setup(x => x.Info(It.IsAny <string>(), It.IsAny <long?>(), It.IsAny <long?>(), It.IsAny <long?>())).Verifiable(); logger.Setup(x => x.Error(It.IsAny <Exception>(), It.IsAny <string>(), It.IsAny <long?>(), It.IsAny <long?>(), It.IsAny <long?>())).Verifiable(); var commitment = new CommitmentView { Id = 456 }; _sut = new BulkUploadFileParser(logger.Object); var builder = new StringBuilder(); builder.AppendLine(Environment.NewLine); builder.AppendLine("Abba123,1113335559,Froberg,Chris,1998-12-08,SE123321C,25,,,2,2120-08,2125-08,1500,,Employer ref,Provider ref"); var inputData = builder.ToString(); _file = new Mock <HttpPostedFileBase>(); _file.Setup(m => m.FileName).Returns("APPDATA-20051030-213855.csv"); _file.Setup(m => m.ContentLength).Returns(inputData.Length); var textStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(inputData)); _file.Setup(m => m.InputStream).Returns(textStream); var result = _sut.CreateViewModels(123, commitment, inputData); var errors = result.Errors.ToList(); Assert.AreEqual(0, errors.Count); Assert.AreEqual(0, result.Data.Count()); logger.Verify(x => x.Info(It.IsAny <string>(), It.IsAny <long?>(), It.IsAny <long?>(), It.IsAny <long?>()), Times.Never); logger.Verify(x => x.Error(It.IsAny <Exception>(), It.IsAny <string>(), It.IsAny <long?>(), It.IsAny <long?>(), It.IsAny <long?>()), Times.Never); }
public CommitmentViewModel MapToCommitmentViewModel(CommitmentView commitment) { return(new CommitmentViewModel { HashedId = _hashingService.HashValue(commitment.Id), Name = commitment.Reference, LegalEntityName = commitment.LegalEntityName, ProviderName = commitment.ProviderName }); }
public static RequestStatus GetStatus(this CommitmentView commitment) { return(StatusCalculator.GetStatus( commitment.EditStatus, commitment.Apprenticeships.Count, commitment.LastAction, commitment.AgreementStatus, commitment.TransferSender?.Id, commitment.TransferSender?.TransferApprovalStatus)); }
public BulkUploadResult CreateViewModels(long providerId, CommitmentView commitment, string fileContent) { var stopwatch = Stopwatch.StartNew(); var result = _parser.CreateViewModels(providerId, commitment, fileContent); _logger.Trace($"Took {stopwatch.ElapsedMilliseconds} milliseconds to create {result.Data?.Count()} viewmodels"); return(result); }
public void ThenApprenticeshipTypeOnApprovalIsMapped(ApprenticeshipEmployerType?apprenticeshipEmployerType) { var apprenticeship = new Apprenticeship(); var commitment = new CommitmentView { ApprenticeshipEmployerTypeOnApproval = apprenticeshipEmployerType }; var viewModel = Sut.MapToApprenticeshipViewModel(apprenticeship, commitment); Assert.AreEqual(commitment.ApprenticeshipEmployerTypeOnApproval, viewModel.ApprenticeshipEmployerTypeOnApproval); }
public void CreatingViewModels() { var commitment = new CommitmentView { Id = 456 }; var records = _sut.CreateViewModels(123, commitment, _testData); records.Data.Count().Should().Be(8); records.Errors.Should().NotBeNull(); records.Errors.Should().BeEmpty(); }
protected static void AssertCommitmentStatus(CommitmentView commitment, params EditStatus[] allowedEditStatuses) { if (commitment == null) { throw new InvalidStateException("Null commitment"); } if (!allowedEditStatuses.Contains(commitment.EditStatus)) { throw new InvalidStateException($"Invalid commitment state (edit status is {commitment.EditStatus}, expected {string.Join(",", allowedEditStatuses)})"); } }
public void ShouldHaveTransferFlagSetIfCommitmentHasTransferSender() { var apprenticeship = new Apprenticeship { StartDate = _now.AddMonths(+1), HasHadDataLockSuccess = false }; var commitment = new CommitmentView { TransferSender = new TransferSender { Id = 123 } }; var viewModel = Sut.MapToApprenticeshipViewModel(apprenticeship, commitment); viewModel.IsPaidForByTransfer.Should().BeTrue(); }
public void ThenCohortTransferRejectionIsIndicated(TransferApprovalStatus status, bool expectRejectionIndicated) { var apprenticeship = new Apprenticeship(); var commitment = new CommitmentView { TransferSender = new TransferSender { TransferApprovalStatus = status } }; var viewModel = Sut.MapToApprenticeshipViewModel(apprenticeship, commitment); Assert.AreEqual(expectRejectionIndicated, viewModel.IsInTransferRejectedCohort); }
public override void SetUp() { _commitment = new CommitmentView { Messages = new List <MessageView>() }; _mockMediator.Setup(x => x.Send(It.IsAny <GetCommitmentQueryRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(() => new GetCommitmentQueryResponse { Commitment = _commitment }); base.SetUp(); }
public void ShouldHaveLockedStatusIfApprovedTransferFundedWithSuccessfulIlrSubmissionAndCourseNotYetStarted() { var apprenticeship = new Apprenticeship { StartDate = _now.AddMonths(3), HasHadDataLockSuccess = true, PaymentStatus = PaymentStatus.Active }; var commitment = new CommitmentView { TransferSender = new TransferSender { TransferApprovalStatus = TransferApprovalStatus.Approved } }; var viewModel = Sut.MapToApprenticeshipViewModel(apprenticeship, commitment); viewModel.IsLockedForUpdate.Should().BeTrue(); viewModel.IsEndDateLockedForUpdate.Should().BeTrue(); }
private async Task SendNotifications(CommitmentView commitment, Commitments.Api.Types.TransferApprovalStatus newTransferApprovalStatus) { //todo: we should probably also check this in EmployerEmailNotificationService // (ProviderEmailNotificationService uses ProviderEmailService, which checks it) // or in defaultregistry we could supply no-op implementations for XxxEmailNotificationService when SendEmail is disabled if (!_configuration.CommitmentNotification.SendEmail) { _logger.Info("Sending email notifications disabled by config."); return; } var providerNotifyTask = _providerEmailNotificationService.SendSenderApprovedOrRejectedCommitmentNotification(commitment, newTransferApprovalStatus); var employerNotifyTask = _employerEmailNotificationService.SendSenderApprovedOrRejectedCommitmentNotification(commitment, newTransferApprovalStatus); await Task.WhenAll(providerNotifyTask, employerNotifyTask); }
public void Arrange() { _commitmentView = new CommitmentView(); _employerCommitmentApi = new Mock <IEmployerCommitmentApi>(); _employerCommitmentApi.Setup(x => x.GetEmployerCommitment(It.IsAny <long>(), It.IsAny <long>())) .ReturnsAsync(_commitmentView); _employerCommitmentApi.Setup(x => x.GetTransferSenderCommitment(It.IsAny <long>(), It.IsAny <long>())) .ReturnsAsync(_commitmentView); _query = new GetCommitmentQueryRequest { AccountId = ExpectedAccountId, CommitmentId = ExpectedCommitmentId }; _requestHandler = new GetCommitmentQueryHandler(_employerCommitmentApi.Object); }
public void ThenIsUpdateLockedForStartDateAndCourseShouldBeSetCorrectly(bool expected, bool dataLockSuccess, bool transferSender, TransferApprovalStatus?transferApprovalStatus) { var apprenticeship = new Apprenticeship { HasHadDataLockSuccess = dataLockSuccess, PaymentStatus = PaymentStatus.Active }; var commitment = new CommitmentView(); if (transferSender) { commitment.TransferSender = new TransferSender { TransferApprovalStatus = transferApprovalStatus }; } var viewModel = _mapper.MapApprenticeship(apprenticeship, commitment); Assert.AreEqual(expected, viewModel.IsUpdateLockedForStartDateAndCourse); }
public async Task ShouldReturnLegalEntityIdInPublicHashedFormatButNoTransferId() { var commitment = new CommitmentView { EmployerAccountId = 1L, AccountLegalEntityPublicHashedId = "X1X" }; _mockMediator.Setup(x => x.Send(It.IsAny <GetCommitmentQueryRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new GetCommitmentQueryResponse { Commitment = commitment }); var result = await _orchestrator.GetHashedIdsFromCommitment(1L, "ABBA123"); result.HashedLegalEntityId.Should().Be("X1X"); result.HashedTransferSenderId.Should().BeNull(); }
private async Task SendNotification(CommitmentView commitment, SubmitCommitmentCommand message) { _logger.Info($"Sending notification for commitment {commitment.Id} to providers with ukprn {commitment.ProviderId}"); var tokens = new Dictionary <string, string> { { "cohort_reference", commitment.Reference } }; string templateId; switch (commitment.AgreementStatus) { case AgreementStatus.NotAgreed when commitment.TransferSender != null: templateId = "TransferProviderCommitmentNotification"; tokens["receiving_employer"] = commitment.LegalEntityName; break; case AgreementStatus.NotAgreed: templateId = "ProviderCommitmentNotification"; tokens["type"] = message.LastAction == LastAction.Approve ? "approval" : "review"; break; case AgreementStatus.ProviderAgreed when commitment.TransferSender != null && message.LastAction == LastAction.Approve: templateId = "TransferPendingFinalApproval"; tokens["ukprn"] = commitment.ProviderId.ToString(); tokens["receiving_employer"] = commitment.LegalEntityName; break; default: templateId = "ProviderCohortApproved"; break; } var emailMessage = new EmailMessage { TemplateId = templateId, Tokens = tokens }; await _providerEmailService.SendEmailToAllProviderRecipients( commitment.ProviderId.GetValueOrDefault(), commitment.ProviderLastUpdateInfo?.EmailAddress ?? string.Empty, emailMessage); }
private SendNotificationCommand BuildNotificationCommand(string email, CommitmentView commitment, LastAction action, string userDisplayName) { return(new SendNotificationCommand { Email = new Email { RecipientsAddress = email, TemplateId = commitment.AgreementStatus == AgreementStatus.NotAgreed ? "ProviderCommitmentNotification" : "ProviderCohortApproved", ReplyToAddress = "*****@*****.**", Subject = "x", SystemId = "x", Tokens = new Dictionary <string, string> { { "type", action == LastAction.Approve ? "approval" : "review" }, { "cohort_reference", commitment.Reference }, { "first_name", userDisplayName } } } }); }
public BulkUploadResult CreateViewModels(long providerId, CommitmentView commitment, string fileInput) { const string errorMessage = "Upload failed. Please check your file and try again."; using (var tr = new StringReader(fileInput)) { try { var csvReader = new CsvReader(tr); csvReader.Configuration.HasHeaderRecord = true; csvReader.Configuration.IsHeaderCaseSensitive = false; csvReader.Configuration.ThrowOnBadData = true; csvReader.Configuration.RegisterClassMap <CsvRecordMap>(); return(new BulkUploadResult { Data = csvReader.GetRecords <CsvRecord>() .ToList() .Select(record => MapTo(record, commitment)) }); } catch (CsvMissingFieldException) { _logger.Info("Failed to process bulk upload file (missing field).", providerId, commitment.Id); return(new BulkUploadResult { Errors = new List <UploadError> { new UploadError("Some mandatory fields are incomplete. Please check your file and upload again.") } }); } catch (Exception) { _logger.Info("Failed to process bulk upload file.", providerId, commitment.Id); return(new BulkUploadResult { Errors = new List <UploadError> { new UploadError(errorMessage) } }); } } }