public async Task Then_Additional_Courses_for_Provider_Should_Contain_Course_Passed_To_Handler( GetTrainingCourseProviderQuery query, GetProviderStandardItem apiResponse, GetStandardsListItem apiCourseResponse, GetOverallAchievementRateResponse apiAchievementRateResponse, GetStandardsListResponse allCoursesApiResponse, List <GetStandardsListItem> allStandards, GetUkprnsForStandardAndLocationResponse ukprnsCountResponse, GetApprenticeFeedbackResponse appfeedbackResponse, [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockApiClient, [Frozen] Mock <IApprenticeFeedbackApiClient <ApprenticeFeedbackApiConfiguration> > mockApprenticeFeedbackApiClient, GetTrainingCourseProviderQueryHandler handler) { apiCourseResponse.LarsCode = query.CourseId; allStandards.Add(new GetStandardsListItem { LarsCode = apiCourseResponse.LarsCode, Title = apiCourseResponse.Title, Level = apiCourseResponse.Level }); allCoursesApiResponse.Standards = allStandards; ArrangeClients(query, apiResponse, apiCourseResponse, apiAchievementRateResponse, allCoursesApiResponse, ukprnsCountResponse, appfeedbackResponse, mockCoursesApiClient, mockApiClient, mockApprenticeFeedbackApiClient); var result = await handler.Handle(query, CancellationToken.None); result.AdditionalCourses.Should().BeEquivalentTo(allCoursesApiResponse.Standards.Select(c => new { Id = c.LarsCode, c.Title, c.Level }).ToList()); }
public async Task Then_Returns_Totals_For_Standard( GetTrainingCourseProviderQuery query, GetProviderStandardItem apiResponse, GetStandardsListItem apiCourseResponse, GetOverallAchievementRateResponse apiAchievementRateResponse, GetProviderAdditionalStandardsItem apiAdditionalStandardsResponse, GetStandardsListResponse allCoursesApiResponse, GetApprenticeFeedbackResponse appfeedbackResponse, List <int> ukprnsByStandard, List <int> ukprnsByStandardAndLocation, [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockApiClient, [Frozen] Mock <IApprenticeFeedbackApiClient <ApprenticeFeedbackApiConfiguration> > mockApprenticeFeedbackApiClient, GetTrainingCourseProviderQueryHandler handler) { ukprnsByStandard.Add(query.ProviderId); ukprnsByStandardAndLocation.Add(query.ProviderId); var ukprnsCountResponse = new GetUkprnsForStandardAndLocationResponse { UkprnsByStandard = ukprnsByStandard, UkprnsByStandardAndLocation = ukprnsByStandardAndLocation }; ArrangeClients(query, apiResponse, apiCourseResponse, apiAchievementRateResponse, allCoursesApiResponse, ukprnsCountResponse, appfeedbackResponse, mockCoursesApiClient, mockApiClient, mockApprenticeFeedbackApiClient); var result = await handler.Handle(query, CancellationToken.None); result.TotalProviders.Should().Be(ukprnsCountResponse.UkprnsByStandard.ToList().Count); result.TotalProvidersAtLocation.Should().Be(ukprnsCountResponse.UkprnsByStandardAndLocation.ToList().Count); }
public async Task Then_Gets_The_Standard_And_The_Provider_For_That_Course_And_Shortlist_Count_From_Course_Delivery_Api_Client( GetTrainingCourseProviderQuery query, GetProviderStandardItem apiResponse, GetStandardsListItem apiCourseResponse, GetOverallAchievementRateResponse apiAchievementRateResponse, GetStandardsListResponse allCoursesApiResponse, GetUkprnsForStandardAndLocationResponse ukprnsCountResponse, GetApprenticeFeedbackResponse apprenticeFeedbackResponse, int shortlistItemCount, [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockApiClient, [Frozen] Mock <IApprenticeFeedbackApiClient <ApprenticeFeedbackApiConfiguration> > mockApprenticeFeedbackApiClient, [Frozen] Mock <IShortlistService> shortlistService, GetTrainingCourseProviderQueryHandler handler) { shortlistService.Setup(x => x.GetShortlistItemCount(query.ShortlistUserId)) .ReturnsAsync(shortlistItemCount); ArrangeClients(query, apiResponse, apiCourseResponse, apiAchievementRateResponse, allCoursesApiResponse, ukprnsCountResponse, apprenticeFeedbackResponse, mockCoursesApiClient, mockApiClient, mockApprenticeFeedbackApiClient); var result = await handler.Handle(query, CancellationToken.None); result.ProviderStandard.Should().BeEquivalentTo(apiResponse, options => options.Excluding(s => s.ApprenticeFeedback)); result.ProviderStandard.ApprenticeFeedback.Should().BeEquivalentTo(apprenticeFeedbackResponse); result.Course.Should().BeEquivalentTo(apiCourseResponse); result.ShortlistItemCount.Should().Be(shortlistItemCount); mockApiClient.Verify(x => x.Get <GetProviderStandardItem>(It.IsAny <GetProviderByCourseAndUkPrnRequest>()), Times.Once); }
public async Task Then_If_No_Standard_Found_Returns_Empty_Response( GetTrainingCourseQuery query, GetLevelsListResponse levelsApiResponse, GetUkprnsForStandardAndLocationResponse courseDirectoryApiResponse, [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockCourseDeliveryApiClient, GetTrainingCourseQueryHandler handler) { //Arrange mockCoursesApiClient .Setup(client => client.Get <GetStandardsListItem>(It.Is <GetStandardRequest>(c => c.GetUrl.Contains($"api/courses/standards/{query.Id}")))) .ReturnsAsync((GetStandardsListItem)null); var url = new GetUkprnsForStandardAndLocationRequest(query.Id, query.Lat, query.Lon).GetUrl; mockCourseDeliveryApiClient .Setup(client => client.Get <GetUkprnsForStandardAndLocationResponse>( It.Is <GetUkprnsForStandardAndLocationRequest>((c => c.GetUrl.Equals(url))))) .ReturnsAsync(courseDirectoryApiResponse); //Act var result = await handler.Handle(query, CancellationToken.None); //Assert result.Course.Should().BeNull(); }
public async Task Then_Returns_Additional_Courses_for_Provider_That_Are_Available( GetTrainingCourseProviderQuery query, GetProviderStandardItem apiResponse, GetStandardsListItem apiCourseResponse, GetOverallAchievementRateResponse apiAchievementRateResponse, GetProviderAdditionalStandardsItem apiAdditionalStandardsResponse, GetStandardsListResponse allCoursesApiResponse, GetUkprnsForStandardAndLocationResponse ukprnsCountResponse, [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockApiClient, GetTrainingCourseProviderQueryHandler handler) { mockApiClient .Setup(client => client.Get <GetProviderStandardItem>(It.Is <GetProviderByCourseAndUkPrnRequest>(c => c.GetUrl.Contains(query.CourseId.ToString()) && c.GetUrl.Contains(query.ProviderId.ToString() )))) .ReturnsAsync(apiResponse); mockCoursesApiClient .Setup(client => client.Get <GetStandardsListResponse>(It.IsAny <GetAvailableToStartStandardsListRequest>())) .ReturnsAsync(allCoursesApiResponse); var additionalCourses = allCoursesApiResponse.Standards.Select(c => c.LarsCode).ToList(); additionalCourses.Add(-10); mockApiClient .Setup(client => client.Get <GetProviderAdditionalStandardsItem>(It.Is <GetProviderAdditionalStandardsRequest>( c => c.GetUrl.Contains(query.ProviderId.ToString() )))) .ReturnsAsync(new GetProviderAdditionalStandardsItem { StandardIds = additionalCourses }); mockApiClient .Setup(x => x.Get <GetUkprnsForStandardAndLocationResponse>( It.Is <GetUkprnsForStandardAndLocationRequest>(c => c.GetUrl.Contains(query.CourseId.ToString())))) .ReturnsAsync(ukprnsCountResponse); mockCoursesApiClient .Setup(client => client.Get <GetStandardsListItem>( It.Is <GetStandardRequest>(c => c.GetUrl.Contains(query.CourseId.ToString())))) .ReturnsAsync(apiCourseResponse); mockApiClient.Setup(client => client.Get <GetOverallAchievementRateResponse>(It.Is <GetOverallAchievementRateRequest>( c => c.GetUrl.Contains(apiCourseResponse.SectorSubjectAreaTier2Description) ))) .ReturnsAsync(apiAchievementRateResponse); var result = await handler.Handle(query, CancellationToken.None); result.AdditionalCourses.Should().BeInAscendingOrder(c => c.Title); result.AdditionalCourses.Should() .BeEquivalentTo(allCoursesApiResponse.Standards, options => options.ExcludingMissingMembers()); }
public async Task Then_If_There_Is_Lat_Lon_Data_The_Location_Is_Used( string locationName, string authorityName, GetTrainingCourseProviderQuery query, GetOverallAchievementRateResponse apiResponse, GetProviderStandardItem apiProviderStandardResponse, GetStandardsListItem apiCourseResponse, GetStandardsListResponse allCoursesApiResponse, LocationItem locationLookupResponse, GetOverallAchievementRateResponse apiAchievementRateResponse, GetUkprnsForStandardAndLocationResponse ukprnsCountResponse, [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockApiClient, [Frozen] Mock <ILocationLookupService> mockLocationLookupService, GetTrainingCourseProviderQueryHandler handler) { mockLocationLookupService .Setup(service => service.GetLocationInformation(query.Location, query.Lat, query.Lon)) .ReturnsAsync(locationLookupResponse); mockApiClient .Setup(client => client.Get <GetProviderStandardItem>(It.Is <GetProviderByCourseAndUkPrnRequest>(c => c.GetUrl.Contains(query.CourseId.ToString()) && c.GetUrl.Contains(query.ProviderId.ToString()) && c.GetUrl.Contains(locationLookupResponse.GeoPoint.First().ToString()) && c.GetUrl.Contains(locationLookupResponse.GeoPoint.Last().ToString()) ))) .ReturnsAsync(apiProviderStandardResponse); mockApiClient .Setup(client => client.Get <GetProviderAdditionalStandardsItem>(It.Is <GetProviderAdditionalStandardsRequest>( c => c.GetUrl.Contains(query.ProviderId.ToString() )))) .ReturnsAsync(new GetProviderAdditionalStandardsItem { StandardIds = allCoursesApiResponse.Standards.Select(c => c.LarsCode).ToList() }); mockCoursesApiClient .Setup(client => client.Get <GetStandardsListItem>( It.Is <GetStandardRequest>(c => c.GetUrl.Contains(query.CourseId.ToString())))) .ReturnsAsync(apiCourseResponse); mockApiClient .Setup(x => x.Get <GetUkprnsForStandardAndLocationResponse>( It.Is <GetUkprnsForStandardAndLocationRequest>(c => c.GetUrl.Contains(query.CourseId.ToString())))) .ReturnsAsync(ukprnsCountResponse); mockCoursesApiClient .Setup(client => client.Get <GetStandardsListResponse>(It.IsAny <GetAvailableToStartStandardsListRequest>())) .ReturnsAsync(allCoursesApiResponse); mockApiClient.Setup(client => client.Get <GetOverallAchievementRateResponse>(It.Is <GetOverallAchievementRateRequest>( c => c.GetUrl.Contains(apiCourseResponse.SectorSubjectAreaTier2Description) ))) .ReturnsAsync(apiAchievementRateResponse); var result = await handler.Handle(query, CancellationToken.None); result.ProviderStandard.Should().BeEquivalentTo(apiProviderStandardResponse); result.Location.Should().BeEquivalentTo(locationLookupResponse); }
private static void ArrangeClients( GetTrainingCourseProviderQuery query, GetProviderStandardItem apiProviderStandardResponse, GetStandardsListItem apiCourseResponse, GetOverallAchievementRateResponse apiAchievementRateResponse, GetStandardsListResponse allCoursesApiResponse, GetUkprnsForStandardAndLocationResponse ukprnsCountResponse, GetApprenticeFeedbackResponse apprenticeFeedbackResponse, Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockApiClient, Mock <IApprenticeFeedbackApiClient <ApprenticeFeedbackApiConfiguration> > mockApprenticeFeedbackClient) { mockApiClient .Setup(client => client.Get <GetProviderStandardItem>(It.Is <GetProviderByCourseAndUkPrnRequest>(c => c.GetUrl.Contains(query.CourseId.ToString()) && c.GetUrl.Contains(query.ProviderId.ToString()) && c.GetUrl.Contains(apiCourseResponse.SectorSubjectAreaTier2Description) && c.GetUrl.Contains($"shortlistUserId={query.ShortlistUserId}") ))) .ReturnsAsync(apiProviderStandardResponse); mockApiClient .Setup(client => client.Get <GetProviderAdditionalStandardsItem>(It.Is <GetProviderAdditionalStandardsRequest>( c => c.GetUrl.Contains(query.ProviderId.ToString() )))) .ReturnsAsync(new GetProviderAdditionalStandardsItem { StandardIds = allCoursesApiResponse.Standards.Select(c => c.LarsCode).ToList() }); mockApiClient .Setup(x => x.Get <GetUkprnsForStandardAndLocationResponse>( It.Is <GetUkprnsForStandardAndLocationRequest>(c => c.GetUrl.Contains(query.CourseId.ToString())))) .ReturnsAsync(ukprnsCountResponse); mockCoursesApiClient .Setup(client => client.Get <GetStandardsListItem>( It.Is <GetStandardRequest>(c => c.GetUrl.Contains(query.CourseId.ToString())))) .ReturnsAsync(apiCourseResponse); mockCoursesApiClient .Setup(client => client.Get <GetStandardsListResponse>(It.IsAny <GetAvailableToStartStandardsListRequest>())) .ReturnsAsync(allCoursesApiResponse); mockApiClient.Setup(client => client.Get <GetOverallAchievementRateResponse>(It.Is <GetOverallAchievementRateRequest>( c => c.GetUrl.Contains(apiCourseResponse.SectorSubjectAreaTier2Description) ))) .ReturnsAsync(apiAchievementRateResponse); apprenticeFeedbackResponse.Ukprn = query.ProviderId; mockApprenticeFeedbackClient .Setup(s => s.PostWithResponseCode <IEnumerable <GetApprenticeFeedbackResponse> > (It.Is <PostApprenticeFeedbackRequest>(t => ((PostApprenticeFeedbackRequestData)t.Data).Ukprns.Contains(query.ProviderId)))) .ReturnsAsync(new ApiResponse <IEnumerable <GetApprenticeFeedbackResponse> >(new List <GetApprenticeFeedbackResponse> { apprenticeFeedbackResponse }, HttpStatusCode.OK, string.Empty)); }
public async Task Then_Does_Not_Return_Additional_Courses_If_No_Additional_Courses( GetTrainingCourseProviderQuery query, GetProviderStandardItem apiResponse, GetStandardsListItem apiCourseResponse, GetProviderAdditionalStandardsItem apiAdditionalStandardsResponse, GetStandardsListResponse allCoursesApiResponse, GetOverallAchievementRateResponse apiAchievementRateResponse, GetUkprnsForStandardAndLocationResponse ukprnsCountResponse, GetApprenticeFeedbackResponse apprenticeFeedbackResponse, [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockApiClient, [Frozen] Mock <IApprenticeFeedbackApiClient <ApprenticeFeedbackApiConfiguration> > mockApprenticeFeedbackApiClient, GetTrainingCourseProviderQueryHandler handler) { mockApiClient .Setup(client => client.Get <GetProviderStandardItem>(It.Is <GetProviderByCourseAndUkPrnRequest>(c => c.GetUrl.Contains(query.CourseId.ToString()) && c.GetUrl.Contains(query.ProviderId.ToString() )))) .ReturnsAsync(apiResponse); mockApiClient .Setup(client => client.Get <GetProviderAdditionalStandardsItem>(It.Is <GetProviderAdditionalStandardsRequest>(c => c.GetUrl.Contains(query.ProviderId.ToString() )))) .ReturnsAsync(new GetProviderAdditionalStandardsItem { StandardIds = new List <int>() }); mockCoursesApiClient .Setup(client => client.Get <GetStandardsListItem>(It.Is <GetStandardRequest>(c => c.GetUrl.Contains(query.CourseId.ToString())))) .ReturnsAsync(apiCourseResponse); mockCoursesApiClient .Setup(client => client.Get <GetStandardsListResponse>(It.IsAny <GetAvailableToStartStandardsListRequest>())) .ReturnsAsync(allCoursesApiResponse); mockApiClient.Setup(client => client.Get <GetOverallAchievementRateResponse>(It.Is <GetOverallAchievementRateRequest>(c => c.GetUrl.Contains(apiCourseResponse.SectorSubjectAreaTier2Description) ))) .ReturnsAsync(apiAchievementRateResponse); mockApiClient .Setup(x => x.Get <GetUkprnsForStandardAndLocationResponse>( It.Is <GetUkprnsForStandardAndLocationRequest>(c => c.GetUrl.Contains(query.CourseId.ToString())))) .ReturnsAsync(ukprnsCountResponse); apprenticeFeedbackResponse.Ukprn = query.ProviderId; mockApprenticeFeedbackApiClient .Setup(s => s.PostWithResponseCode <IEnumerable <GetApprenticeFeedbackResponse> > (It.Is <PostApprenticeFeedbackRequest>(t => ((PostApprenticeFeedbackRequestData)t.Data).Ukprns.Contains(query.ProviderId)))) .ReturnsAsync(new ApiResponse <IEnumerable <GetApprenticeFeedbackResponse> >(new List <GetApprenticeFeedbackResponse> { apprenticeFeedbackResponse }, HttpStatusCode.OK, string.Empty)); var result = await handler.Handle(query, CancellationToken.None); result.AdditionalCourses.Should().BeEquivalentTo(new List <GetAdditionalCourseListItem>()); }
public async Task Then_If_Demand_Feature_Is_Not_Enabled_Then_False_Returned_And_Api_Not_Called( GetTrainingCourseQuery query, GetStandardsListItem coursesApiResponse, GetLevelsListResponse levelsApiResponse, GetUkprnsForStandardAndLocationResponse courseDirectoryApiResponse, int shortlistItemCount, GetShowEmployerDemandResponse showEmployerDemandResponse, [Frozen] Mock <IOptions <FindApprenticeshipTrainingConfiguration> > config, [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockCourseDeliveryApiClient, [Frozen] Mock <IShortlistService> shortlistService, [Frozen] Mock <IEmployerDemandApiClient <EmployerDemandApiConfiguration> > mockEmployerDemandApiClient, GetTrainingCourseQueryHandler handler) { //Arrange config.Object.Value.EmployerDemandFeatureToggle = false; levelsApiResponse.Levels.First().Name = "GCSE"; levelsApiResponse.Levels.First().Code = 2; coursesApiResponse.Level = 2; coursesApiResponse.LevelEquivalent = levelsApiResponse.Levels .Single(x => x.Code == coursesApiResponse.Level).Name; var url = new GetUkprnsForStandardAndLocationRequest(query.Id, query.Lat, query.Lon).GetUrl; mockCoursesApiClient .Setup(client => client.Get <GetStandardsListItem>(It.Is <GetStandardRequest>(c => c.GetUrl.Contains($"api/courses/standards/{query.Id}")))) .ReturnsAsync(coursesApiResponse); shortlistService.Setup(x => x.GetShortlistItemCount(query.ShortlistUserId)) .ReturnsAsync(shortlistItemCount); mockCourseDeliveryApiClient .Setup(client => client.Get <GetUkprnsForStandardAndLocationResponse>( It.Is <GetUkprnsForStandardAndLocationRequest>((c => c.GetUrl.Equals(url))))) .ReturnsAsync(courseDirectoryApiResponse); mockCoursesApiClient .Setup(client => client.Get <GetLevelsListResponse>(It.IsAny <GetLevelsListRequest>())) .ReturnsAsync(levelsApiResponse); mockEmployerDemandApiClient .Setup(client => client.GetResponseCode(It.IsAny <GetShowEmployerDemandRequest>())) .ReturnsAsync(HttpStatusCode.OK); //Act var result = await handler.Handle(query, CancellationToken.None); //Assert result.Course.Should().BeEquivalentTo(coursesApiResponse); result.Course.LevelEquivalent.Should().Be("GCSE"); result.ProvidersCount.Should().Be(courseDirectoryApiResponse.UkprnsByStandard.ToList().Count); result.ProvidersCountAtLocation.Should().Be(courseDirectoryApiResponse.UkprnsByStandardAndLocation.ToList().Count); result.ShortlistItemCount.Should().Be(shortlistItemCount); result.ShowEmployerDemand.Should().BeFalse(); mockEmployerDemandApiClient .Verify(client => client.GetResponseCode(It.IsAny <GetShowEmployerDemandRequest>()), Times.Never); }
public async Task Then_If_There_Is_No_Location_Then_Location_Not_Passed( GetTrainingCourseQuery query, GetStandardsListItem coursesApiResponse, GetLevelsListResponse levelsApiResponse, GetUkprnsForStandardAndLocationResponse courseDirectoryApiResponse, int shortlistItemCount, LocationItem locationItem, [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockCourseDeliveryApiClient, [Frozen] Mock <IShortlistService> shortlistService, [Frozen] Mock <ILocationLookupService> locationLookupService, GetTrainingCourseQueryHandler handler) { //Arrange locationLookupService .Setup(x => x.GetLocationInformation(query.LocationName, query.Lat, query.Lon, false)) .ReturnsAsync((LocationItem)null); levelsApiResponse.Levels.First().Name = "GCSE"; coursesApiResponse.Level = levelsApiResponse.Levels.First().Code; coursesApiResponse.LevelEquivalent = levelsApiResponse.Levels .Single(x => x.Code == coursesApiResponse.Level).Name; var url = new GetUkprnsForStandardAndLocationRequest(query.Id, 0, 0).GetUrl; mockCoursesApiClient .Setup(client => client.Get <GetStandardsListItem>(It.Is <GetStandardRequest>(c => c.GetUrl.Contains($"api/courses/standards/{query.Id}")))) .ReturnsAsync(coursesApiResponse); shortlistService.Setup(x => x.GetShortlistItemCount(query.ShortlistUserId)) .ReturnsAsync(shortlistItemCount); mockCourseDeliveryApiClient .Setup(client => client.Get <GetUkprnsForStandardAndLocationResponse>( It.Is <GetUkprnsForStandardAndLocationRequest>((c => c.GetUrl.Equals(url))))) .ReturnsAsync(courseDirectoryApiResponse); mockCoursesApiClient .Setup(client => client.Get <GetLevelsListResponse>(It.IsAny <GetLevelsListRequest>())) .ReturnsAsync(levelsApiResponse); //Act var result = await handler.Handle(query, CancellationToken.None); //Assert result.Course.Should().BeEquivalentTo(coursesApiResponse); result.Course.LevelEquivalent.Should().Be("GCSE"); result.ProvidersCount.Should().Be(courseDirectoryApiResponse.UkprnsByStandard.ToList().Count); result.ProvidersCountAtLocation.Should().Be(courseDirectoryApiResponse.UkprnsByStandardAndLocation.ToList().Count); result.ShortlistItemCount.Should().Be(shortlistItemCount); }
private static void ArrangeClients( GetTrainingCourseProviderQuery query, GetProviderStandardItem apiProviderStandardResponse, GetStandardsListItem apiCourseResponse, GetOverallAchievementRateResponse apiAchievementRateResponse, GetStandardsListResponse allCoursesApiResponse, GetUkprnsForStandardAndLocationResponse ukprnsCountResponse, Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockApiClient) { mockApiClient .Setup(client => client.Get <GetProviderStandardItem>(It.Is <GetProviderByCourseAndUkPrnRequest>(c => c.GetUrl.Contains(query.CourseId.ToString()) && c.GetUrl.Contains(query.ProviderId.ToString()) && c.GetUrl.Contains(apiCourseResponse.SectorSubjectAreaTier2Description) && c.GetUrl.Contains($"shortlistUserId={query.ShortlistUserId}") ))) .ReturnsAsync(apiProviderStandardResponse); mockApiClient .Setup(client => client.Get <GetProviderAdditionalStandardsItem>(It.Is <GetProviderAdditionalStandardsRequest>( c => c.GetUrl.Contains(query.ProviderId.ToString() )))) .ReturnsAsync(new GetProviderAdditionalStandardsItem { StandardIds = allCoursesApiResponse.Standards.Select(c => c.LarsCode).ToList() }); mockApiClient .Setup(x => x.Get <GetUkprnsForStandardAndLocationResponse>( It.Is <GetUkprnsForStandardAndLocationRequest>(c => c.GetUrl.Contains(query.CourseId.ToString())))) .ReturnsAsync(ukprnsCountResponse); mockCoursesApiClient .Setup(client => client.Get <GetStandardsListItem>( It.Is <GetStandardRequest>(c => c.GetUrl.Contains(query.CourseId.ToString())))) .ReturnsAsync(apiCourseResponse); mockCoursesApiClient .Setup(client => client.Get <GetStandardsListResponse>(It.IsAny <GetAvailableToStartStandardsListRequest>())) .ReturnsAsync(allCoursesApiResponse); mockApiClient.Setup(client => client.Get <GetOverallAchievementRateResponse>(It.Is <GetOverallAchievementRateRequest>( c => c.GetUrl.Contains(apiCourseResponse.SectorSubjectAreaTier2Description) ))) .ReturnsAsync(apiAchievementRateResponse); }
public async Task Then_Returns_Additional_Courses_for_Provider_In_Alphabetical_Order( GetTrainingCourseProviderQuery query, GetProviderStandardItem apiResponse, GetStandardsListItem apiCourseResponse, GetOverallAchievementRateResponse apiAchievementRateResponse, GetProviderAdditionalStandardsItem apiAdditionalStandardsResponse, GetStandardsListResponse allCoursesApiResponse, GetUkprnsForStandardAndLocationResponse ukprnsCountResponse, [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockApiClient, GetTrainingCourseProviderQueryHandler handler) { ArrangeClients(query, apiResponse, apiCourseResponse, apiAchievementRateResponse, allCoursesApiResponse, ukprnsCountResponse, mockCoursesApiClient, mockApiClient); var result = await handler.Handle(query, CancellationToken.None); result.AdditionalCourses.Should().BeInAscendingOrder(c => c.Title); result.AdditionalCourses.Should() .BeEquivalentTo(allCoursesApiResponse.Standards, options => options.ExcludingMissingMembers()); }
public async Task Then_Gets_The_Overall_Achievement_Rate_Data_From_The_Course_SubjectSectorArea( GetTrainingCourseProviderQuery query, GetProviderStandardItem apiResponse, GetStandardsListItem apiCourseResponse, GetOverallAchievementRateResponse apiAchievementRateResponse, GetProviderAdditionalStandardsItem apiAdditionalStandardsResponse, GetStandardsListResponse allCoursesApiResponse, GetUkprnsForStandardAndLocationResponse ukprnsCountResponse, [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockApiClient, GetTrainingCourseProviderQueryHandler handler) { query.Lat = 0; query.Lon = 0; query.Location = string.Empty; ArrangeClients(query, apiResponse, apiCourseResponse, apiAchievementRateResponse, allCoursesApiResponse, ukprnsCountResponse, mockCoursesApiClient, mockApiClient); var result = await handler.Handle(query, CancellationToken.None); result.OverallAchievementRates.Should().BeEquivalentTo(apiAchievementRateResponse.OverallAchievementRates); }
public async Task Then_If_The_Provider_Is_Not_Found_For_Location_And_Without_Location_Null_Returned( string locationName, string authorityName, GetTrainingCourseProviderQuery query, GetOverallAchievementRateResponse apiResponse, GetProviderStandardItem apiProviderStandardResponse, GetStandardsListItem apiCourseResponse, GetStandardsListResponse allCoursesApiResponse, LocationItem locationLookupResponse, GetOverallAchievementRateResponse apiAchievementRateResponse, GetUkprnsForStandardAndLocationResponse ukprnsCountResponse, GetApprenticeFeedbackResponse apprenticeFeedbackResponse, [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockApiClient, [Frozen] Mock <ILocationLookupService> mockLocationLookupService, [Frozen] Mock <IApprenticeFeedbackApiClient <ApprenticeFeedbackApiConfiguration> > mockApprenticeFeedbackApiClient, GetTrainingCourseProviderQueryHandler handler) { query.Location = $"{locationName}, {authorityName} "; mockLocationLookupService .Setup(service => service.GetLocationInformation(query.Location, query.Lat, query.Lon, false)) .ReturnsAsync(locationLookupResponse); mockApiClient .Setup(client => client.Get <GetProviderStandardItem>(It.Is <GetProviderByCourseAndUkPrnRequest>(c => c.GetUrl.Contains(query.CourseId.ToString()) && c.GetUrl.Contains(query.ProviderId.ToString()) && c.GetUrl.Contains(locationLookupResponse.GeoPoint.First().ToString()) && c.GetUrl.Contains(locationLookupResponse.GeoPoint.Last().ToString()) ))) .ReturnsAsync((GetProviderStandardItem)null); mockApiClient .Setup(client => client.Get <GetProviderStandardItem>(It.Is <GetProviderByCourseAndUkPrnRequest>(c => c.GetUrl.Contains(query.CourseId.ToString()) && c.GetUrl.Contains(query.ProviderId.ToString()) && c.GetUrl.Contains("?lat=&lon=") ))) .ReturnsAsync((GetProviderStandardItem)null); mockApiClient .Setup(x => x.Get <GetUkprnsForStandardAndLocationResponse>( It.Is <GetUkprnsForStandardAndLocationRequest>(c => c.GetUrl.Contains(query.CourseId.ToString())))) .ReturnsAsync(ukprnsCountResponse); mockApiClient .Setup(client => client.Get <GetProviderAdditionalStandardsItem>(It.Is <GetProviderAdditionalStandardsRequest>( c => c.GetUrl.Contains(query.ProviderId.ToString() )))) .ReturnsAsync(new GetProviderAdditionalStandardsItem { StandardIds = allCoursesApiResponse.Standards.Select(c => c.LarsCode).ToList() }); mockCoursesApiClient .Setup(client => client.Get <GetStandardsListItem>( It.Is <GetStandardRequest>(c => c.GetUrl.Contains(query.CourseId.ToString())))) .ReturnsAsync(apiCourseResponse); mockCoursesApiClient .Setup(client => client.Get <GetStandardsListResponse>(It.IsAny <GetAvailableToStartStandardsListRequest>())) .ReturnsAsync(allCoursesApiResponse); mockApiClient.Setup(client => client.Get <GetOverallAchievementRateResponse>(It.Is <GetOverallAchievementRateRequest>( c => c.GetUrl.Contains(apiCourseResponse.SectorSubjectAreaTier2Description) ))) .ReturnsAsync(apiAchievementRateResponse); apprenticeFeedbackResponse.Ukprn = query.ProviderId; mockApprenticeFeedbackApiClient .Setup(s => s.PostWithResponseCode <IEnumerable <GetApprenticeFeedbackResponse> > (It.Is <PostApprenticeFeedbackRequest>(t => ((PostApprenticeFeedbackRequestData)t.Data).Ukprns.Contains(query.ProviderId)))) .ReturnsAsync(new ApiResponse <IEnumerable <GetApprenticeFeedbackResponse> >(new List <GetApprenticeFeedbackResponse> { apprenticeFeedbackResponse }, HttpStatusCode.OK, string.Empty)); var result = await handler.Handle(query, CancellationToken.None); result.ProviderStandard.Should().BeNull(); }
public async Task Then_If_There_Is_A_Location_But_No_CourseProvider_Returned_Then_CourseProvider_Is_Retrieved_With_No_Location( string locationName, string authorityName, GetTrainingCourseProviderQuery query, GetOverallAchievementRateResponse apiResponse, GetProviderStandardItem apiProviderStandardResponse, GetStandardsListItem apiCourseResponse, GetStandardsListResponse allCoursesApiResponse, LocationItem locationLookupResponse, GetOverallAchievementRateResponse apiAchievementRateResponse, GetUkprnsForStandardAndLocationResponse ukprnsCountResponse, [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockApiClient, [Frozen] Mock <ILocationLookupService> mockLocationLookupService, GetTrainingCourseProviderQueryHandler handler) { query.Location = $"{locationName}, {authorityName} "; mockLocationLookupService .Setup(service => service.GetLocationInformation(query.Location, query.Lat, query.Lon)) .ReturnsAsync(locationLookupResponse); mockApiClient .Setup(client => client.Get <GetProviderStandardItem>(It.Is <GetProviderByCourseAndUkPrnRequest>(c => c.GetUrl.Contains(query.CourseId.ToString()) && c.GetUrl.Contains(query.ProviderId.ToString()) && c.GetUrl.Contains(locationLookupResponse.GeoPoint.First().ToString()) && c.GetUrl.Contains(locationLookupResponse.GeoPoint.Last().ToString()) ))) .ReturnsAsync((GetProviderStandardItem)null); mockApiClient .Setup(client => client.Get <GetProviderStandardItem>(It.Is <GetProviderByCourseAndUkPrnRequest>(c => c.GetUrl.Contains(query.CourseId.ToString()) && c.GetUrl.Contains(query.ProviderId.ToString()) && c.GetUrl.Contains("?lat=&lon=") && c.GetUrl.Contains($"shortlistUserId={query.ShortlistUserId}") ))) .ReturnsAsync(apiProviderStandardResponse); mockApiClient .Setup(x => x.Get <GetUkprnsForStandardAndLocationResponse>( It.Is <GetUkprnsForStandardAndLocationRequest>(c => c.GetUrl.Contains(query.CourseId.ToString())))) .ReturnsAsync(ukprnsCountResponse); mockApiClient .Setup(client => client.Get <GetProviderAdditionalStandardsItem>(It.Is <GetProviderAdditionalStandardsRequest>( c => c.GetUrl.Contains(query.ProviderId.ToString() )))) .ReturnsAsync(new GetProviderAdditionalStandardsItem { StandardIds = allCoursesApiResponse.Standards.Select(c => c.LarsCode).ToList() }); mockCoursesApiClient .Setup(client => client.Get <GetStandardsListItem>( It.Is <GetStandardRequest>(c => c.GetUrl.Contains(query.CourseId.ToString())))) .ReturnsAsync(apiCourseResponse); mockCoursesApiClient .Setup(client => client.Get <GetStandardsListResponse>(It.IsAny <GetAvailableToStartStandardsListRequest>())) .ReturnsAsync(allCoursesApiResponse); mockApiClient.Setup(client => client.Get <GetOverallAchievementRateResponse>(It.Is <GetOverallAchievementRateRequest>( c => c.GetUrl.Contains(apiCourseResponse.SectorSubjectAreaTier2Description) ))) .ReturnsAsync(apiAchievementRateResponse); var result = await handler.Handle(query, CancellationToken.None); result.ProviderStandard.Should().BeEquivalentTo(apiProviderStandardResponse); Assert.IsTrue(result.ProviderStandard.DeliveryTypes.Select(x => x.DeliveryModes).ToList().TrueForAll(x => x.Equals("NotFound"))); }