Example #1
0
        public void IndexTest(bool validJobProfile, bool inContentAuthoringSite, bool isContentPreviewMode)
        {
            //Assign
            SetupCallsAndFakes(validJobProfile, inContentAuthoringSite, isContentPreviewMode);

            //Act
            var jobprofilehtbController = new JobProfileHowToBecomeController(webAppContextFake, jobProfileRepositoryFake, applicationLoggerFake, sitefinityPageFake, mapper);
            var indexMethodCall         = jobprofilehtbController.WithCallTo(c => c.Index());

            //Assert
            if (inContentAuthoringSite)
            {
                indexMethodCall
                .ShouldRenderDefaultView()
                .WithModel <JobProfileHowToBecomeViewModel>(vm =>
                {
                    AssertViewModelProperties(vm, jobprofilehtbController, validJobProfile);
                })
                .AndNoModelErrors();

                if (!isContentPreviewMode)
                {
                    A.CallTo(() => jobProfileRepositoryFake.GetByUrlName(A <string> ._)).MustHaveHappened();
                }
                else
                {
                    A.CallTo(() => jobProfileRepositoryFake.GetByUrlNameForPreview(A <string> ._)).MustHaveHappened();
                }
            }
            else
            {
                indexMethodCall.ShouldRedirectTo("\\");
            }
        }
Example #2
0
        public void IndexUrlNameTest(string urlName, bool validJobProfile, bool isContentPreviewMode)
        {
            //Set up comman call
            SetUpDependeciesAndCall(validJobProfile, isContentPreviewMode);

            //Instantiate & Act
            using (var jobprofileController = new JobProfileDetailsController(
                       webAppContextFake, repositoryFake, loggerFake, sitefinityPage, mapperCfg.CreateMapper(), asyncHelper, searchQueryService))
            {
                //Act
                var indexWithUrlNameMethodCall = jobprofileController.WithCallTo(c => c.Index(urlName));

                if (validJobProfile)
                {
                    indexWithUrlNameMethodCall
                    .ShouldRenderDefaultView()
                    .WithModel <JobProfileDetailsViewModel>(vm =>
                    {
                        vm.SalaryText.Should().BeEquivalentTo(jobprofileController.SalaryText);
                        vm.HoursText.Should().BeEquivalentTo(jobprofileController.HoursText);
                        vm.MaxAndMinHoursAreBlankText.Should().BeEquivalentTo(jobprofileController
                                                                              .MaxAndMinHoursAreBlankText);
                        vm.HoursTimePeriodText.Should().BeEquivalentTo(jobprofileController.HoursTimePeriodText);
                        vm.AlternativeTitle.Should().BeEquivalentTo(dummyJobProfile.AlternativeTitle);
                        vm.SalaryRange.Should().BeEquivalentTo(dummyJobProfile.SalaryRange);
                        vm.Overview.Should().BeEquivalentTo(dummyJobProfile.Overview);
                        vm.Title.Should().BeEquivalentTo(dummyJobProfile.Title);
                        vm.MaximumHours.Should().BeEquivalentTo(dummyJobProfile.MaximumHours.ToString());
                        vm.MinimumHours.Should().BeEquivalentTo(dummyJobProfile.MinimumHours.ToString());
                        vm.WorkingHoursDetails.Should().BeEquivalentTo(dummyJobProfile.WorkingHoursDetails);
                        vm.WorkingPatternDetails.Should().BeEquivalentTo(dummyJobProfile.WorkingPatternDetails);
                        vm.WorkingPattern.Should().BeEquivalentTo(dummyJobProfile.WorkingPattern);
                        vm.SalaryStarter.Should().Be(starterSalary);
                        vm.SalaryExperienced.Should().Be(experiencedSalary);
                        vm.SalaryContextLink.Should().Be(jobprofileController.SalaryContextLink);
                        vm.SalaryContextText.Should().Be(jobprofileController.SalaryContextText);
                    })
                    .AndNoModelErrors();
                }
                else
                {
                    indexWithUrlNameMethodCall.ShouldGiveHttpStatus(404);
                }

                if (!isContentPreviewMode)
                {
                    A.CallTo(() => repositoryFake.GetByUrlName(A <string> ._)).MustHaveHappened();
                }
                else
                {
                    A.CallTo(() => repositoryFake.GetByUrlNameForPreview(A <string> ._)).MustHaveHappened();
                }
            }
        }
        /// <summary>
        /// Gets the job profile details view.
        /// </summary>
        /// <param name="urlName">The urlname.</param>
        /// <returns>ActionResult</returns>
        private ActionResult GetBreadcrumbView(string urlName)
        {
            var breadCrumbLink = new BreadcrumbLink();
            var model          = new DfcBreadcrumbViewModel
            {
                HomepageText    = HomepageText,
                HomepageLink    = HomepageLink,
                BreadcrumbLinks = new List <BreadcrumbLink>
                {
                    breadCrumbLink
                }
            };

            // We get the page node we are on
            var currentPageNode = sitefinityCurrentContext.GetCurrentDfcPageNode();

            if (currentPageNode != null)
            {
                var nodeUrl = currentPageNode.Url.OriginalString;
                switch (nodeUrl.ToUpperInvariant())
                {
                case var jobCategoriesPage when !string.IsNullOrEmpty(urlName) && jobCategoriesPage.Contains(JobCategoriesPathSegment):
                {
                    var category = categoryRepo.GetByUrlName(urlName);
                    breadCrumbLink.Text = (category == null) ? currentPageNode.Title : category.Title;
                    break;
                }

                case var jobProfilePage when !string.IsNullOrEmpty(urlName) && jobProfilePage.Contains(JobProfilesPathSegment):
                {
                    var jobProfile = jobProfileRepository.GetByUrlName(urlName);
                    breadCrumbLink.Text = (jobProfile == null) ? currentPageNode.Title : jobProfile.Title;
                    break;
                }

                case var alertsPage when alertsPage.Contains(AlertsPathSegment):
                {
                    breadCrumbLink.Text = AlertsPageText;
                    break;
                }

                default:
                {
                    model.BreadcrumbLinks = sitefinityCurrentContext.BreadcrumbToParent();

                    //the current page should not be linked
                    model.BreadcrumbLinks.FirstOrDefault().Link = null;
                    model.BreadcrumbLinks = model.BreadcrumbLinks.Reverse().ToList();
                    break;
                }
                }
            }

            return(View(model));
        }
Example #4
0
        public void IndexCustomPagesTest(SegmentType segmentType, string repoTitle, string expectedLinkTitle)
        {
            //Setup
            var dummyDfcPageSiteNode = A.Dummy <DfcPageSiteNode>();

            dummyDfcPageSiteNode.Title = expectedLinkTitle;
            A.CallTo(() => sitefinityCurrentContext.GetCurrentDfcPageNode()).Returns(dummyDfcPageSiteNode);

            //Instantiate
            var dfcBreadcrumbController = new DfcBreadcrumbController(repositoryCategoryFake, repositoryJobProfileFake, sitefinityCurrentContext, loggerFake);

            switch (segmentType)
            {
            case SegmentType.Category:
                dummyDfcPageSiteNode.Url = new Uri($"/abcd/{dfcBreadcrumbController.JobCategoriesPathSegment}", UriKind.RelativeOrAbsolute);
                A.CallTo(() => repositoryCategoryFake.GetByUrlName(A <string> ._)).Returns(repoTitle == null ? null : new JobProfileCategory()
                {
                    Title = repoTitle
                });
                break;

            case SegmentType.JobProfile:
                dummyDfcPageSiteNode.Url = new Uri($"/abcd/{dfcBreadcrumbController.JobProfilesPathSegment}", UriKind.RelativeOrAbsolute);
                A.CallTo(() => repositoryJobProfileFake.GetByUrlName(A <string> ._)).Returns(repoTitle == null ? null : new JobProfile()
                {
                    Title = repoTitle
                });
                break;

            case SegmentType.Alert:
                dummyDfcPageSiteNode.Url = new Uri($"/abcd/{dfcBreadcrumbController.AlertsPathSegment}", UriKind.RelativeOrAbsolute);
                dfcBreadcrumbController.AlertsPageText = expectedLinkTitle;
                break;
            }

            // Act
            var indexMethodCall = dfcBreadcrumbController.WithCallTo(c => c.Index("dummyURLName"));

            //Assert
            indexMethodCall
            .ShouldRenderDefaultView()
            .WithModel <DfcBreadcrumbViewModel>(vm =>
            {
                vm.HomepageText.Should().BeEquivalentTo(dfcBreadcrumbController.HomepageText);
                vm.HomepageLink.Should().BeEquivalentTo(dfcBreadcrumbController.HomepageLink);
                vm.BreadcrumbLinks.FirstOrDefault().Text.Should().BeEquivalentTo(expectedLinkTitle);
                vm.BreadcrumbLinks.FirstOrDefault().Link.Should().BeEquivalentTo(null);
            })
            .AndNoModelErrors();
        }
Example #5
0
        private void SetupCallsAndFakes(bool isValidJobProfile, bool inContentAuthoringSite = false, bool isContentPreviewMode = false)
        {
            webAppContextFake        = A.Fake <IWebAppContext>(ops => ops.Strict());
            jobProfileRepositoryFake = A.Fake <IJobProfileRepository>(ops => ops.Strict());
            applicationLoggerFake    = A.Fake <IApplicationLogger>();
            sitefinityPageFake       = A.Fake <ISitefinityPage>(ops => ops.Strict());
            mapper = new MapperConfiguration(c => c.AddProfile <JobProfilesAutoMapperProfile>()).CreateMapper();

            A.CallTo(() => webAppContextFake.IsContentAuthoringSite).Returns(inContentAuthoringSite);
            A.CallTo(() => webAppContextFake.IsContentPreviewMode).Returns(isContentPreviewMode);
            A.CallTo(() => webAppContextFake.SetMetaDescription(A <string> ._)).DoesNothing();
            A.CallTo(() => jobProfileRepositoryFake.GetByUrlName(A <string> ._))
            .Returns(GetDummyJobProfile(isValidJobProfile));
            A.CallTo(() => jobProfileRepositoryFake.GetByUrlNameForPreview(A <string> ._))
            .Returns(GetDummyJobProfile(isValidJobProfile));
            A.CallTo(() => sitefinityPageFake.GetDefaultJobProfileToUse(A <string> ._))
            .Returns(nameof(JobProfile.UrlName));
        }
Example #6
0
        private void SetUpDependeciesAndCall(bool validJobProfile, bool isContentPreviewMode)
        {
            ////Set up comman call
            dummyJobProfile = validJobProfile
                ? new JobProfile
            {
                AlternativeTitle = nameof(JobProfile.AlternativeTitle),
                SalaryRange      = nameof(JobProfile.SalaryRange),
                Overview         = nameof(JobProfile.Overview),
                Title            = nameof(JobProfile.Title),
                MaximumHours     = 40,
                MinimumHours     = 10
            }
                : null;

            // Set up calls
            A.CallTo(() => repositoryFake.GetByUrlName(A <string> ._)).Returns(dummyJobProfile);
            A.CallTo(() => repositoryFake.GetByUrlNameForPreview(A <string> ._)).Returns(dummyJobProfile);
            A.CallTo(() => webAppContextFake.IsContentAuthoringSite).Returns(isContentPreviewMode);
            A.CallTo(() => sitefinityPage.GetDefaultJobProfileToUse(A <string> ._))
            .ReturnsLazily((string defaultProfile) => defaultProfile);
        }
Example #7
0
        public ActionResult Index(string urlName)
        {
            if (webAppContext.IsCategoryPage && !string.IsNullOrEmpty(urlName))
            {
                var category = categoryRepo.GetByUrlName(urlName);
                if (category != null)
                {
                    this.ViewBag.Title = $"{category.Title} {PageTitleSeparator} {PageTitleSuffix}";
                }
            }
            else if (webAppContext.IsJobProfilePage && !string.IsNullOrEmpty(urlName))
            {
                var jobProfile = jobProfileRepository.GetByUrlName(urlName);
                if (jobProfile != null)
                {
                    this.ViewBag.Title = $"{jobProfile.Title} {PageTitleSeparator} {PageTitleSuffix}";
                }
            }

            //Need to return a blank view so that we can check the view bag in tests.
            return(View(new SetContentRelatedPageTitleModel {
                DisplayView = webAppContext.IsContentAuthoringAndNotPreviewMode
            }));
        }