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 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 RepoActionResult UpsertFrameworkSkill(FrameworkSkill onetSkill) { //CodeReview: Worth abstrating this out to a get by url var repoSkill = frameworkSkillRepository.Get(item => item.Visible && item.Status == ContentLifecycleStatus.Live && item.UrlName == onetSkill.SfUrlName); if (repoSkill != null) { var master = frameworkSkillRepository.GetMaster(repoSkill); var temp = frameworkSkillRepository.GetTemp(master); dynamicContentExtensions.SetFieldValue(temp, nameof(FrameworkSkill.Description), onetSkill.Description); dynamicContentExtensions.SetFieldValue(temp, nameof(FrameworkSkill.ONetElementId), onetSkill.ONetElementId); var updatedMaster = frameworkSkillRepository.CheckinTemp(temp); frameworkSkillRepository.Publish(updatedMaster, UpdateComment); frameworkSkillRepository.Commit(); } else { var newRepoSkill = frameworkSkillRepository.Create(); newRepoSkill.UrlName = onetSkill.SfUrlName; dynamicContentExtensions.SetFieldValue(newRepoSkill, nameof(FrameworkSkill.Title), onetSkill.Title); dynamicContentExtensions.SetFieldValue(newRepoSkill, nameof(FrameworkSkill.Description), onetSkill.Description); dynamicContentExtensions.SetFieldValue(newRepoSkill, nameof(FrameworkSkill.ONetElementId), onetSkill.ONetElementId); frameworkSkillRepository.Add(newRepoSkill); frameworkSkillRepository.Commit(); } return(new RepoActionResult { Success = true }); }
public void UpsertSocSkillMatrix(SocSkillMatrix socSkillMatrix) { var repoSocMatrix = socMatrixRepository.Get(item => item.Visible && item.Status == ContentLifecycleStatus.Live && item.UrlName == socSkillMatrix.SfUrlName); if (repoSocMatrix != null) { var master = socMatrixRepository.GetMaster(repoSocMatrix); if (!string.IsNullOrWhiteSpace(socSkillMatrix.ONetElementId)) { dynamicContentExtensions.DeleteRelatedFieldValues(master, RelatedSkillField); var relatedSkillItem = frameworkSkillRepository.Get(d => d.Status == ContentLifecycleStatus.Master && d.GetValue <string>(nameof(FrameworkSkill.ONetElementId)) == socSkillMatrix.ONetElementId); if (relatedSkillItem != null) { dynamicContentExtensions.SetRelatedFieldValue(master, relatedSkillItem, RelatedSkillField, 1); } } if (!string.IsNullOrWhiteSpace(socSkillMatrix.SocCode)) { dynamicContentExtensions.DeleteRelatedFieldValues(master, RelatedSocField); var relatedSocItem = socCodeRepository.Get(d => d.Status == ContentLifecycleStatus.Master && d.GetValue <string>(nameof(SocCode.SOCCode)) == socSkillMatrix.SocCode); if (relatedSocItem != null) { dynamicContentExtensions.SetRelatedFieldValue(master, relatedSocItem, RelatedSocField, 1); } } // Save related on live version socMatrixRepository.Commit(); var temp = socMatrixRepository.GetTemp(master); dynamicContentExtensions.SetFieldValue(temp, nameof(SocSkillMatrix.Title), socSkillMatrix.Title); dynamicContentExtensions.SetFieldValue(temp, nameof(SocSkillMatrix.Contextualised), socSkillMatrix.Contextualised); dynamicContentExtensions.SetFieldValue(temp, nameof(SocSkillMatrix.ONetAttributeType), socSkillMatrix.ONetAttributeType); dynamicContentExtensions.SetFieldValue(temp, nameof(SocSkillMatrix.ONetRank), socSkillMatrix.ONetRank); dynamicContentExtensions.SetFieldValue(temp, nameof(SocSkillMatrix.Rank), socSkillMatrix.Rank); var updatedMaster = socMatrixRepository.CheckinTemp(temp); socMatrixRepository.Publish(updatedMaster, UpdateComment); socMatrixRepository.Commit(); } else { var newSocMatrix = socMatrixRepository.Create(); dynamicContentExtensions.SetFieldValue(newSocMatrix, UrlNameField, (Lstring)socSkillMatrix.SfUrlName); socMatrixRepository.Add(newSocMatrix); socMatrixRepository.Commit(); var newlyCreated = socMatrixRepository.Get(item => item.Visible && item.Status == ContentLifecycleStatus.Live && item.UrlName == socSkillMatrix.SfUrlName); if (newlyCreated != null) { UpsertSocSkillMatrix(socSkillMatrix); } } }