public void Arrange() { BaseArrange(); ImportLearnerDetail = CreateImportLearnerDetail(44444); _secondImportLearnerDetail = CreateImportLearnerDetail(55555); }
private ImportLearnerDetailResult CheckMissingMandatoryFields(ImportLearnerDetail request) { _logger.LogDebug("Handling Import Learner Detail Request - Checking for missing mandatory fields"); var result = new ImportLearnerDetailResult { Uln = request.Uln, StdCode = request.StdCode, Outcome = "ErrorMissingMandatoryField", Errors = new List <string>() }; AddMissingMandatoryFieldError(result, request.Source, nameof(request.Source)); AddMissingMandatoryFieldError(result, request.Ukprn, nameof(request.Ukprn)); AddMissingMandatoryFieldError(result, request.Uln, nameof(request.Uln)); AddMissingMandatoryFieldError(result, request.StdCode, nameof(request.StdCode)); AddMissingMandatoryFieldError(result, request.FundingModel, nameof(request.FundingModel)); AddMissingMandatoryFieldError(result, request.GivenNames, nameof(request.GivenNames)); AddMissingMandatoryFieldError(result, request.FamilyName, nameof(request.FamilyName)); AddMissingMandatoryFieldError(result, request.LearnStartDate, nameof(request.LearnStartDate)); AddMissingMandatoryFieldError(result, request.PlannedEndDate, nameof(request.PlannedEndDate)); AddMissingMandatoryFieldError(result, request.CompletionStatus, nameof(request.CompletionStatus)); AddMissingMandatoryFieldError(result, request.LearnRefNumber, nameof(request.LearnRefNumber)); AddMissingMandatoryFieldError(result, request.DelLocPostCode, nameof(request.DelLocPostCode)); return(result.Errors.Count > 0 ? result : null); }
private async Task <string> UpdateIlrRecord(ImportLearnerDetail importLearnerDetail, bool isUpdate, Ilr currentLearner = null) { _logger.LogDebug("Handling Import Learner Detail Request - Update Ilr"); // for an update to certain fields if the request is null then the currrent value will be // retained, otherwise the request value will be used await _ilrRepository.Update(new Ilr { Source = importLearnerDetail.Source, UkPrn = importLearnerDetail.Ukprn.Value, Uln = importLearnerDetail.Uln.Value, StdCode = importLearnerDetail.StdCode.Value, FundingModel = importLearnerDetail.FundingModel, GivenNames = importLearnerDetail.GivenNames, FamilyName = importLearnerDetail.FamilyName, EpaOrgId = RetainCurrentValueForNullUpdate(currentLearner?.EpaOrgId, importLearnerDetail.EpaOrgId, isUpdate), LearnStartDate = importLearnerDetail.LearnStartDate.Value, PlannedEndDate = importLearnerDetail.PlannedEndDate, CompletionStatus = importLearnerDetail.CompletionStatus, LearnRefNumber = importLearnerDetail.LearnRefNumber, DelLocPostCode = importLearnerDetail.DelLocPostCode, LearnActEndDate = RetainCurrentValueForNullUpdate(currentLearner?.LearnActEndDate, importLearnerDetail.LearnActEndDate, isUpdate), WithdrawReason = RetainCurrentValueForNullUpdate(currentLearner?.WithdrawReason, importLearnerDetail.WithdrawReason, isUpdate), Outcome = RetainCurrentValueForNullUpdate(currentLearner?.Outcome, importLearnerDetail.Outcome, isUpdate), AchDate = RetainCurrentValueForNullUpdate(currentLearner?.AchDate, importLearnerDetail.AchDate, isUpdate), OutGrade = RetainCurrentValueForNullUpdate(currentLearner?.OutGrade, importLearnerDetail.OutGrade, isUpdate) }); return($"{(isUpdate ? "Updated" : "Replaced")}LearnerDetail"); }
private async Task <string> CreateIlrRecord(ImportLearnerDetail importLearnerDetail) { _logger.LogDebug("Handling Import Learner Detail Request - Create Ilr"); await _ilrRepository.Create(new Ilr { Source = importLearnerDetail.Source, UkPrn = importLearnerDetail.Ukprn.Value, Uln = importLearnerDetail.Uln.Value, StdCode = importLearnerDetail.StdCode.Value, FundingModel = importLearnerDetail.FundingModel, GivenNames = importLearnerDetail.GivenNames, FamilyName = importLearnerDetail.FamilyName, EpaOrgId = importLearnerDetail.EpaOrgId, LearnStartDate = importLearnerDetail.LearnStartDate.Value, PlannedEndDate = importLearnerDetail.PlannedEndDate, CompletionStatus = importLearnerDetail.CompletionStatus, LearnRefNumber = importLearnerDetail.LearnRefNumber, DelLocPostCode = importLearnerDetail.DelLocPostCode, LearnActEndDate = importLearnerDetail.LearnActEndDate, WithdrawReason = importLearnerDetail.WithdrawReason, Outcome = importLearnerDetail.Outcome, AchDate = importLearnerDetail.AchDate, OutGrade = importLearnerDetail.OutGrade }); return("CreatedLearnerDetail"); }
private async Task <string> HandleSameSourceRequest(Ilr learner, ImportLearnerDetail importLearnerDetail, CancellationToken cancellationToken) { if (importLearnerDetail.Ukprn == learner.UkPrn) { if (importLearnerDetail.LearnActEndDate != null && importLearnerDetail.LearnStartDate == importLearnerDetail.LearnActEndDate) { return("IgnoreLearnActEndDateSameAsLearnStartDate"); } if (importLearnerDetail.PlannedEndDate == learner.PlannedEndDate && importLearnerDetail.LearnStartDate == learner.LearnStartDate) { return(await UpdateIlrRecord(importLearnerDetail, true, learner)); } if (importLearnerDetail.LearnStartDate > learner.LearnStartDate) { return(await UpdateIlrRecord(importLearnerDetail, false)); } } else { var certificate = await _certificateRepository.GetCertificate(importLearnerDetail.Uln.Value, importLearnerDetail.StdCode.Value); if (certificate != null) { return("IgnoreUkprnChangedButCertficateAlreadyExists"); } if (importLearnerDetail.FundingModel == 99 && learner.FundingModel != 99) { return("IgnoreFundingModelChangedTo99WhenPrevioulsyNot99"); } if (importLearnerDetail.LearnActEndDate == null && learner.LearnActEndDate != null) { return(await UpdateIlrRecord(importLearnerDetail, false)); } if (importLearnerDetail.LearnActEndDate != null && importLearnerDetail.PlannedEndDate > learner.PlannedEndDate) { return(await UpdateIlrRecord(importLearnerDetail, false)); } if (importLearnerDetail.LearnStartDate > learner.LearnStartDate) { return(await UpdateIlrRecord(importLearnerDetail, false)); } } return("IgnoreOutOfDate"); }
private async Task <string> HandleRequest(ImportLearnerDetail importLearnerDetail, CancellationToken cancellationToken) { if (importLearnerDetail.Uln == 9999999999 || importLearnerDetail.Uln == 1000000000) { return("IgnoreUlnDummyValue"); } var learner = await _ilrRepository.Get(importLearnerDetail.Uln.Value, importLearnerDetail.StdCode.Value); if (learner != null) { return(await HandleExistingLearnerRequest(learner, importLearnerDetail, cancellationToken)); } return(await CreateIlrRecord(importLearnerDetail)); }
private async Task <string> HandleExistingLearnerRequest(Ilr learner, ImportLearnerDetail importLearnerDetail, CancellationToken cancellationToken) { // the source represents an academic year which should be compared as a number var requestSource = int.Parse(importLearnerDetail.Source); var learnerSource = int.Parse(learner.Source); if (requestSource < learnerSource) { return("IgnoreSourcePriorToCurrentSource"); } else if (requestSource > learnerSource) { return(await UpdateIlrRecord(importLearnerDetail, false)); } return(await HandleSameSourceRequest(learner, importLearnerDetail, cancellationToken)); }
public void Arrange() { BaseArrange(); // Arrange ImportLearnerDetail = CreateImportLearnerDetail(4444, 44444444444, 44); SecondImportLearnerDetail = CreateImportLearnerDetail(5555, 55555555555, 55); Request = new ImportLearnerDetailRequest { ImportLearnerDetails = new List <ImportLearnerDetail> { ImportLearnerDetail, SecondImportLearnerDetail } }; }
protected void VerifyIlrReplaced(ImportLearnerDetail importLearnerDetail, Func <Times> times) { IlrRepository.Verify(r => r.Update(It.IsAny <Ilr>()), times); ModifiedIlr.Source.Should().Be(importLearnerDetail.Source); ModifiedIlr.UkPrn.Should().Be(importLearnerDetail.Ukprn.Value); ModifiedIlr.Uln.Should().Be(importLearnerDetail.Uln.Value); ModifiedIlr.StdCode.Should().Be(importLearnerDetail.StdCode.Value); ModifiedIlr.FundingModel.Should().Be(importLearnerDetail.FundingModel); ModifiedIlr.GivenNames.Should().Be(importLearnerDetail.GivenNames); ModifiedIlr.FamilyName.Should().Be(importLearnerDetail.FamilyName); ModifiedIlr.EpaOrgId.Should().Be(importLearnerDetail.EpaOrgId); ModifiedIlr.LearnStartDate.Should().Be(importLearnerDetail.LearnStartDate.Value); ModifiedIlr.PlannedEndDate.Should().Be(importLearnerDetail.PlannedEndDate); ModifiedIlr.CompletionStatus.Should().Be(importLearnerDetail.CompletionStatus); ModifiedIlr.LearnRefNumber.Should().Be(importLearnerDetail.LearnRefNumber); ModifiedIlr.DelLocPostCode.Should().Be(importLearnerDetail.DelLocPostCode); ModifiedIlr.LearnActEndDate.Should().Be(importLearnerDetail.LearnActEndDate); ModifiedIlr.WithdrawReason.Should().Be(importLearnerDetail.WithdrawReason); ModifiedIlr.Outcome.Should().Be(importLearnerDetail.Outcome); ModifiedIlr.AchDate.Should().Be(importLearnerDetail.AchDate); ModifiedIlr.OutGrade.Should().Be(importLearnerDetail.OutGrade); }
private async Task <string> HandleSameSourceRequest(Ilr learner, ImportLearnerDetail importLearnerDetail, CancellationToken cancellationToken) { if (importLearnerDetail.Ukprn == learner.UkPrn) { if (importLearnerDetail.LearnActEndDate != null && importLearnerDetail.LearnStartDate == importLearnerDetail.LearnActEndDate) { return("IgnoreLearnActEndDateSameAsLearnStartDate"); } if (importLearnerDetail.PlannedEndDate == learner.PlannedEndDate && importLearnerDetail.LearnStartDate == learner.LearnStartDate) { return(await UpdateIlrRecord(importLearnerDetail, true, learner)); } if (importLearnerDetail.LearnStartDate > learner.LearnStartDate) { return(await UpdateIlrRecord(importLearnerDetail, false)); } } else { var certificate = await _certificateRepository.GetCertificate(importLearnerDetail.Uln.Value, importLearnerDetail.StdCode.Value); if (certificate != null) { var ignore = true; if (certificate.Status == CertificateStatus.Deleted || certificate.Status == CertificateStatus.Draft) { ignore = false; } else { var certificateData = JsonConvert.DeserializeObject <CertificateData>(certificate.CertificateData); if (certificate.Status == CertificateStatus.Submitted && certificateData.OverallGrade == CertificateGrade.Fail) { ignore = false; } } if (ignore) { return("IgnoreUkprnChangedButCertficateAlreadyExists"); } } if (importLearnerDetail.FundingModel == 99 && learner.FundingModel != 99) { return("IgnoreFundingModelChangedTo99WhenPrevioulsyNot99"); } if (importLearnerDetail.LearnActEndDate == null && learner.LearnActEndDate != null) { return(await UpdateIlrRecord(importLearnerDetail, false)); } if (importLearnerDetail.LearnActEndDate != null && importLearnerDetail.PlannedEndDate > learner.PlannedEndDate) { return(await UpdateIlrRecord(importLearnerDetail, false)); } if (importLearnerDetail.LearnStartDate > learner.LearnStartDate) { return(await UpdateIlrRecord(importLearnerDetail, false)); } } return("IgnoreOutOfDate"); }