Example #1
0
        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);
        }
Example #2
0
        public void Then_If_There_Is_An_Error_From_The_Api_A_Exception_Is_Returned(
            string errorContent,
            CreateVacancyCommand command,
            GetProviderAccountLegalEntitiesResponse response,
            [Frozen] Mock <IProviderRelationshipsApiClient <ProviderRelationshipsApiConfiguration> > providerRelationshipsApiClient,
            [Frozen] Mock <IRecruitApiClient <RecruitApiConfiguration> > recruitApiClient,
            CreateVacancyCommandHandler handler)
        {
            //Arrange
            command.PostVacancyRequestData.OwnerType = OwnerType.Provider;
            response.AccountProviderLegalEntities.First().AccountLegalEntityPublicHashedId = command.PostVacancyRequestData.AccountLegalEntityPublicHashedId;
            command.IsSandbox = false;
            var apiResponse = new ApiResponse <string>(null, HttpStatusCode.InternalServerError, errorContent);

            recruitApiClient
            .Setup(client => client.PostWithResponseCode <string>(It.IsAny <PostVacancyRequest>()))
            .ReturnsAsync(apiResponse);
            providerRelationshipsApiClient.Setup(x =>
                                                 x.Get <GetProviderAccountLegalEntitiesResponse>(It.IsAny <GetProviderAccountLegalEntitiesRequest>())).ReturnsAsync(response);

            //Act
            Func <Task> act = async() => await handler.Handle(command, CancellationToken.None);

            //Assert
            act.Should().Throw <Exception>()
            .WithMessage($"Response status code does not indicate success: {(int)HttpStatusCode.InternalServerError} ({HttpStatusCode.InternalServerError})");
        }
        public async Task Then_The_Query_Is_Handled_And_Api_Called_For_Ukprn(
            GetProviderAccountLegalEntitiesResponse apiQueryResponse,
            GetProviderAccountLegalEntitiesQuery query,
            [Frozen] Mock <IProviderRelationshipsApiClient <ProviderRelationshipsApiConfiguration> > apiClient,
            GetProviderAccountLegalEntitiesQueryHandler handler)
        {
            apiClient.Setup(x =>
                            x.Get <GetProviderAccountLegalEntitiesResponse>(
                                It.Is <GetProviderAccountLegalEntitiesRequest>(c => c.GetUrl.Contains($"ukprn={query.Ukprn}"))))
            .ReturnsAsync(apiQueryResponse);

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

            actual.ProviderAccountLegalEntities.Should().BeEquivalentTo(apiQueryResponse.AccountProviderLegalEntities);
        }
Example #4
0
        public void And_The_AccountLegalEntityPublicHashedId_And_Ukprn_Is_Not_Null_And_AccountPublicHashedId_Is_Null_Then_ProviderRelations_Api_Checked_And_If_Not_In_Response_Exception_Thrown(
            GetVacanciesQuery query,
            GetProviderAccountLegalEntitiesResponse providerAccountLegalEntitiesResponse,
            [Frozen] Mock <IAccountLegalEntityPermissionService> accountLegalEntityPermissionService,
            [Frozen] Mock <IFindApprenticeshipApiClient <FindApprenticeshipApiConfiguration> > apiClient,
            GetVacanciesQueryHandler handler)
        {
            query.AccountPublicHashedId = "";
            query.AccountIdentifier     = new AccountIdentifier($"Employer-{query.Ukprn}-Product");
            accountLegalEntityPermissionService
            .Setup(x => x.GetAccountLegalEntity(It.Is <AccountIdentifier>(c => c.Equals(query.AccountIdentifier)),
                                                query.AccountLegalEntityPublicHashedId)).ReturnsAsync((AccountLegalEntityItem)null);

            Assert.ThrowsAsync <SecurityException>(() => handler.Handle(query, CancellationToken.None));
        }
        public async Task Then_If_Provider_And_AccountLegalEntity_Does_Not_Exist_Then_Null_Returned(
            int ukprn,
            string accountLegalEntityPublicHashedId,
            GetProviderAccountLegalEntitiesResponse response,
            [Frozen] Mock <IProviderRelationshipsApiClient <ProviderRelationshipsApiConfiguration> > providerRelationshipsApiClient,
            AccountLegalEntityPermissionService service)
        {
            var accountIdentifier = new AccountIdentifier($"Provider-{ukprn}-Product");

            providerRelationshipsApiClient.Setup(x =>
                                                 x.Get <GetProviderAccountLegalEntitiesResponse>(It.Is <GetProviderAccountLegalEntitiesRequest>(c =>
                                                                                                                                                c.GetUrl.Contains(accountIdentifier.Ukprn.ToString())))).ReturnsAsync(response);

            var actual = await service.GetAccountLegalEntity(accountIdentifier, accountLegalEntityPublicHashedId);

            actual.Should().BeNull();
            providerRelationshipsApiClient.Verify(x => x.Get <GetProviderAccountLegalEntitiesResponse>(It.IsAny <GetProviderAccountLegalEntitiesRequest>()), Times.Once);
        }
        public async Task Then_If_Provider_The_Provider_Relations_Api_Is_Checked(
            int ukprn,
            string accountLegalEntityPublicHashedId,
            GetProviderAccountLegalEntitiesResponse response,
            [Frozen] Mock <IProviderRelationshipsApiClient <ProviderRelationshipsApiConfiguration> > providerRelationshipsApiClient,
            AccountLegalEntityPermissionService service)
        {
            var accountIdentifier = new AccountIdentifier($"Provider-{ukprn}-Product");

            response.AccountProviderLegalEntities.First().AccountLegalEntityPublicHashedId = accountLegalEntityPublicHashedId;
            providerRelationshipsApiClient.Setup(x =>
                                                 x.Get <GetProviderAccountLegalEntitiesResponse>(It.Is <GetProviderAccountLegalEntitiesRequest>(c =>
                                                                                                                                                c.GetUrl.Contains(accountIdentifier.Ukprn.ToString())))).ReturnsAsync(response);

            var actual = await service.GetAccountLegalEntity(accountIdentifier, accountLegalEntityPublicHashedId);

            actual.Name.Should().Be(response.AccountProviderLegalEntities.First().AccountLegalEntityName);
            actual.AccountLegalEntityPublicHashedId.Should().Be(response.AccountProviderLegalEntities.First().AccountLegalEntityPublicHashedId);
            actual.AccountHashedId.Should().Be(response.AccountProviderLegalEntities.First().AccountHashedId);
        }