public void UpsertSocSkillMatrixTest(bool skillAvailable) { //Arrange var dummySocSkill = new SocSkillMatrix { Title = "title test", SocCode = nameof(SocSkillMatrix.SocCode), Skill = nameof(SocSkillMatrix.Skill) }; var dummyDynamicContent = A.Dummy <DynamicContent>(); // Dummies and fakes SetupRepositoryCalls(dummyDynamicContent, skillAvailable); var socSkillMatrixRepository = new SocSkillMatrixRepository(fakeFrameworkSkillRepository, fakeSocMatrixRepository, fakeDynamicContentExtensions, fakeSocCodeRepository, fakeSocSkillConverter); // Act socSkillMatrixRepository.UpsertSocSkillMatrix(dummySocSkill); // Assert if (!skillAvailable) { A.CallTo(() => fakeSocMatrixRepository.Create()).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeSocMatrixRepository.Add(dummyDynamicContent)).MustHaveHappenedOnceExactly(); } else { A.CallTo(() => fakeSocMatrixRepository.GetMaster(dummyDynamicContent)) .MustHaveHappenedOnceExactly(); A.CallTo(() => fakeSocMatrixRepository.GetTemp(dummyDynamicContent)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeSocMatrixRepository.CheckinTemp(dummyDynamicContent)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeSocMatrixRepository.Publish(dummyDynamicContent, A <string> ._)) .MustHaveHappenedOnceExactly(); A.CallTo(() => fakeDynamicContentExtensions.SetRelatedFieldValue(dummyDynamicContent, dummyDynamicContent, A <string> ._, A <float> ._)).MustHaveHappened(2, Times.OrLess); A.CallTo(() => fakeDynamicContentExtensions.DeleteRelatedFieldValues(dummyDynamicContent, A <string> ._)) .MustHaveHappened(2, Times.OrLess); A.CallTo(() => fakeDynamicContentExtensions.SetFieldValue(dummyDynamicContent, A <string> ._, A <string> ._)) .MustHaveHappened(); A.CallTo(() => fakeDynamicContentExtensions.SetFieldValue(dummyDynamicContent, A <string> ._, A <decimal?> ._)) .MustHaveHappened(2, Times.Exactly); A.CallTo(() => fakeSocCodeRepository.Get(A <Expression <Func <DynamicContent, bool> > > .That.Matches(m => LinqExpressionsTestHelper.IsExpressionEqual(m, d => d.Status == ContentLifecycleStatus.Master && d.GetValue <string>(nameof(SocCode.SOCCode)) == dummySocSkill.SocCode)))) .MustHaveHappened(); A.CallTo(() => fakeSocMatrixRepository.Get(A <Expression <Func <DynamicContent, bool> > > .That.Matches(m => LinqExpressionsTestHelper.IsExpressionEqual(m, item => item.Visible && item.Status == ContentLifecycleStatus.Live && item.UrlName == dummySocSkill.SfUrlName)))).MustHaveHappened(); A.CallTo(() => fakeSocMatrixRepository.Commit()).MustHaveHappened(); } }
public void GetSocSkillMatricesTest(bool skillsAvailable) { //Arrange var dummySkill = A.Dummy <SocSkillMatrix>(); var dummyDynamicContent = A.Dummy <DynamicContent>(); // Dummies and fakes A.CallTo(() => fakeSocSkillConverter.ConvertFrom(dummyDynamicContent)).Returns(dummySkill); A.CallTo(() => fakeSocMatrixRepository.GetMany(A <Expression <Func <DynamicContent, bool> > > ._)).Returns(new EnumerableQuery <DynamicContent>(new List <DynamicContent> { skillsAvailable?dummyDynamicContent: null })); var socSkillMatrixRepository = new SocSkillMatrixRepository(fakeFrameworkSkillRepository, fakeSocMatrixRepository, fakeDynamicContentExtensions, fakeSocCodeRepository, fakeSocSkillConverter); // Act socSkillMatrixRepository.GetSocSkillMatrices(); // Assert // Needs investigation as fake convertor not registering call made to it when there is a soc skill available. //if (skillsAvailable) //{ // A.CallTo(() => fakeFrameworkSkillConverter.ConvertFrom(A<DynamicContent>._)).MustHaveHappened(); //} //else //{ // A.CallTo(() => fakeFrameworkSkillConverter.ConvertFrom(A<DynamicContent>._)).MustNotHaveHappened(); //} A.CallTo(() => fakeSocMatrixRepository.GetMany(A <Expression <Func <DynamicContent, bool> > > .That.Matches(m => LinqExpressionsTestHelper.IsExpressionEqual(m, item => item.Visible && item.Status == ContentLifecycleStatus.Live)))).MustHaveHappened(); }
public void GetJobProfileCategoriesTests() { A.CallTo(() => fakeTaxonomyRepository.GetMany(A <Expression <Func <HierarchicalTaxon, bool> > > ._)).Returns(new EnumerableQuery <HierarchicalTaxon>(new List <HierarchicalTaxon> { dummyTaxon })); //Instantiate var jobProfileCategoryRepository = GetTestJobProfileCategoryRepository(); var retunedCategories = jobProfileCategoryRepository.GetJobProfileCategories(); //Asset - should get back the same number retunedCategories.Should().HaveCount(1); A.CallTo(() => fakeTaxonomyRepository.Get(A <Expression <Func <HierarchicalTaxon, bool> > > ._)).MustNotHaveHappened(); A.CallTo(() => fakeTaxonomyRepository.GetMany(A <Expression <Func <HierarchicalTaxon, bool> > > .That.Matches(m => LinqExpressionsTestHelper.IsExpressionEqual(m, category => category.Taxonomy.Name == JobprofileTaxonomyName)))).MustHaveHappened(); }
public void UpsertFrameworkSkillTest(bool skillAvailable) { //Arrange var dummySkill = new FrameworkSkill { Title = "title test" }; var dummyDynamicContent = A.Dummy <DynamicContent>(); // Dummies and fakes A.CallTo(() => fakeFrameworkSkillRepository.Get(A <Expression <Func <DynamicContent, bool> > > ._)).Returns(skillAvailable ? dummyDynamicContent : null); A.CallTo(() => fakeFrameworkSkillRepository.GetMaster(dummyDynamicContent)).Returns(dummyDynamicContent); A.CallTo(() => fakeFrameworkSkillRepository.GetTemp(dummyDynamicContent)).Returns(dummyDynamicContent); A.CallTo(() => fakeFrameworkSkillRepository.CheckinTemp(dummyDynamicContent)).Returns(dummyDynamicContent); A.CallTo(() => fakeFrameworkSkillRepository.Create()).Returns(dummyDynamicContent); A.CallTo(() => fakeFrameworkSkillRepository.Add(dummyDynamicContent)).DoesNothing(); A.CallTo(() => fakeFrameworkSkillRepository.Publish(dummyDynamicContent, A <string> ._)).DoesNothing(); A.CallTo(() => fakeFrameworkSkillRepository.Commit()).DoesNothing(); A.CallTo(() => fakeFrameworkSkillRepository.CheckinTemp(dummyDynamicContent)).Returns(dummyDynamicContent); A.CallTo(() => fakeDynamicContentExtensions.SetFieldValue(dummyDynamicContent, A <string> ._, A <string> ._)).DoesNothing(); var frameworkSkillRepository = new FrameworkSkillRepository(fakeFrameworkSkillRepository, fakeDynamicContentExtensions, fakeFrameworkSkillConverter); // Act frameworkSkillRepository.UpsertFrameworkSkill(dummySkill); // Assert if (skillAvailable) { A.CallTo(() => fakeFrameworkSkillRepository.GetMaster(dummyDynamicContent)) .MustHaveHappenedOnceExactly(); A.CallTo(() => fakeFrameworkSkillRepository.GetTemp(dummyDynamicContent)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeFrameworkSkillRepository.CheckinTemp(dummyDynamicContent)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeFrameworkSkillRepository.Publish(dummyDynamicContent, A <string> ._)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeFrameworkSkillRepository.Commit()).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeDynamicContentExtensions.SetFieldValue(dummyDynamicContent, A <string> ._, A <string> ._)).MustHaveHappened(2, Times.Exactly); } else { A.CallTo(() => fakeFrameworkSkillRepository.Create()).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeFrameworkSkillRepository.Add(dummyDynamicContent)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeFrameworkSkillRepository.Commit()).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeDynamicContentExtensions.SetFieldValue(dummyDynamicContent, A <string> ._, A <string> ._)).MustHaveHappened(3, Times.Exactly); } A.CallTo(() => fakeFrameworkSkillRepository.Get(A <Expression <Func <DynamicContent, bool> > > .That.Matches(m => LinqExpressionsTestHelper.IsExpressionEqual(m, item => item.Visible && item.Status == ContentLifecycleStatus.Live && item.UrlName == dummySkill.SfUrlName)))).MustHaveHappened(); }
public void GetByUrlNameTest(bool isExistingJobCategory) { //Instantiate var jobProfileCategoryRepository = GetTestJobProfileCategoryRepository(); A.CallTo(() => fakeTaxonomyRepository.Get(A <Expression <Func <HierarchicalTaxon, bool> > > ._)).Returns(isExistingJobCategory ? dummyTaxon : null); A.CallTo(() => fakeTaxonomyRepository.GetMany(A <Expression <Func <HierarchicalTaxon, bool> > > ._)).Returns(new EnumerableQuery <HierarchicalTaxon>(new List <HierarchicalTaxon>())); string categoryUrlName = dummyTaxon.UrlName; var retunedCategory = jobProfileCategoryRepository.GetByUrlName(categoryUrlName); //this is the one we are going to try and find if (isExistingJobCategory) { //Asserts retunedCategory.Name.Should().Be(dummyTaxon.Name); retunedCategory.Title.Should().Be(dummyTaxon.Title); retunedCategory.Description.Should().Be(dummyTaxon.Description); A.CallTo(() => fakeTaxonomyRepository.GetMany(A <Expression <Func <HierarchicalTaxon, bool> > > ._)).MustHaveHappened(); } else { //Asserts retunedCategory.Should().BeNull(); A.CallTo(() => fakeTaxonomyRepository.GetMany(A <Expression <Func <HierarchicalTaxon, bool> > > ._)).MustNotHaveHappened(); } A.CallTo(() => fakeTaxonomyRepository.Get(A <Expression <Func <HierarchicalTaxon, bool> > > .That.Matches(m => LinqExpressionsTestHelper.IsExpressionEqual(m, c => c.UrlName == categoryUrlName && c.Taxonomy.Name == JobprofileTaxonomyName)))).MustHaveHappened(); }
public void GetByUrlNameTest() { var dummyJobProfile = A.Dummy <JobProfile>(); var urlName = "testURLName"; A.CallTo(() => fakeJobProfileConverter.ConvertFrom(A <DynamicContent> ._)).Returns(dummyJobProfile); var jobProfileRepository = new JobProfileRepository(fakeRepository, fakeJobProfileConverter, fakeDynamicContentExtensions, fakeSocSkillRepo, fakeWitConverter, fakeJobProfileSearchConverter); jobProfileRepository.GetByUrlName(urlName); //A.CallTo(() => fakeRepository.Get(A<Expression<Func<DynamicContent, bool>>>.That.Matches(m => ExpressionEqualityComparer.Instance.Equals()))).MustHaveHappened(); A.CallTo(() => fakeRepository.Get(A <Expression <Func <DynamicContent, bool> > > .That.Matches(m => LinqExpressionsTestHelper.IsExpressionEqual(m, item => item.UrlName == urlName && item.Status == ContentLifecycleStatus.Live && item.Visible == true)))).MustHaveHappened(); }
public void GetByUrlNameForSearchIndexTest(bool publishing) { var dummyJobProfile = A.Dummy <JobProfile>(); var urlName = "testURLName"; A.CallTo(() => fakeJobProfileConverter.ConvertFrom(A <DynamicContent> ._)).Returns(dummyJobProfile); var jobProfileRepository = new JobProfileRepository(fakeRepository, fakeJobProfileConverter, fakeDynamicContentExtensions, fakeSocSkillRepo, fakeWitConverter, fakeJobProfileSearchConverter); jobProfileRepository.GetByUrlNameForSearchIndex(urlName, publishing); A.CallTo(() => fakeRepository.Get(A <Expression <Func <DynamicContent, bool> > > .That.Matches(m => LinqExpressionsTestHelper.IsExpressionEqual(m, item => item.UrlName == urlName && item.Status == (publishing ? ContentLifecycleStatus.Master : ContentLifecycleStatus.Live))))).MustHaveHappened(); }
public void UpdateSocSkillMatricesTest(bool jobProfileAvailable) { // Arrange var urlname = "test-url"; var digitalSkill = "digiSkill"; var jobProfile = new JobProfileOverloadForWhatItTakes { UrlName = urlname, DigitalSkillsLevel = digitalSkill }; var dummyDynamicContent = A.Dummy <DynamicContent>(); var socSkill = new SocSkillMatrix { Title = "test soc" }; var socSkills = new List <SocSkillMatrix> { socSkill }; // Fakes Setup A.CallTo(() => fakeRepository.Get(A <Expression <Func <DynamicContent, bool> > > ._)) .Returns(jobProfileAvailable ? dummyDynamicContent : null); A.CallTo(() => fakeRepository.GetMaster(dummyDynamicContent)).Returns(dummyDynamicContent); A.CallTo(() => fakeRepository.Update(dummyDynamicContent, digitalSkill)).DoesNothing(); A.CallTo(() => fakeRepository.Commit()).DoesNothing(); A.CallTo(() => fakeDynamicContentExtensions.SetRelatedFieldValue(dummyDynamicContent, dummyDynamicContent, A <string> ._, A <float> ._)).DoesNothing(); A.CallTo(() => fakeDynamicContentExtensions.DeleteRelatedFieldValues(dummyDynamicContent, A <string> ._)).DoesNothing(); A.CallTo(() => fakeRepository.Get(A <Expression <Func <DynamicContent, bool> > > ._)) .Returns(jobProfileAvailable ? dummyDynamicContent : null); A.CallTo(() => fakeSocSkillRepo.Get(A <Expression <Func <DynamicContent, bool> > > ._)) .Returns(dummyDynamicContent); var jobProfileRepository = new JobProfileRepository(fakeRepository, fakeJobProfileConverter, fakeDynamicContentExtensions, fakeSocSkillRepo, fakeWitConverter, fakeJobProfileSearchConverter); // Act jobProfileRepository.UpdateSocSkillMatrices(jobProfile, socSkills); // Assert A.CallTo(() => fakeRepository.Get(A <Expression <Func <DynamicContent, bool> > > .That.Matches(m => LinqExpressionsTestHelper.IsExpressionEqual(m, item => item.UrlName == jobProfile.UrlName && item.Status == ContentLifecycleStatus.Live && item.Visible)))) .MustHaveHappened(); if (jobProfileAvailable) { A.CallTo(() => fakeRepository.GetMaster(dummyDynamicContent)).MustHaveHappened(); A.CallTo(() => fakeRepository.Update(dummyDynamicContent, A <string> ._)).MustHaveHappened(); A.CallTo(() => fakeRepository.Commit()).MustHaveHappened(); A.CallTo(() => fakeDynamicContentExtensions.SetRelatedFieldValue(A <DynamicContent> ._, A <DynamicContent> ._, "RelatedSkills", A <float> ._)).MustHaveHappened(); A.CallTo(() => fakeDynamicContentExtensions.DeleteRelatedFieldValues(A <DynamicContent> ._, A <string> ._)) .MustHaveHappened(); A.CallTo(() => fakeSocSkillRepo.Get(A <Expression <Func <DynamicContent, bool> > > .That.Matches(m => LinqExpressionsTestHelper.IsExpressionEqual(m, d => d.Status == ContentLifecycleStatus.Master && d.UrlName == socSkill.SfUrlName)))).MustHaveHappened(); } else { A.CallTo(() => fakeRepository.GetMaster(dummyDynamicContent)).MustNotHaveHappened(); A.CallTo(() => fakeRepository.Update(dummyDynamicContent, A <string> ._)).MustNotHaveHappened(); A.CallTo(() => fakeRepository.Commit()).MustNotHaveHappened(); A.CallTo(() => fakeRepository.CheckinTemp(dummyDynamicContent)).MustNotHaveHappened(); A.CallTo(() => fakeDynamicContentExtensions.SetRelatedFieldValue(A <DynamicContent> ._, A <DynamicContent> ._, A <string> ._, A <float> ._)).MustNotHaveHappened(); A.CallTo(() => fakeDynamicContentExtensions.DeleteRelatedFieldValues(A <DynamicContent> ._, A <string> ._)).MustNotHaveHappened(); A.CallTo(() => fakeSocSkillRepo.Get(A <Expression <Func <DynamicContent, bool> > > ._)) .MustNotHaveHappened(); } }
public void GetLiveJobProfilesTest(bool jobProfilesAvailable) { //Arrange var dummyJobProfile = A.Dummy <JobProfileOverloadForWhatItTakes>(); // Dummies and fakes A.CallTo(() => fakeWitConverter.ConvertFrom(A <DynamicContent> ._)).Returns(dummyJobProfile); A.CallTo(() => fakeRepository.GetMany(A <Expression <Func <DynamicContent, bool> > > ._)).Returns(jobProfilesAvailable ? new EnumerableQuery <DynamicContent>(new List <DynamicContent> { new DynamicContent() }) : Enumerable.Empty <DynamicContent>().AsQueryable()); var jobProfileRepository = new JobProfileRepository(fakeRepository, fakeJobProfileConverter, fakeDynamicContentExtensions, fakeSocSkillRepo, fakeWitConverter, fakeJobProfileSearchConverter); // Act jobProfileRepository.GetLiveJobProfiles(); // Assert if (jobProfilesAvailable) { A.CallTo(() => fakeWitConverter.ConvertFrom(A <DynamicContent> ._)).MustHaveHappened(); } else { A.CallTo(() => fakeWitConverter.ConvertFrom(A <DynamicContent> ._)).MustNotHaveHappened(); } A.CallTo(() => fakeRepository.GetMany(A <Expression <Func <DynamicContent, bool> > > .That.Matches(m => LinqExpressionsTestHelper.IsExpressionEqual(m, item => item.Status == ContentLifecycleStatus.Live && item.Visible)))).MustHaveHappened(); }