public void UpdateSocOccupationalCodeTest(bool validSoc)
        {
            //Assign
            var fakeRepo            = GetTestJobProfileSocCodeRepository();
            var socCode             = new SocCode();
            var dummyDynamicContent = A.Dummy <DynamicContent>();

            // Setup Fakes
            if (validSoc)
            {
                A.CallTo(() => fakeRepository.Get(A <Expression <Func <DynamicContent, bool> > > ._)).Returns(dummyDynamicContent);
            }
            else
            {
                A.CallTo(() => fakeRepository.Get(A <Expression <Func <DynamicContent, bool> > > ._)).Returns(null);
            }

            A.CallTo(() => fakeRepository.GetMaster(dummyDynamicContent)).Returns(dummyDynamicContent);
            A.CallTo(() => fakeRepository.GetTemp(dummyDynamicContent)).Returns(dummyDynamicContent);
            A.CallTo(() => fakeRepository.CheckinTemp(dummyDynamicContent)).Returns(dummyDynamicContent);
            A.CallTo(() => fakeRepository.Publish(dummyDynamicContent, A <string> ._)).DoesNothing();
            A.CallTo(() => fakeRepository.Commit()).DoesNothing();
            A.CallTo(() => fakeRepository.CheckinTemp(dummyDynamicContent)).Returns(dummyDynamicContent);
            A.CallTo(() =>
                     fakeDynamicContentExtensions.SetFieldValue(dummyDynamicContent, nameof(socCode.ONetOccupationalCode), A <string> ._)).DoesNothing();

            //Act
            fakeRepo.UpdateSocOccupationalCode(socCode);

            //Assert
            if (validSoc)
            {
                A.CallTo(() => fakeRepository.GetMaster(dummyDynamicContent)).MustHaveHappened();
                A.CallTo(() => fakeRepository.GetTemp(dummyDynamicContent)).MustHaveHappened();
                A.CallTo(() => fakeRepository.CheckinTemp(dummyDynamicContent)).MustHaveHappened();
                A.CallTo(() => fakeRepository.Publish(dummyDynamicContent, A <string> ._)).MustHaveHappened();
                A.CallTo(() => fakeRepository.Commit()).MustHaveHappened();
                A.CallTo(() => fakeRepository.CheckinTemp(dummyDynamicContent)).MustHaveHappened();
                A.CallTo(() =>
                         fakeDynamicContentExtensions.SetFieldValue(dummyDynamicContent, nameof(socCode.ONetOccupationalCode), A <string> ._)).MustHaveHappened();
            }
            else
            {
                A.CallTo(() => fakeRepository.GetMaster(dummyDynamicContent)).MustNotHaveHappened();
                A.CallTo(() => fakeRepository.GetTemp(dummyDynamicContent)).MustNotHaveHappened();
                A.CallTo(() => fakeRepository.CheckinTemp(dummyDynamicContent)).MustNotHaveHappened();
                A.CallTo(() => fakeRepository.Publish(dummyDynamicContent, A <string> ._)).MustNotHaveHappened();
                A.CallTo(() => fakeRepository.Commit()).MustNotHaveHappened();
                A.CallTo(() => fakeRepository.CheckinTemp(dummyDynamicContent)).MustNotHaveHappened();
                A.CallTo(() =>
                         fakeDynamicContentExtensions.SetFieldValue(dummyDynamicContent, nameof(socCode.ONetOccupationalCode), A <string> ._)).MustNotHaveHappened();
            }

            A.CallTo(() => fakeRepository.Get(A <Expression <Func <DynamicContent, bool> > > .That.Matches(m => LinqExpressionsTestHelper.IsExpressionEqual(m, item => item.Visible && item.Status == ContentLifecycleStatus.Live && item.UrlName == socCode.UrlName)))).MustHaveHappened();
        }
        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 UpdateSocSkillMatrices(JobProfileOverloadForWhatItTakes jobProfile, IEnumerable <SocSkillMatrix> socSkillMatrices)
        {
            var jobprofile = repository.Get(item =>
                                            item.UrlName == jobProfile.UrlName && item.Status == ContentLifecycleStatus.Live && item.Visible);

            var skillMatrices = socSkillMatrices as IList <SocSkillMatrix> ?? socSkillMatrices.ToList();

            if (jobprofile != null && skillMatrices.Any())
            {
                var master = repository.GetMaster(jobprofile);

                dynamicContentExtensions.DeleteRelatedFieldValues(master, RelatedSkillField);

                float ordinal = 1;
                foreach (var socSkillMatrix in skillMatrices)
                {
                    var relatedSocSkillItem = socSkillRepository.Get(d => d.Status == ContentLifecycleStatus.Master && d.UrlName == socSkillMatrix.SfUrlName);

                    if (relatedSocSkillItem != null)
                    {
                        dynamicContentExtensions.SetRelatedFieldValue(master, relatedSocSkillItem, RelatedSkillField, socSkillMatrix.Rank.HasValue ? (float)socSkillMatrix.Rank.Value : ordinal);
                    }

                    ordinal++;
                }

                dynamicContentExtensions.SetFieldValue(master, nameof(JobProfile.DigitalSkillsLevel), jobProfile.DigitalSkillsLevel);

                repository.Commit();

                repository.Update(master, UpdateComment);

                repository.Commit();
            }

            return(new RepoActionResult {
                Success = true
            });
        }
        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 RepoActionResult UpdateSocOccupationalCode(SocCode socCode)
        {
            var socCodeItem = repository.Get(item => item.Visible && item.Status == ContentLifecycleStatus.Live && item.UrlName == socCode.UrlName);

            if (socCodeItem != null)
            {
                var master = repository.GetMaster(socCodeItem);

                var temp = repository.GetTemp(master);

                dynamicContentExtensions.SetFieldValue(temp, nameof(SocCode.ONetOccupationalCode), socCode.ONetOccupationalCode);

                var updatedMaster = repository.CheckinTemp(temp);

                repository.Publish(updatedMaster, UpdateComment);
                repository.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);
                }
            }
        }
        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();
            }
        }