public async Task Then_The_Api_Is_Called_With_The_Request_And_Vacancies_Returned( GetVacanciesQuery query, GetVacanciesResponse apiResponse, List <string> categories, GetStandardsListItem courseResponse, [Frozen] Mock <ICourseService> courseService, [Frozen] Mock <IFindApprenticeshipApiClient <FindApprenticeshipApiConfiguration> > apiClient, GetVacanciesQueryHandler handler) { courseService.Setup(x => x.MapRoutesToCategories(query.Routes)).Returns(categories); query.AccountLegalEntityPublicHashedId = ""; var expectedGetRequest = new GetVacanciesRequest(query.PageNumber, query.PageSize, query.AccountLegalEntityPublicHashedId, query.Ukprn, query.AccountPublicHashedId, query.StandardLarsCode, query.NationWideOnly, query.Lat, query.Lon, query.DistanceInMiles, categories, query.PostedInLastNumberOfDays, query.Sort); apiClient.Setup(x => x.Get <GetVacanciesResponse>(It.Is <GetVacanciesRequest>(c => c.GetUrl.Equals(expectedGetRequest.GetUrl)))).ReturnsAsync(apiResponse); courseService.Setup(x => x.GetActiveStandards <GetStandardsListResponse>(nameof(GetStandardsListResponse))).ReturnsAsync(new GetStandardsListResponse { Standards = new List <GetStandardsListItem> { courseResponse } }); var actual = await handler.Handle(query, CancellationToken.None); actual.Vacancies.Should().BeEquivalentTo(apiResponse.ApprenticeshipVacancies); actual.Total.Should().Be(apiResponse.Total); actual.TotalFiltered.Should().Be(apiResponse.TotalFound); actual.TotalPages.Should().Be((int)Math.Ceiling((decimal)apiResponse.TotalFound / query.PageSize)); }
public async Task And_The_AccountIdentifier_Is_External_Then_HashedIds_Are_Not_Set( Guid externalId, GetVacanciesQuery query, GetVacanciesResponse apiResponse, GetProviderAccountLegalEntitiesResponse providerAccountLegalEntitiesResponse, GetStandardsListResponse courses, [Frozen] Mock <ICourseService> courseService, [Frozen] Mock <IAccountLegalEntityPermissionService> accountLegalEntityPermissionService, [Frozen] Mock <IFindApprenticeshipApiClient <FindApprenticeshipApiConfiguration> > apiClient, GetVacanciesQueryHandler handler) { query.Routes = new List <string>(); query.AccountPublicHashedId = ""; query.AccountIdentifier = new AccountIdentifier($"External-{externalId}-Product"); var expectedGetRequest = new GetVacanciesRequest(query.PageNumber, query.PageSize, "", query.Ukprn, query.AccountPublicHashedId, query.StandardLarsCode, query.NationWideOnly, query.Lat, query.Lon, query.DistanceInMiles, new List <string>(), query.PostedInLastNumberOfDays, query.Sort); courseService.Setup(x => x.MapRoutesToCategories(query.Routes)).Returns(new List <string>()); apiClient.Setup(x => x.Get <GetVacanciesResponse>(It.Is <GetVacanciesRequest>(c => c.GetUrl.Equals(expectedGetRequest.GetUrl)))).ReturnsAsync(apiResponse); courseService.Setup(x => x.GetActiveStandards <GetStandardsListResponse>(nameof(GetStandardsListResponse))).ReturnsAsync(courses); var actual = await handler.Handle(query, CancellationToken.None); actual.Vacancies.Should().BeEquivalentTo(apiResponse.ApprenticeshipVacancies); accountLegalEntityPermissionService .Verify(x => x.GetAccountLegalEntity(It.IsAny <AccountIdentifier>(), query.AccountLegalEntityPublicHashedId), Times.Never); }
public async Task And_The_AccountLegalEntityPublicHashedId_And_Ukprn_Is_Not_Null_And_AccountPublicHashedId_Is_Null_Then_Permission_Checked( GetVacanciesQuery query, GetVacanciesResponse apiResponse, AccountLegalEntityItem accountLegalEntityItem, GetStandardsListResponse courses, [Frozen] Mock <ICourseService> courseService, [Frozen] Mock <IAccountLegalEntityPermissionService> accountLegalEntityPermissionService, [Frozen] Mock <IFindApprenticeshipApiClient <FindApprenticeshipApiConfiguration> > apiClient, GetVacanciesQueryHandler handler) { query.Routes = null; query.AccountIdentifier = new AccountIdentifier("Employer-ABC123-Product"); var expectedGetRequest = new GetVacanciesRequest(query.PageNumber, query.PageSize, query.AccountLegalEntityPublicHashedId, query.Ukprn, query.AccountPublicHashedId, query.StandardLarsCode, query.NationWideOnly, query.Lat, query.Lon, query.DistanceInMiles, new List <string>(), query.PostedInLastNumberOfDays, query.Sort); courseService.Setup(x => x.MapRoutesToCategories(query.Routes)).Returns(new List <string>()); apiClient.Setup(x => x.Get <GetVacanciesResponse>(It.Is <GetVacanciesRequest>(c => c.GetUrl.Equals(expectedGetRequest.GetUrl)))).ReturnsAsync(apiResponse); accountLegalEntityPermissionService .Setup(x => x.GetAccountLegalEntity(It.Is <AccountIdentifier>(c => c.Equals(query.AccountIdentifier)), query.AccountLegalEntityPublicHashedId)).ReturnsAsync(accountLegalEntityItem); courseService.Setup(x => x.GetActiveStandards <GetStandardsListResponse>(nameof(GetStandardsListResponse))).ReturnsAsync(courses); var actual = await handler.Handle(query, CancellationToken.None); actual.Vacancies.Should().BeEquivalentTo(apiResponse.ApprenticeshipVacancies); }
public async Task And_The_AccountLegalEntityPublicHashedId_Is_Null_Then_No_LegalEntity_Check_Is_Performed( GetVacanciesQuery query, GetVacanciesResponse apiResponse, GetStandardsListResponse courses, [Frozen] Mock <ICourseService> courseService, [Frozen] Mock <IAccountsApiClient <AccountsConfiguration> > accountsApi, [Frozen] Mock <IProviderRelationshipsApiClient <ProviderRelationshipsApiConfiguration> > providerRelationshipsApiClient, [Frozen] Mock <IFindApprenticeshipApiClient <FindApprenticeshipApiConfiguration> > apiClient, GetVacanciesQueryHandler handler) { query.Routes = null; query.AccountLegalEntityPublicHashedId = ""; var expectedGetRequest = new GetVacanciesRequest(query.PageNumber, query.PageSize, query.AccountLegalEntityPublicHashedId, query.Ukprn, query.AccountPublicHashedId, query.StandardLarsCode, query.NationWideOnly, query.Lat, query.Lon, query.DistanceInMiles, new List <string>(), query.PostedInLastNumberOfDays, query.Sort); courseService.Setup(x => x.MapRoutesToCategories(query.Routes)).Returns(new List <string>()); apiClient.Setup(x => x.Get <GetVacanciesResponse>(It.Is <GetVacanciesRequest>(c => c.GetUrl.Equals(expectedGetRequest.GetUrl)))).ReturnsAsync(apiResponse); courseService.Setup(x => x.GetActiveStandards <GetStandardsListResponse>(nameof(GetStandardsListResponse))).ReturnsAsync(courses); await handler.Handle(query, CancellationToken.None); accountsApi.Verify(x => x.Get <AccountDetail>(It.IsAny <GetAllEmployerAccountLegalEntitiesRequest>()), Times.Never); providerRelationshipsApiClient.Verify(x => x.Get <GetProviderAccountLegalEntitiesResponse>(It.IsAny <GetProviderAccountLegalEntitiesRequest>()), Times.Never); }
public async Task Then_The_Route_And_CourseTitle_Are_Taken_From_Standards_Service_And_Ignored_For_Null( int standardLarsCode, string findAnApprenticeshipBaseUrl, GetVacanciesQuery query, GetVacanciesResponse apiResponse, GetStandardsListItem courseResponse, [Frozen] Mock <IFindApprenticeshipApiClient <FindApprenticeshipApiConfiguration> > apiClient, [Frozen] Mock <ICourseService> courseService, [Frozen] Mock <IOptions <VacanciesConfiguration> > vacanciesConfiguration, GetVacanciesQueryHandler handler) { vacanciesConfiguration.Object.Value.FindAnApprenticeshipBaseUrl = findAnApprenticeshipBaseUrl; courseResponse.LarsCode = standardLarsCode; foreach (var vacanciesItem in apiResponse.ApprenticeshipVacancies) { vacanciesItem.StandardLarsCode = standardLarsCode; } apiResponse.ApprenticeshipVacancies.First().StandardLarsCode = null; query.AccountLegalEntityPublicHashedId = ""; var expectedGetRequest = new GetVacanciesRequest(query.PageNumber, query.PageSize, query.AccountLegalEntityPublicHashedId, query.Ukprn, query.AccountPublicHashedId, query.StandardLarsCode, query.NationWideOnly, query.Lat, query.Lon, query.DistanceInMiles, new List <string>(), query.PostedInLastNumberOfDays, query.Sort); apiClient.Setup(x => x.Get <GetVacanciesResponse>(It.Is <GetVacanciesRequest>(c => c.GetUrl.Equals(expectedGetRequest.GetUrl)))).ReturnsAsync(apiResponse); courseService.Setup(x => x.GetActiveStandards <GetStandardsListResponse>(nameof(GetStandardsListResponse))).ReturnsAsync(new GetStandardsListResponse { Standards = new List <GetStandardsListItem> { courseResponse } }); courseService.Setup(x => x.MapRoutesToCategories(query.Routes)).Returns(new List <string>()); var actual = await handler.Handle(query, CancellationToken.None); actual.Vacancies.ToList().TrueForAll(c => c.CourseTitle.Equals(courseResponse.Title) && c.Route.Equals(courseResponse.Route) && c.CourseLevel.Equals(courseResponse.Level) ).Should().BeTrue(); foreach (var vacancy in actual.Vacancies) { vacancy.VacancyUrl.Should().Be($"{findAnApprenticeshipBaseUrl}/apprenticeship/reference/{vacancy.VacancyReference}"); } }
public async Task Then_If_There_Is_A_AccountLegalEntityPublicHashedId_And_No_Account_Or_Ukprn_Then_Exception_Thrown( GetVacanciesQuery query, GetVacanciesResponse apiResponse, AccountDetail accountDetailApiResponse, [Frozen] Mock <IAccountsApiClient <AccountsConfiguration> > accountsApi, [Frozen] Mock <IProviderRelationshipsApiClient <ProviderRelationshipsApiConfiguration> > providerRelationshipsApiClient, [Frozen] Mock <IFindApprenticeshipApiClient <FindApprenticeshipApiConfiguration> > apiClient, GetVacanciesQueryHandler handler) { query.AccountPublicHashedId = null; query.Ukprn = null; Assert.ThrowsAsync <SecurityException>(() => handler.Handle(query, CancellationToken.None)); providerRelationshipsApiClient.Verify(x => x.Get <GetProviderAccountLegalEntitiesResponse>(It.IsAny <GetProviderAccountLegalEntitiesRequest>()), Times.Never); accountsApi.Verify(x => x.Get <AccountDetail>(It.IsAny <GetAllEmployerAccountLegalEntitiesRequest>()), Times.Never); apiClient.Verify(x => x.Get <GetVacanciesResponse>(It.IsAny <GetVacanciesRequest>()), Times.Never); }
public async Task Then_The_Routes_Are_Filtered_And_Postcode_Searched_And_Adverts_Returned( string findAnApprenticeshipBaseUrl, GetAdvertsQuery query, List <string> categories, LocationItem locationItem, GetVacanciesResponse vacanciesResponse, GetRoutesListResponse getRoutesListResponse, GetStandardsListResponse standards, [Frozen] Mock <IOptions <CampaignConfiguration> > configuration, [Frozen] Mock <ICourseService> courseService, [Frozen] Mock <ILocationLookupService> locationLookupService, [Frozen] Mock <IFindApprenticeshipApiClient <FindApprenticeshipApiConfiguration> > faaApiClient, GetAdvertsQueryHandler handler) { //Arrange query.Route = standards.Standards.First().Route.ToLower(); configuration.Object.Value.FindAnApprenticeshipBaseUrl = findAnApprenticeshipBaseUrl; var expectedAdvertUrl = new GetVacanciesRequest(0, 20, null, null, null, new List <int> { standards.Standards.First().LarsCode }, null, locationItem.GeoPoint.First(), locationItem.GeoPoint.Last(), query.Distance, null, null, "DistanceAsc"); locationLookupService.Setup(x => x.GetLocationInformation(query.Postcode, 0, 0, false)) .ReturnsAsync(locationItem); faaApiClient .Setup(x => x.Get <GetVacanciesResponse>(It.Is <GetVacanciesRequest>(c => c.GetUrl.Equals(expectedAdvertUrl.GetUrl)))).ReturnsAsync(vacanciesResponse); courseService.Setup(x => x.GetRoutes()).ReturnsAsync(getRoutesListResponse); courseService.Setup(x => x.GetActiveStandards <GetStandardsListResponse>(nameof(GetStandardsListResponse))).ReturnsAsync(standards); var actual = await handler.Handle(query, CancellationToken.None); actual.Vacancies.Should().BeEquivalentTo(vacanciesResponse.ApprenticeshipVacancies); actual.TotalFound.Should().Be(vacanciesResponse.ApprenticeshipVacancies.Count()); actual.Routes.Should().BeEquivalentTo(getRoutesListResponse.Routes); actual.Location.Should().BeEquivalentTo(locationItem); foreach (var vacancy in actual.Vacancies) { vacancy.VacancyUrl.Should().Be($"{findAnApprenticeshipBaseUrl}/apprenticeship/reference/{vacancy.VacancyReference}"); } }