Example #1
0
        public async Task SitemapControllerSitemapReturnsSuccess()
        {
            // Arrange
            const int resultsCount    = 3;
            var       expectedResults = A.CollectionOfFake <ContentPageModel>(resultsCount);
            var       controller      = BuildSitemapController();

            expectedResults[0].IncludeInSitemap = true;
            expectedResults[0].CanonicalName    = "help";
            expectedResults[1].IncludeInSitemap = false;
            expectedResults[1].CanonicalName    = "not-in-sitemap";
            expectedResults[2].IncludeInSitemap = true;
            expectedResults[2].CanonicalName    = "in-sitemap";

            A.CallTo(() => FakeContentPageService.GetAllAsync(A <string> .Ignored)).Returns(expectedResults);

            // Act
            var result = await controller.Sitemap(PagesController.CategoryNameForHelp).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentPageService.GetAllAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();

            var contentResult = Assert.IsType <ContentResult>(result);

            contentResult.ContentType.Should().Be(MediaTypeNames.Application.Xml);

            controller.Dispose();
        }
        public async Task SitemapControllerSitemapReturnsSuccess()
        {
            // Arrange
            const int resultsCount    = 3;
            var       expectedResults = A.CollectionOfFake <JobCategory>(resultsCount);
            var       controller      = BuildSitemapController();

            expectedResults[0].CanonicalName = "default-article";
            expectedResults[1].CanonicalName = "yes-in-sitemap";
            expectedResults[2].CanonicalName = "in-sitemap";

            A.CallTo(() => FakeContentPageService.GetAllAsync()).Returns(expectedResults);

            // Act
            var result = await controller.Sitemap().ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentPageService.GetAllAsync()).MustHaveHappenedOnceExactly();

            var contentResult = Assert.IsType <ContentResult>(result);

            contentResult.ContentType.Should().Be(MediaTypeNames.Application.Xml);

            controller.Dispose();
        }
Example #3
0
        public async Task SitemapControllerViewReturnsSuccessWhenNoData()
        {
            // Arrange
            const int resultsCount    = 0;
            var       expectedResults = A.CollectionOfFake <ContentPageModel>(resultsCount);
            var       controller      = BuildSitemapController();

            A.CallTo(() => FakeContentPageService.GetAllAsync(A <string> .Ignored)).Returns(expectedResults);

            // Act
            var result = await controller.SitemapView().ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentPageService.GetAllAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();

            _ = Assert.IsType <NoContentResult>(result);

            controller.Dispose();
        }
Example #4
0
        public async Task SitemapControllerViewReturnsSuccess()
        {
            // Arrange
            const int resultsCount    = 5;
            var       expectedResults = A.CollectionOfFake <ContentPageModel>(resultsCount);
            var       controller      = BuildSitemapController();

            expectedResults[0].IncludeInSitemap         = true;
            expectedResults[0].PageLocation             = "/default-location";
            expectedResults[0].CanonicalName            = "default-article";
            expectedResults[0].IsDefaultForPageLocation = true;
            expectedResults[1].IncludeInSitemap         = false;
            expectedResults[1].PageLocation             = "/default-location";
            expectedResults[1].CanonicalName            = "not-in-sitemap";
            expectedResults[2].IncludeInSitemap         = true;
            expectedResults[2].PageLocation             = "/default-location";
            expectedResults[2].CanonicalName            = "in-sitemap";
            expectedResults[3].IncludeInSitemap         = true;
            expectedResults[3].PageLocation             = "/";
            expectedResults[3].CanonicalName            = "slash-location";
            expectedResults[4].IncludeInSitemap         = true;
            expectedResults[4].PageLocation             = string.Empty;
            expectedResults[4].CanonicalName            = "empty-location";

            A.CallTo(() => FakeContentPageService.GetAllAsync(A <string> .Ignored)).Returns(expectedResults);

            // Act
            var result = await controller.SitemapView().ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentPageService.GetAllAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();

            var contentResult = Assert.IsType <ContentResult>(result);

            contentResult.ContentType.Should().Be(MediaTypeNames.Application.Xml);

            controller.Dispose();
        }
Example #5
0
        public async void PagesControllerIndexReturnsNotAcceptable(string mediaTypeName)
        {
            // Arrange
            const int resultsCount = 0;
            IEnumerable <ContentPageModel> expectedResults = null;
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakeContentPageService.GetAllAsync()).Returns(expectedResults);
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <ContentPageModel> .Ignored)).Returns(A.Fake <IndexDocumentViewModel>());

            // Act
            var result = await controller.Index().ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentPageService.GetAllAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <ContentPageModel> .Ignored)).MustHaveHappened(resultsCount, Times.Exactly);

            var statusResult = Assert.IsType <StatusCodeResult>(result);

            A.Equals((int)HttpStatusCode.NotAcceptable, statusResult.StatusCode);

            controller.Dispose();
        }
Example #6
0
        public async void PagesControllerIndexJsonReturnsSuccessWhenNoData(string mediaTypeName)
        {
            // Arrange
            const int resultsCount = 0;
            IEnumerable <ContentPageModel> expectedResults = null;
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakeContentPageService.GetAllAsync()).Returns(expectedResults);
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <ContentPageModel> .Ignored)).Returns(A.Fake <IndexDocumentViewModel>());

            // Act
            var result = await controller.Index().ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentPageService.GetAllAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <ContentPageModel> .Ignored)).MustHaveHappened(resultsCount, Times.Exactly);

            var jsonResult = Assert.IsType <OkObjectResult>(result);
            var model      = Assert.IsAssignableFrom <IndexViewModel>(jsonResult.Value);

            A.Equals(null, model.Documents);

            controller.Dispose();
        }
Example #7
0
        public async void PagesControllerIndexHtmlReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            const int resultsCount    = 2;
            var       expectedResults = A.CollectionOfFake <ContentPageModel>(resultsCount);
            var       controller      = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakeContentPageService.GetAllAsync()).Returns(expectedResults);
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <ContentPageModel> .Ignored)).Returns(A.Fake <IndexDocumentViewModel>());

            // Act
            var result = await controller.Index().ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentPageService.GetAllAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <ContentPageModel> .Ignored)).MustHaveHappened(resultsCount, Times.Exactly);

            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <IndexViewModel>(viewResult.ViewData.Model);

            A.Equals(resultsCount, model.Documents.Count());

            controller.Dispose();
        }