Exemplo n.º 1
0
        public void IndexMetaDescriptionTest(string titleAndUrlName, bool validJobCategory)
        {
            //Setup the fakes and dummies
            var repositoryFake    = A.Fake <IJobProfileCategoryRepository>(ops => ops.Strict());
            var webAppContextFake = A.Fake <IWebAppContext>(ops => ops.Strict());
            var loggerFake        = A.Fake <IApplicationLogger>();

            var dummyJobProfileCategory = A.Dummy <JobProfileCategory>();

            dummyJobProfileCategory.Title = titleAndUrlName;
            var dummyRelatedJobProfiles = A.CollectionOfDummy <JobProfile>(5);

            // Set up calls
            A.CallTo(() => repositoryFake.GetByUrlName(A <string> ._)).Returns(validJobCategory ? dummyJobProfileCategory : null);
            A.CallTo(() => repositoryFake.GetRelatedJobProfiles(A <string> ._)).Returns(dummyRelatedJobProfiles);
            A.CallTo(() => webAppContextFake.SetMetaDescription(A <string> ._)).DoesNothing();

            //Instantiate & Act
            var jobprofileController = new JobProfilesByCategoryController(repositoryFake, webAppContextFake, loggerFake);

            //Act
            jobprofileController.MetaDescription = "Test {JobCategory}-{JOBCATEGORY}-{jobcategory}";
            var indexWithUrlNameMethodCall = jobprofileController.WithCallTo(c => c.Index(titleAndUrlName));

            //Assert
            if (validJobCategory)
            {
                A.CallTo(() => webAppContextFake.SetMetaDescription(A <string> .That.Contains($"Test {titleAndUrlName}-{titleAndUrlName}-{titleAndUrlName}"))).MustHaveHappened();
            }
            else
            {
                indexWithUrlNameMethodCall.ShouldGiveHttpStatus(404);
            }
        }
Exemplo n.º 2
0
        public void IndexUrlNameTest(string urlName, bool validJobCategory)
        {
            //Setup the fakes and dummies
            var repositoryFake    = A.Fake <IJobProfileCategoryRepository>(ops => ops.Strict());
            var webAppContextFake = A.Fake <IWebAppContext>(ops => ops.Strict());
            var loggerFake        = A.Fake <IApplicationLogger>();

            var dummyJobProfileCategory = A.Dummy <JobProfileCategory>();
            var dummyRelatedJobProfiles = A.CollectionOfDummy <JobProfile>(5);

            // Set up calls
            A.CallTo(() => repositoryFake.GetByUrlName(A <string> ._)).Returns(validJobCategory ? dummyJobProfileCategory : null);

            A.CallTo(() => repositoryFake.GetRelatedJobProfiles(A <string> ._)).Returns(dummyRelatedJobProfiles);

            A.CallTo(() => webAppContextFake.SetMetaDescription(A <string> ._)).DoesNothing();

            //Instantiate & Act
            var jobprofileController = new JobProfilesByCategoryController(repositoryFake, webAppContextFake, loggerFake);

            //Act
            var indexWithUrlNameMethodCall = jobprofileController.WithCallTo(c => c.Index(urlName));

            //Assert
            A.CallTo(() => repositoryFake.GetByUrlName(A <string> ._)).MustHaveHappened();

            if (validJobCategory)
            {
                indexWithUrlNameMethodCall
                .ShouldRenderDefaultView()
                .WithModel <JobProfileByCategoryViewModel>(vm =>
                {
                    vm.Title.Should().BeEquivalentTo(dummyJobProfileCategory.Title);
                    vm.Description.Should().BeEquivalentTo(dummyJobProfileCategory.Description);
                    vm.JobProfiles.Should().BeEquivalentTo(dummyRelatedJobProfiles);
                })
                .AndNoModelErrors();

                A.CallTo(() => repositoryFake.GetRelatedJobProfiles(A <string> ._)).MustHaveHappened();
            }
            else
            {
                indexWithUrlNameMethodCall.ShouldGiveHttpStatus(404);
            }
        }