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
            });
        }
Exemple #3
0
        public void GetTest(IReadOnlyCollection <DFC_GDSTranlations> setupDbSetData, IReadOnlyCollection <content_model_reference> contentModelSetupData, IReadOnlyCollection <DFC_GDSCombinations> combinationSetupData, FrameworkSkill mappedWhatitTakesData, string onetElementId)
        {
            //InProgress as have to yield single object against collection
            //Arrange
            var fakeDbContext        = A.Fake <OnetSkillsFramework>();
            var fakeTranslationDbSet = A.Fake <DbSet <DFC_GDSTranlations> >(c => c
                                                                            .Implements(typeof(IQueryable <DFC_GDSTranlations>))
                                                                            .Implements(typeof(IDbAsyncEnumerable <DFC_GDSTranlations>))).SetupData(setupDbSetData.ToList());
            var fakeContentDbSet = A.Fake <DbSet <content_model_reference> >(c => c
                                                                             .Implements(typeof(IQueryable <content_model_reference>))
                                                                             .Implements(typeof(IDbAsyncEnumerable <content_model_reference>)))
                                   .SetupData(contentModelSetupData.ToList());
            var fakeCombinationDbSet = A.Fake <DbSet <DFC_GDSCombinations> >(c => c
                                                                             .Implements(typeof(IQueryable <DFC_GDSCombinations>))
                                                                             .Implements(typeof(IDbAsyncEnumerable <DFC_GDSCombinations>)))
                                       .SetupData(combinationSetupData.ToList());

            //Act
            A.CallTo(() => fakeDbContext.DFC_GDSTranlations).Returns(fakeTranslationDbSet);
            A.CallTo(() => fakeDbContext.content_model_reference).Returns(fakeContentDbSet);
            A.CallTo(() => fakeDbContext.DFC_GDSCombinations).Returns(fakeCombinationDbSet);
            var repo = new TranslationQueryRepository(fakeDbContext);

            //Assert
            var result = repo.Get(x => x.ONetElementId == onetElementId);

            result.Should().NotBeNull();
            if (mappedWhatitTakesData == null || result == null)
            {
                Xunit.Assert.True(false, "The mapped data should not be null ");
            }
            else
            {
                result.Should().BeEquivalentTo(mappedWhatitTakesData);
                result.ONetElementId.Should().Be(onetElementId);
            }
        }