public IQueryable <ApprenticeVacancy> GetApprenticeVacanciesBySocCode(string socCode) { var socCodeItem = repository.Get(item => item.Visible && item.Status == ContentLifecycleStatus.Live && item.GetValue <string>(nameof(SocCode.SOCCode)) == socCode); var vacancies = dynamicContentExtensions.GetRelatedParentItems(socCodeItem, DynamicTypes.JobProfileApprenticeshipContentType, repository.GetProviderName()); if (vacancies.Any()) { return(vacancies.Select(item => converter.ConvertFrom(item))); } return(Enumerable.Empty <ApprenticeVacancy>().AsQueryable()); }
public void GetByJobProfileUrlNameTests(string urlName, bool validJobProfile, bool validDataInjection) { //Assign //Setup Fakes A.CallTo(() => fakeJobprofileRepository.Get(A <Expression <Func <DynamicContent, bool> > > ._)).Returns(validJobProfile ? dummyDynamicContent : null); A.CallTo(() => fakeDynamicContentExtensions.GetRelatedParentItems(A <DynamicContent> ._, A <string> ._, A <string> ._)).Returns(validDataInjection ? new EnumerableQuery <DynamicContent>(new List <DynamicContent> { dummyDynamicContent }) : Enumerable.Empty <DynamicContent>().AsQueryable()); A.CallTo(() => fakeConverter.ConvertFrom(A <DynamicContent> ._)).Returns(new StructuredDataInjection()); //Act var result = structuredDataInjectionRepository.GetByJobProfileUrlName(urlName); //Assert A.CallTo(() => fakeJobprofileRepository.Get(A <Expression <Func <DynamicContent, bool> > > ._)) .MustHaveHappenedOnceExactly(); if (validDataInjection) { A.CallTo(() => fakeConverter.ConvertFrom(A <DynamicContent> ._)) .MustHaveHappenedOnceExactly(); } if (!validDataInjection || !validJobProfile) { result.Should().BeNull(); } }
public StructuredDataInjection GetByJobProfileUrlName(string urlName) { var jobProfile = jobprofileRepository.Get(item => item.UrlName == urlName && item.Status == ContentLifecycleStatus.Live && item.Visible); if (jobProfile != null) { var structuredDataItems = dynamicContentExtensions.GetRelatedParentItems(jobProfile, DynamicTypes.StructuredDataInjectionContentType, structuredDataDynamicModuleRepository.GetProviderName()); if (structuredDataItems.Any()) { var structuredDataItem = converter.ConvertFrom(structuredDataItems.First()); structuredDataItem.JobProfileLinkName = urlName; return(structuredDataItem); } } return(null); }
public void GetApprenticeVacanciesBySocCodeTest(bool validSoc) { //Assign var fakeRepo = GetTestJobProfileSocCodeRepository(validSoc); var socCode = nameof(JobProfileSocCodeRepositoryTest); //Act var result = fakeRepo.GetApprenticeVacanciesBySocCode(socCode); //Assert if (validSoc) { result.Should().NotBeEmpty(); } else { result.Should().BeEmpty(); } A.CallTo(() => fakeDynamicContentExtensions.GetRelatedParentItems(A <DynamicContent> ._, A <string> ._, A <string> ._)).MustHaveHappened(); A.CallTo(() => fakeRepository.Get(A <Expression <Func <DynamicContent, bool> > > .That.Matches(m => LinqExpressionsTestHelper.IsExpressionEqual(m, item => item.Visible && item.Status == ContentLifecycleStatus.Live && item.GetValue <string>(nameof(SocCode.SOCCode)) == socCode)))).MustHaveHappened(); }