public void AddNewSOCMappingsTest()
        {
            //Setup
            var fakeDbContext = A.Fake <OnetSkillsFramework>();
            var fakeDbSet     = A.Fake <DbSet <DFC_SocMappings> >(c => c
                                                                  .Implements(typeof(IQueryable <DFC_SocMappings>))
                                                                  .Implements(typeof(IDbAsyncEnumerable <DFC_SocMappings>)));
            var fakeMapper = A.Fake <IMapper>();

            A.CallTo(() => fakeDbContext.DFC_SocMappings).Returns(fakeDbSet);
            A.CallTo(() => fakeDbContext.SaveChanges()).Returns(1);

            var repo    = new SocMappingRepository(fakeDbContext, fakeMapper);
            var testSOC = new SocCode()
            {
                SOCCode = "TestSOC1", ONetOccupationalCode = "TestONetCode1", Description = "TestDescription"
            };
            var testSOCList = new List <SocCode>
            {
                testSOC
            };

            //Call
            repo.AddNewSOCMappings(testSOCList);

            //Asserts
            A.CallTo(() => fakeDbContext.SaveChanges()).MustHaveHappened(Repeated.Exactly.Once);
        }
        public void GetTest(IReadOnlyCollection <DFC_SocMappings> setupSocData, SocCode responseData, string socCode)
        {
            var fakeDbContext = A.Fake <OnetSkillsFramework>();
            var actualMapper  = new MapperConfiguration(c => c.AddProfile <SkillsFrameworkMapper>()).CreateMapper();
            var fakeDbSet     = A.Fake <DbSet <DFC_SocMappings> >(c => c
                                                                  .Implements(typeof(IQueryable <DFC_SocMappings>))
                                                                  .Implements(typeof(IDbAsyncEnumerable <DFC_SocMappings>)))
                                .SetupData(setupSocData.ToList());


            A.CallTo(() => fakeDbContext.DFC_SocMappings).Returns(fakeDbSet);


            var repo = new SocMappingRepository(fakeDbContext, actualMapper);

            var result = repo.Get(x => x.SOCCode == socCode);

            A.CallTo(() => fakeDbContext.DFC_SocMappings).MustHaveHappened(Repeated.Exactly.Once);
            if (responseData == null || result == null)
            {
                Assert.True(false, "Response Data should not be null");
            }
            else
            {
                result.Should().BeEquivalentTo(responseData);
            }
        }
        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 IList <SocSkillMatrix> CreateSocSkillsMatrixRecords(SocCode soc)
        {
            if (soc == null)
            {
                throw new ArgumentNullException(nameof(soc));
            }

            var occupationSkills = skillsFrameworkService.GetRelatedSkillMapping(soc.ONetOccupationalCode);

            //Create SOC skill matrix records
            reportAuditRepository.CreateAudit(ActionDetailsKey, $"Found {occupationSkills.Count()} Skills for {soc.ONetOccupationalCode} SOC {soc.SOCCode} from SkillFramework Service");
            //Save it as an error as well
            if (occupationSkills.Count() == 0)
            {
                reportAuditRepository.CreateAudit(ErrorDetailsKey, $"Found {occupationSkills.Count()} Skills for {soc.ONetOccupationalCode} SOC {soc.SOCCode} from SkillFramework Service");
            }

            var rankGenerated      = 1;
            var socSkillMatrixData = new List <SocSkillMatrix>();

            foreach (var occupationSkill in occupationSkills)
            {
                var socSkillToAdd = new SocSkillMatrix
                {
                    Title             = $"{soc.SOCCode}-{occupationSkill.Name}",
                    SocCode           = soc.SOCCode,
                    Skill             = occupationSkill.Name,
                    ONetRank          = occupationSkill.Score,
                    Rank              = rankGenerated,
                    ONetElementId     = occupationSkill.Id,
                    ONetAttributeType = occupationSkill.Category.ToString()
                };
                socSkillMatrixRepository.UpsertSocSkillMatrix(socSkillToAdd);
                socSkillMatrixData.Add(socSkillToAdd);
                reportAuditRepository.CreateAudit(ActionDetailsKey, $"Added/Updated Soc Skill Matrix profile {socSkillToAdd.Title}  into socskill matrix repo");
                rankGenerated++;
            }

            return(socSkillMatrixData);
        }
        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 AddNewSOCMappingsTest()
        {
            var skillsFrameworkService = new SkillsFrameworkService(fakeApplicationLogger,
                                                                    fakeDigitalSkill,
                                                                    fakeSkillsRepository,
                                                                    fakeSkillsBusinessRuleEngine,
                                                                    fakeSocMappingRepository
                                                                    );

            A.CallTo(() => fakeSocMappingRepository.AddNewSOCMappings(A <List <SocCode> > ._)).DoesNothing();

            var testSOC = new SocCode()
            {
                SOCCode = "TestSOC1", ONetOccupationalCode = "TestONetCode1", Description = "TestDescription"
            };
            var testSOCList = new List <SocCode>
            {
                testSOC
            };

            skillsFrameworkService.AddNewSOCMappings(testSOCList);

            A.CallTo(() => fakeSocMappingRepository.AddNewSOCMappings(A <List <SocCode> > ._)).MustHaveHappenedOnceExactly();
        }
        public void ImportForSingleSoc(string jobProfileSoc)
        {
            var lockedJobProfiles = new List <JobProfileOverloadForWhatItTakes>();

            reportAuditRepository.CreateAudit(ActionDetailsKey, $"Updating Job profiles for SOC - {jobProfileSoc}");
            var soc = jobProfileSocCodeRepository.GetBySocCode(jobProfileSoc);

            if (soc == null)
            {
                reportAuditRepository.CreateAudit(ErrorDetailsKey, $"SOC - {jobProfileSoc} NOT found in Sitefinity!");
                soc = new SocCode {
                    SOCCode = jobProfileSoc
                };
            }
            else
            {
                skillsFrameworkService.SetSocStatusSelectedForUpdate(soc);
                var jobProfilesForSoc = jobProfileSocCodeRepository.GetLiveJobProfilesBySocCode(soc.SOCCode).ToList();
                reportAuditRepository.CreateAudit(ActionDetailsKey,
                                                  $"Found {jobProfilesForSoc.Count} job profiles for SOC {soc.SOCCode}");

                lockedJobProfiles = jobProfilesForSoc.Where(x => x.Locked).ToList();
                foreach (var lockedJobProfile in lockedJobProfiles)
                {
                    reportAuditRepository.CreateAudit(SummaryDetailsKey, $"{lockedJobProfile.UrlName} could not be updated as it is locked or already in a Draft status with Soc code {jobProfileSoc}");
                }

                var safeJobProfiles = jobProfilesForSoc.Where(x => !x.Locked).ToList();
                //We have safe job linked to the SOC
                if (safeJobProfiles.Any())
                {
                    var socSkillMatrixData = CreateSocSkillsMatrixRecords(soc);
                    var digitalSkillLevel  = skillsFrameworkService.GetDigitalSkillLevel(soc.ONetOccupationalCode);
                    reportAuditRepository.CreateAudit(ActionDetailsKey,
                                                      $"Got {digitalSkillLevel} for Occupational Code : {soc.ONetOccupationalCode} SOC {soc.SOCCode} from SkillFramework Service");
                    var digitSkillValue = Convert.ToInt32(digitalSkillLevel).ToString();

                    //DO all profiles that exist for this code
                    foreach (var profile in safeJobProfiles)
                    {
                        if (socSkillMatrixData.Any())
                        {
                            profile.DigitalSkillsLevel = digitSkillValue;
                            jobProfileRepository.UpdateSocSkillMatrices(profile, socSkillMatrixData);
                            reportAuditRepository.CreateAudit(ActionDetailsKey,
                                                              $"Linked Job Profile {profile.UrlName} with the following socskilmatrices {string.Join(", ", socSkillMatrixData.ToList().Select(sk => sk.Title))}");
                        }
                    }

                    reportAuditRepository.CreateAudit(ActionDetailsKey, $"Updated job profiles SOC {jobProfileSoc}");
                }
                else
                {
                    reportAuditRepository.CreateAudit(ErrorDetailsKey,
                                                      $"Found {safeJobProfiles.Count} unlocked job profiles for SOC {soc.SOCCode}");
                }
            }
            if (!lockedJobProfiles.Any())
            {
                skillsFrameworkService.SetSocStatusCompleted(soc);
                reportAuditRepository.CreateAudit(ActionDetailsKey, $"Set status to Completed for SOC {soc.SOCCode}");
            }
            reportAuditRepository.CreateAudit(ActionDetailsKey, "-----------------------------------------------------------------------------------------------------------------------------");
            reportAuditRepository.CreateAudit(ActionDetailsKey, " ");
        }