Exemplo n.º 1
0
        public JobProfileSection GetFirstMatchedJobProfileSection(JobProfileSectionFilter sectionFilter)
        {
            var subControls    = SitefinityPage.GetControlOnPageByCaption(sectionFilter.SubFilters);
            var widgetChildren = SitefinityPage.GetWidgets(subControls);

            return(widgetChildren
                   .Select(w => GetJobProfileSectionFromWidget(sectionFilter, w))
                   .FirstOrDefault(child => !string.IsNullOrEmpty(child.Title) && !string.IsNullOrEmpty(child.ContentField)));
        }
Exemplo n.º 2
0
        private static JobProfileSection GetJobProfileSectionFromWidget(JobProfileSectionFilter sectionFilter, KeyValuePair <string, MvcControllerProxy> widget)
        {
            var titleMember        = sectionFilter.TitleMember;
            var contentFieldMember = sectionFilter.ContentFieldMember;
            Dictionary <string, object> settings = widget.Value.Settings.Values;

            return(new JobProfileSection
            {
                Title = settings[titleMember]?.ToString(),
                ContentField = settings[contentFieldMember]?.ToString(),
            });
        }
Exemplo n.º 3
0
        public void GetJobProfileSectionsTest()
        {
            //Fakes and dummies
            var dummyJobProfileSectionFilters = new JobProfileSectionFilter[]
            {
                new JobProfileSectionFilter
                {
                    ContentFieldMember = "ContentField",
                    SectionCaption     = "Section",
                    TitleMember        = "Title"
                },
                new JobProfileSectionFilter
                {
                    ContentFieldMember = "AnotherContentField",
                    SectionCaption     = "AnotherSection",
                    TitleMember        = "AnotherTitle",
                    SubFilters         = new[] { "filter1", "filter2" }
                },
            };

            var expectedJobProfileSection = new JobProfileSection[]
            {
                new JobProfileSection
                {
                    ContentField = "ContentField",
                    Title        = "Title"
                },
                new JobProfileSection
                {
                    ContentField = "AnotherContentField",
                    Title        = "AnotherTitle"
                },
            };

            var dummyValues = new Dictionary <string, object>();

            dummyValues.Add("Title", "Title");
            dummyValues.Add("ContentField", "ContentField");
            dummyValues.Add("AnotherTitle", "AnotherTitle");
            dummyValues.Add("AnotherContentField", "AnotherContentField");

            var fakeSettings = A.Fake <DummySettings>();

            A.CallTo(() => fakeSettings.Values).Returns(dummyValues);

            var mvcControllerFake = A.Fake <MvcControllerProxy>();

            A.CallTo(() => mvcControllerFake.Settings).Returns(fakeSettings);

            var dummyWidgets = new KeyValuePair <string, MvcControllerProxy>[]
            {
                new KeyValuePair <string, MvcControllerProxy>("Section", mvcControllerFake),
                new KeyValuePair <string, MvcControllerProxy>("AnotherSection", mvcControllerFake),
            };

            Guid one = Guid.NewGuid(), two = Guid.NewGuid();
            var  fakeSitefinityPage = A.Fake <ISitefinityPage>(o => o.Strict());

            A.CallTo(() => fakeSitefinityPage.GetControlsInOrder(A <IEnumerable <string> > ._)).Returns(new Guid[] { one, two });
            A.CallTo(() => fakeSitefinityPage.GetControlOnPageByCaption(A <IEnumerable <string> > ._)).Returns(new Guid[] { one, two });
            A.CallTo(() => fakeSitefinityPage.GetWidgets(A <IEnumerable <Guid> > ._)).Returns(dummyWidgets);

            //Instantiate and act
            var jpContentService    = new JobProfilePageContentService(fakeSitefinityPage);
            var result              = jpContentService.GetJobProfileSections(dummyJobProfileSectionFilters);

            //Assert
            expectedJobProfileSection.Should().BeEquivalentTo(result, opt => opt.WithStrictOrdering());
            A.CallTo(() => fakeSettings.Values).MustHaveHappened();
            A.CallTo(() => mvcControllerFake.Settings).MustHaveHappened();
            A.CallTo(() => fakeSitefinityPage.GetControlsInOrder(A <IEnumerable <string> > ._)).MustHaveHappened();
            A.CallTo(() => fakeSitefinityPage.GetControlOnPageByCaption(A <IEnumerable <string> > ._)).MustHaveHappened();
            A.CallTo(() => fakeSitefinityPage.GetWidgets(A <IEnumerable <Guid> > ._)).MustHaveHappened();
        }