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 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();
            }
        }