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_Gets_The_Standard_And_The_List_Of_Providers_For_That_Course_From_Course_Delivery_Api_Client_With_No_Location_And_ShortlistItem_Count( GetTrainingCourseProvidersQuery query, GetProvidersListResponse apiResponse, GetStandardsListItem apiCourseResponse, GetShowEmployerDemandResponse showEmployerDemandResponse, int shortlistItemCount, [Frozen] Mock <IOptions <FindApprenticeshipTrainingConfiguration> > config, [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockApiClient, [Frozen] Mock <IEmployerDemandApiClient <EmployerDemandApiConfiguration> > mockEmployerDemandApiClient, [Frozen] Mock <IShortlistService> shortlistService, [Frozen] Mock <ILocationLookupService> mockLocationLookup, GetTrainingCourseProvidersQueryHandler handler) { config.Object.Value.EmployerDemandFeatureToggle = true; apiCourseResponse.Level = 1; query.Location = ""; query.Lat = 0; query.Lon = 0; mockApiClient .Setup(client => client.Get <GetProvidersListResponse>(It.Is <GetProvidersByCourseRequest>(c => c.GetUrl.Contains(query.Id.ToString()) && c.GetUrl.Contains($"sectorSubjectArea={apiCourseResponse.SectorSubjectAreaTier2Description}&level={apiCourseResponse.Level}") ))) .ReturnsAsync(apiResponse); mockCoursesApiClient .Setup(client => client.Get <GetStandardsListItem>(It.Is <GetStandardRequest>(c => c.GetUrl.Contains(query.Id.ToString())))) .ReturnsAsync(apiCourseResponse); mockEmployerDemandApiClient .Setup(client => client.GetResponseCode(It.IsAny <GetShowEmployerDemandRequest>())) .ReturnsAsync(HttpStatusCode.OK); shortlistService.Setup(x => x.GetShortlistItemCount(query.ShortlistUserId)) .ReturnsAsync(shortlistItemCount); mockLocationLookup .Setup(service => service.GetLocationInformation(query.Location, query.Lat, query.Lon)) .ReturnsAsync((LocationItem)null); var result = await handler.Handle(query, CancellationToken.None); result.Providers.Should().BeEquivalentTo(apiResponse.Providers); result.Total.Should().Be(apiResponse.TotalResults); result.Course.Should().BeEquivalentTo(apiCourseResponse); result.ShowEmployerDemand.Should().BeTrue(); result.ShortlistItemCount.Should().Be(shortlistItemCount); result.Location.Should().BeNull(); }