GetRecommendedLearningForSelfAssessment_calls_learning_hub_resource_service_with_distinct_ids() { // Given A.CallTo(() => selfAssessmentDataService.GetCompetencyIdsForSelfAssessment(SelfAssessmentId)) .Returns(new[] { 1, 2, 3, 4, 5 }); var competencyLearningResources = Builder <CompetencyLearningResource> .CreateListOfSize(5).All() .With(clr => clr.LearningHubResourceReferenceId = LearningHubResourceReferenceId) .And(clr => clr.LearningResourceReferenceId = LearningResourceReferenceId).Build(); A.CallTo( () => competencyLearningResourcesDataService.GetActiveCompetencyLearningResourcesByCompetencyId( A <int> ._ ) ).Returns(competencyLearningResources); GivenLearningHubApiReturnsResources(0); // When await recommendedLearningService.GetRecommendedLearningForSelfAssessment(SelfAssessmentId, DelegateId); // Then A.CallTo( () => learningHubResourceService.GetResourceReferenceDetailsByReferenceIds( A <List <int> > .That.Matches(i => i.Single() == LearningHubResourceReferenceId) ) ) .MustHaveHappenedOnceExactly(); A.CallTo( () => learningHubResourceService.GetBulkResourcesByReferenceIds( A <List <int> > .That.Matches(i => i.Single() == LearningHubResourceReferenceId) ) ) .MustHaveHappenedOnceExactly(); }
GetRecommendedLearningForSelfAssessment( int selfAssessmentId, int delegateId ) { var hasMaxSignpostedResources = Int32.TryParse( configDataService.GetConfigValue(ConfigDataService.MaxSignpostedResources), out var maxSignpostedResources ); var competencyIds = selfAssessmentDataService.GetCompetencyIdsForSelfAssessment(selfAssessmentId); var competencyLearningResources = new List <CompetencyLearningResource>(); foreach (var competencyId in competencyIds) { var learningHubResourceReferencesForCompetency = competencyLearningResourcesDataService.GetActiveCompetencyLearningResourcesByCompetencyId( competencyId ); competencyLearningResources.AddRange(learningHubResourceReferencesForCompetency); } var resourceReferences = competencyLearningResources.Select( clr => (clr.LearningHubResourceReferenceId, clr.LearningResourceReferenceId) ).Distinct().ToDictionary( x => x.LearningHubResourceReferenceId, x => x.LearningResourceReferenceId ); var uniqueLearningHubReferenceIds = competencyLearningResources.Select( clr => clr.LearningHubResourceReferenceId ).Distinct().ToList(); var resources = learningHubResourceService.GetResourceReferenceDetailsByReferenceIds(uniqueLearningHubReferenceIds); var delegateLearningLogItems = learningLogItemsDataService.GetLearningLogItems(delegateId); var recommendedResources = resources.Select( rr => GetPopulatedRecommendedResource( selfAssessmentId, delegateId, resourceReferences[rr.RefId], delegateLearningLogItems, rr, competencyLearningResources ) ) .WhereNotNull() .OrderByDescending(resource => resource.RecommendationScore); var bestRecommendedResources = hasMaxSignpostedResources ? recommendedResources.Take(maxSignpostedResources).ToList() : recommendedResources.ToList(); var apiResources = await learningHubResourceService.GetBulkResourcesByReferenceIds( bestRecommendedResources.Select(resource => resource.LearningHubReferenceId).ToList() ); var recommendedResourcesPresentInApi = bestRecommendedResources.Where( resource => !apiResources.bulkResourceReferences.UnmatchedResourceReferenceIds.Contains( resource.LearningHubReferenceId ) ).ToList(); return(recommendedResourcesPresentInApi, apiResources.apiIsAccessible); }