public async Task Then_learner_details_are_retrieved(int pageNumber)
        {
            // Arrange
            var providerMessage = new RefreshIlrsProviderMessage
            {
                Source            = "1920",
                Ukprn             = UkprnThree,
                LearnerPageNumber = pageNumber
            };


            // Act
            await Sut.ProcessLearners(providerMessage);

            // Assert
            var optionsLearnerFundModels = ConfigurationHelper.ConvertCsvValueToList <int>(Options.Object.Value.LearnerFundModels);

            DataCollectionServiceApiClient.Verify(
                v => v.GetLearners(
                    "1920",
                    UkprnThree,
                    1,
                    -1,
                    It.Is <List <int> >(p => Enumerable.SequenceEqual(p, optionsLearnerFundModels)),
                    -1,
                    Options.Object.Value.LearnerPageSize,
                    pageNumber),
                Times.Once);
        }
        private async Task <List <RefreshIlrsProviderMessage> > QueueProviders(string source, DateTime lastRunDateTime)
        {
            var providerMessagesToQueue = new List <RefreshIlrsProviderMessage>();
            var pageSize = _refreshIlrsOptions.ProviderPageSize;

            var providersPage = await _dataCollectionServiceApiClient.GetProviders(source, lastRunDateTime, pageSize, pageNumber : 1);

            if (providersPage != null && providersPage.PagingInfo.TotalItems > 0)
            {
                do
                {
                    foreach (var providerUkprn in providersPage.Providers)
                    {
                        var message = new RefreshIlrsProviderMessage
                        {
                            Ukprn             = providerUkprn,
                            Source            = source,
                            LearnerPageNumber = 1
                        };

                        providerMessagesToQueue.Add(message);
                    }

                    // each subsequent page will be retrieved; any data which has changed during paging which would be contained
                    // on a previously retrieved page will be proceseed on a subsequent run; any data which has changed during paging
                    // which would be contained on a subsequent page will be duplicated on a subsequent run;
                    providersPage = await _dataCollectionServiceApiClient.GetProviders(source, lastRunDateTime, pageSize, providersPage.PagingInfo.PageNumber + 1);
                }while (providersPage != null && providersPage.PagingInfo.PageNumber <= providersPage.PagingInfo.TotalPages);
            }

            return(providerMessagesToQueue);
        }
示例#3
0
        private async Task <RefreshIlrsProviderMessage> ExportLearnerDetails(RefreshIlrsProviderMessage providerMessage)
        {
            RefreshIlrsProviderMessage nextPageProviderMessage = null;

            var aimType      = 1;
            var allStandards = -1;
            var fundModels   = ConfigurationHelper.ConvertCsvValueToList <int>(_refreshIlrsOptions.LearnerFundModels);
            var allProgTypes = -1;
            var pageSize     = _refreshIlrsOptions.LearnerPageSize;

            var learnersPage = await _dataCollectionServiceApiClient.GetLearners(providerMessage.Source, providerMessage.Ukprn, aimType, allStandards, fundModels, allProgTypes, pageSize, providerMessage.LearnerPageNumber);

            if (learnersPage != null)
            {
                if (learnersPage.PagingInfo.TotalPages > learnersPage.PagingInfo.PageNumber)
                {
                    // queue a new message to process the next page
                    nextPageProviderMessage = new RefreshIlrsProviderMessage
                    {
                        Ukprn             = providerMessage.Ukprn,
                        Source            = providerMessage.Source,
                        LearnerPageNumber = providerMessage.LearnerPageNumber + 1
                    };
                }

                // the learners must be filtered to remove learning deliveries which do not match the filters as the
                // data collection API returns learners which have at least one learning delivery matching a filter,
                // but it then returns ALL learning deliveries for each matching learner
                var filteredLearners = FilterLearners(learnersPage.Learners, providerMessage.Source, aimType, fundModels);
                if (filteredLearners.Count > 0)
                {
                    ImportLearnerDetailRequest request = new ImportLearnerDetailRequest
                    {
                        ImportLearnerDetails = filteredLearners
                    };

                    var response = await _assessorServiceApiClient.ImportLearnerDetails(request);

                    var totalErrorsInResponse = response?.LearnerDetailResults?.Sum(e => e.Errors?.Count ?? 0);
                    if (totalErrorsInResponse > 0)
                    {
                        _logger.LogInformation($"Request to import {request.ImportLearnerDetails.Count} learner details resulted in {totalErrorsInResponse} error(s)");
                    }

                    response?.LearnerDetailResults?.ForEach(ld =>
                    {
                        if ((ld.Errors?.Count ?? 0) > 0)
                        {
                            _logger.LogDebug($"Request to import learner details (Uln:{ld.Uln},StdCode:{ld.StdCode}) failed due to '{ld.Outcome}' '{string.Join(", ", ld?.Errors)}'");
                        }
                    });
                }
            }

            return(nextPageProviderMessage);
        }
示例#4
0
 public async Task <RefreshIlrsProviderMessage> ProcessLearners(RefreshIlrsProviderMessage providerMessage)
 {
     try
     {
         return(await ExportLearnerDetails(providerMessage));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, $"Refresh Ilrs for Ukprn {providerMessage.Ukprn}, process learners failed for '{providerMessage.Source}' on page {providerMessage.LearnerPageNumber} ");
         throw;
     }
 }
        public async Task Then_learner_details_import_request_is_sent_to_assessor()
        {
            // Arrange
            var providerMessage = new RefreshIlrsProviderMessage
            {
                Source            = "1920",
                Ukprn             = UkprnThree,
                LearnerPageNumber = 1
            };

            // Act
            await Sut.ProcessLearners(providerMessage);

            // Assert
            AssertLearnerDetailRequest(UkprnThreeOne);
        }
        public async Task Then_subsequent_page_provider_is_returned(int pageNumber, bool subsequentPageReturned)
        {
            // Arrange
            var providerMessage = new RefreshIlrsProviderMessage
            {
                Source            = "1920",
                Ukprn             = UkprnFour,
                LearnerPageNumber = pageNumber
            };

            // Act
            var nextPageProviderMessage = await Sut.ProcessLearners(providerMessage);

            // Assert
            nextPageProviderMessage.Should().Match(p => subsequentPageReturned && p != null || !subsequentPageReturned && p == null);
        }