public ApprenticeshipTrainingSummary GetActiveApprenticeshipTrainingByProvider(long ukprn, int page) { var apprenticeshipTrainingSummary = new ApprenticeshipTrainingSummary { Ukprn = ukprn }; var apprenticeships = new List <ApprenticeshipTraining>(); apprenticeships.AddRange(GetActiveStandardsForUkprn(ukprn)); apprenticeships.AddRange(GetActiveFrameworksForUkprn(ukprn)); var totalCount = apprenticeships.Count; var pageSize = _applicationSettings.PageSizeApprenticeshipSummary; var paginationDetails = _paginationHelper.GeneratePaginationDetails(page, pageSize, totalCount); apprenticeshipTrainingSummary.PaginationDetails = paginationDetails; apprenticeshipTrainingSummary.ApprenticeshipTrainingItems = apprenticeships.OrderBy(x => x.Name) .ThenBy(x => x.Level) .Skip(paginationDetails.NumberOfRecordsToSkip) .Take(pageSize); return(apprenticeshipTrainingSummary); }
public void ShouldReturnActiveListOfProviderApprenticeshipsForUkprn() { const long ukprn = 10005214L; const int totalCount = 400; var apprenticeshipTraining = new ApprenticeshipTraining { Identifier = "321-1-1", Name = "Archeologist", TrainingType = ApprenticeshipTrainingType.Framework, Level = 3, Type = "Framework" }; var apprenticeshipTrainingList = new List <ApprenticeshipTraining> { apprenticeshipTraining }; const int numberPerPage = 20; const int numberReturned = 1; const int page = 2; const int lastPage = 37; var paginationDetails = new PaginationDetails { NumberPerPage = 20, Page = page, TotalCount = totalCount, LastPage = lastPage }; var expected = new ApprenticeshipTrainingSummary { ApprenticeshipTrainingItems = apprenticeshipTrainingList, PaginationDetails = paginationDetails, Ukprn = ukprn }; _mockGetProviders.Setup( x => x.GetActiveApprenticeshipTrainingByProvider(ukprn, 1)).Returns(expected); var result = _sut.GetActiveApprenticeshipTrainingByProvider(ukprn); var providerApprenticeships = result.Value.ApprenticeshipTrainingItems.ToArray(); Assert.AreEqual(apprenticeshipTrainingList.Count, providerApprenticeships.Length); Assert.AreEqual(totalCount, result.Value.PaginationDetails.TotalCount); Assert.AreEqual(numberPerPage, result.Value.PaginationDetails.NumberPerPage); Assert.AreEqual(numberReturned, result.Value.ApprenticeshipTrainingItems.Count()); Assert.AreEqual(page, result.Value.PaginationDetails.Page); Assert.AreEqual(lastPage, result.Value.PaginationDetails.LastPage); Assert.AreEqual(providerApprenticeships[0].Identifier, apprenticeshipTraining.Identifier); }
public void ShouldBeSuccessIfProviderReturned() { var provider = new Provider(); var apprenticeshipTrainingSummary = new ApprenticeshipTrainingSummary { Ukprn = 42, ApprenticeshipTrainingItems = new List <ApprenticeshipTraining> { new ApprenticeshipTraining { Identifier = "5", TrainingType = ApprenticeshipTrainingType.Framework, Type = "Framework", Level = 3, Name = "Software engineer" } }, PaginationDetails = new PaginationDetails { LastPage = 2, NumberOfRecordsToSkip = 0, NumberPerPage = 20, Page = 1, TotalCount = 21 } }; _mockProviderDetailRepository = new Mock <IGetProviderDetails>(); _mockProviderDetailRepository.Setup(x => x.GetProviderDetails(It.IsAny <long>())).Returns(Task.FromResult(provider)); _mockProviderDetailRepository.Setup(x => x.GetApprenticeshipTrainingSummary(It.IsAny <long>(), It.IsAny <int>())).Returns(Task.FromResult(apprenticeshipTrainingSummary)); _handler = new ProviderDetailHandler(_mockProviderDetailRepository.Object); var message = new ProviderDetailQuery(); var response = _handler.Handle(message, default(CancellationToken)).Result; response.StatusCode.Should().Be(ProviderDetailResponse.ResponseCodes.Success); response.Provider.Should().Be(provider); response.ApprenticeshipTrainingSummary.Should().Be(apprenticeshipTrainingSummary); }
public static ProviderDetailViewModel GetProviderDetailViewModel(Provider provider, ApprenticeshipTrainingSummary apprenticeshipTrainingSummary, IEnumerable <long> hideAboutThisProviderForUlns = null, string searchTerm = null) { hideAboutThisProviderForUlns = hideAboutThisProviderForUlns ?? new List <long>(); var employerSatisfationMessage = (provider.EmployerSatisfaction > 0) ? ProviderMappingHelper.GetPercentageText(provider.EmployerSatisfaction) : ProviderMappingHelper.GetPercentageText(null); var learnerSatisfationMessage = (provider.LearnerSatisfaction > 0) ? ProviderMappingHelper.GetPercentageText(provider.LearnerSatisfaction) : ProviderMappingHelper.GetPercentageText(null); var viewModel = new ProviderDetailViewModel { DisplayAboutThisProvider = !hideAboutThisProviderForUlns.Contains(provider.Ukprn), Email = provider.Email, CurrentlyNotStartingNewApprentices = provider.CurrentlyNotStartingNewApprentices, IsEmployerProvider = provider.IsEmployerProvider, EmployerSatisfaction = provider.EmployerSatisfaction, EmployerSatisfactionMessage = employerSatisfationMessage, IsHigherEducationInstitute = provider.IsHigherEducationInstitute, LearnerSatisfaction = provider.LearnerSatisfaction, LearnerSatisfactionMessage = learnerSatisfationMessage, NationalProvider = provider.NationalProvider, Phone = provider.Phone, UkPrn = provider.Ukprn, ProviderName = provider.ProviderName, Website = provider.Website, MarketingInfo = provider.MarketingInfo, ApprenticeshipTrainingSummary = apprenticeshipTrainingSummary, HasParentCompanyGuarantee = provider.HasParentCompanyGuarantee, IsNew = provider.IsNew, IsLevyPayerOnly = provider.IsLevyPayerOnly, SearchTerm = searchTerm, ProviderFeedback = Is <ProviderFeedbackFeature> .Enabled && provider.ProviderFeedback != null ? new FeedbackViewModel(provider.ProviderFeedback) : (FeedbackViewModel)null }; if (provider.Aliases != null && provider.Aliases.Any()) { viewModel.TradingNames = provider.Aliases.Aggregate((aggregatingTradingNames, aliasToAdd) => aggregatingTradingNames + ", " + aliasToAdd); } return(viewModel); }