Example #1
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();
                }
            }
        }
Example #2
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 #3
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 #4
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);
        }