public async Task Then_If_There_Is_A_Location_Supplied_It_Is_Searched_And_Passed_To_The_Provider_Search(
            string locationName,
            string authorityName,
            GetTrainingCourseProvidersQuery query,
            GetProvidersListResponse apiResponse,
            IEnumerable <GetApprenticeFeedbackResponse> apprenticeFeedbackResponse,
            GetStandardsListItem apiCourseResponse,
            LocationItem locationServiceResponse,
            [Frozen] Mock <ILocationLookupService> mockLocationLookupService,
            [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient,
            [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockApiClient,
            [Frozen] Mock <IApprenticeFeedbackApiClient <ApprenticeFeedbackApiConfiguration> > mockApprenticeFeedbackApiClient,
            GetTrainingCourseProvidersQueryHandler handler)
        {
            query.Location = $"{locationName}, {authorityName} ";
            query.Lat      = 0;
            query.Lon      = 0;

            var providerUkprns = apiResponse.Providers.Select(s => s.Ukprn);

            for (var i = 0; i < apprenticeFeedbackResponse.Count(); i++)
            {
                apprenticeFeedbackResponse.ToArray()[i].Ukprn = providerUkprns.ToArray()[i];
            }

            mockLocationLookupService
            .Setup(service => service.GetLocationInformation(query.Location, query.Lat, query.Lon, false))
            .ReturnsAsync(locationServiceResponse);
            mockApiClient
            .Setup(client => client.Get <GetProvidersListResponse>(It.Is <GetProvidersByCourseRequest>(c =>
                                                                                                       c.GetUrl.Contains(query.Id.ToString()) &&
                                                                                                       c.GetUrl.Contains(locationServiceResponse.GeoPoint.First().ToString()) &&
                                                                                                       c.GetUrl.Contains(locationServiceResponse.GeoPoint.Last().ToString()) &&
                                                                                                       c.GetUrl.Contains($"&sortOrder={query.SortOrder}")
                                                                                                       )))
            .ReturnsAsync(apiResponse);
            mockCoursesApiClient
            .Setup(client => client.Get <GetStandardsListItem>(It.Is <GetStandardRequest>(c => c.GetUrl.Contains(query.Id.ToString()))))
            .ReturnsAsync(apiCourseResponse);
            mockApprenticeFeedbackApiClient
            .Setup(s => s.PostWithResponseCode <IEnumerable <GetApprenticeFeedbackResponse> >(It.Is <PostApprenticeFeedbackRequest>
                                                                                                  (t =>
                                                                                                  ((PostApprenticeFeedbackRequestData)t.Data).Ukprns.Except(apiResponse.Providers.Select(s => s.Ukprn)).Count() == 0 &&
                                                                                                  apiResponse.Providers.Select(s => s.Ukprn).Except(((PostApprenticeFeedbackRequestData)t.Data).Ukprns).Count() == 0
                                                                                                  ))).ReturnsAsync(new ApiResponse <IEnumerable <GetApprenticeFeedbackResponse> >(apprenticeFeedbackResponse, HttpStatusCode.OK, string.Empty));

            var result = await handler.Handle(query, CancellationToken.None);

            result.Providers.Should().BeEquivalentTo(apiResponse.Providers, options => options.Excluding(s => s.ApprenticeFeedback));
            result.Total.Should().Be(apiResponse.TotalResults);
            result.Course.Should().BeEquivalentTo(apiCourseResponse);
            result.Location.Name.Should().Be(locationServiceResponse.Name);
            result.Location.GeoPoint.Should().BeEquivalentTo(locationServiceResponse.GeoPoint);

            foreach (var provider in result.Providers)
            {
                provider.ApprenticeFeedback.Should().BeEquivalentTo(apprenticeFeedbackResponse.First(s => s.Ukprn == provider.Ukprn));
            }
        }
        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,
            IEnumerable <GetApprenticeFeedbackResponse> apprenticeFeedbackResponse,
            int shortlistItemCount,
            [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient,
            [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockApiClient,
            [Frozen] Mock <IApprenticeFeedbackApiClient <ApprenticeFeedbackApiConfiguration> > mockApprenticeFeedbackApiClient,
            [Frozen] Mock <IShortlistService> shortlistService,
            [Frozen] Mock <ILocationLookupService> mockLocationLookup,
            GetTrainingCourseProvidersQueryHandler handler)
        {
            apiCourseResponse.Level = 1;
            query.Location          = "";
            query.Lat = 0;
            query.Lon = 0;

            var providerUkprns = apiResponse.Providers.Select(s => s.Ukprn);

            for (var i = 0; i < apprenticeFeedbackResponse.Count(); i++)
            {
                apprenticeFeedbackResponse.ToArray()[i].Ukprn = providerUkprns.ToArray()[i];
            }

            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);
            shortlistService.Setup(x => x.GetShortlistItemCount(query.ShortlistUserId))
            .ReturnsAsync(shortlistItemCount);
            mockLocationLookup
            .Setup(service => service.GetLocationInformation(query.Location, query.Lat, query.Lon, false))
            .ReturnsAsync((LocationItem)null);
            mockApprenticeFeedbackApiClient
            .Setup(s => s.PostWithResponseCode <IEnumerable <GetApprenticeFeedbackResponse> >(It.Is <PostApprenticeFeedbackRequest>
                                                                                                  (t =>
                                                                                                  ((PostApprenticeFeedbackRequestData)t.Data).Ukprns.Except(apiResponse.Providers.Select(s => s.Ukprn)).Count() == 0 &&
                                                                                                  apiResponse.Providers.Select(s => s.Ukprn).Except(((PostApprenticeFeedbackRequestData)t.Data).Ukprns).Count() == 0
                                                                                                  ))).ReturnsAsync(new ApiResponse <IEnumerable <GetApprenticeFeedbackResponse> >(apprenticeFeedbackResponse, HttpStatusCode.OK, string.Empty));

            var result = await handler.Handle(query, CancellationToken.None);

            result.Providers.Should().BeEquivalentTo(apiResponse.Providers, options => options.Excluding(s => s.ApprenticeFeedback));
            result.Total.Should().Be(apiResponse.TotalResults);
            result.Course.Should().BeEquivalentTo(apiCourseResponse);
            result.ShortlistItemCount.Should().Be(shortlistItemCount);
            result.Location.Should().BeNull();

            foreach (var provider in result.Providers)
            {
                provider.ApprenticeFeedback.Should().BeEquivalentTo(apprenticeFeedbackResponse.First(s => s.Ukprn == provider.Ukprn));
            }
        }
        public async Task Then_The_Api_Is_Called_With_The_Request_And_Providers_Returned(
            GetProvidersQuery query,
            GetProvidersListResponse apiResponse,
            [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > apiClient,
            GetProvidersQueryHandler handler
            )
        {
            apiClient.Setup(x => x.Get <GetProvidersListResponse>(It.IsAny <GetProvidersRequest>())).ReturnsAsync(apiResponse);

            var actual = await handler.Handle(query, CancellationToken.None);

            actual.Providers.Should().BeEquivalentTo(apiResponse.Providers);
        }
        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();
        }
Пример #5
0
        public async Task <IActionResult> GetAll()
        {
            try
            {
                var result = await _mediator.Send(new GetProvidersQuery());

                var model = new GetProvidersListResponse
                {
                    Providers = result.Providers.Select(c => (GetProvidersResponse)c)
                };
                return(Ok(model));
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error getting all providers");
                return(BadRequest());
            }
        }
        public async Task Then_If_There_Is_A_Location_Supplied_It_Is_Searched_And_Passed_To_The_Provider_Search(
            string locationName,
            string authorityName,
            GetTrainingCourseProvidersQuery query,
            GetProvidersListResponse apiResponse,
            GetStandardsListItem apiCourseResponse,
            LocationItem locationServiceResponse,
            [Frozen] Mock <IOptions <FindApprenticeshipTrainingConfiguration> > config,
            [Frozen] Mock <ILocationLookupService> mockLocationLookupService,
            [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient,
            [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockApiClient,
            GetTrainingCourseProvidersQueryHandler handler)
        {
            config.Object.Value.EmployerDemandFeatureToggle = true;
            query.Location = $"{locationName}, {authorityName} ";
            query.Lat      = 0;
            query.Lon      = 0;

            mockLocationLookupService
            .Setup(service => service.GetLocationInformation(query.Location, query.Lat, query.Lon))
            .ReturnsAsync(locationServiceResponse);
            mockApiClient
            .Setup(client => client.Get <GetProvidersListResponse>(It.Is <GetProvidersByCourseRequest>(c =>
                                                                                                       c.GetUrl.Contains(query.Id.ToString()) &&
                                                                                                       c.GetUrl.Contains(locationServiceResponse.GeoPoint.First().ToString()) &&
                                                                                                       c.GetUrl.Contains(locationServiceResponse.GeoPoint.Last().ToString()) &&
                                                                                                       c.GetUrl.Contains($"&sortOrder={query.SortOrder}")
                                                                                                       )))
            .ReturnsAsync(apiResponse);
            mockCoursesApiClient
            .Setup(client => client.Get <GetStandardsListItem>(It.Is <GetStandardRequest>(c => c.GetUrl.Contains(query.Id.ToString()))))
            .ReturnsAsync(apiCourseResponse);

            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.Location.Name.Should().Be(locationServiceResponse.Name);
            result.Location.GeoPoint.Should().BeEquivalentTo(locationServiceResponse.GeoPoint);
        }
        public async Task Then_Gets_The_Standard_And_The_List_Of_Providers_For_That_Course_From_Course_Delivery_Api_Client(
            GetTrainingCourseProvidersQuery query,
            GetProvidersListResponse apiResponse,
            GetStandardsListItem apiCourseResponse,
            [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient,
            [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockApiClient,
            GetTrainingCourseProvidersQueryHandler handler)
        {
            mockApiClient
            .Setup(client => client.Get <GetProvidersListResponse>(It.Is <GetProvidersByCourseRequest>(c => c.GetUrl.Contains(query.Id.ToString()))))
            .ReturnsAsync(apiResponse);
            mockCoursesApiClient
            .Setup(client => client.Get <GetStandardsListItem>(It.Is <GetStandardRequest>(c => c.GetUrl.Contains(query.Id.ToString()))))
            .ReturnsAsync(apiCourseResponse);

            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);
        }
        public async Task And_If_Feature_Not_Enabled_For_Employer_Demand_Then_Show_Demand_False(
            GetTrainingCourseProvidersQuery query,
            GetProvidersListResponse apiResponse,
            GetStandardsListItem apiCourseResponse,
            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,
            GetTrainingCourseProvidersQueryHandler handler)
        {
            config.Object.Value.EmployerDemandFeatureToggle = false;
            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.Forbidden);
            shortlistService.Setup(x => x.GetShortlistItemCount(query.ShortlistUserId))
            .ReturnsAsync(shortlistItemCount);

            var result = await handler.Handle(query, CancellationToken.None);

            result.ShowEmployerDemand.Should().BeFalse();
            mockEmployerDemandApiClient
            .Verify(client => client.GetResponseCode(It.IsAny <GetShowEmployerDemandRequest>()), Times.Never);
        }