public async Task PagesControllerBreadcrumbHtmlReturnsSuccessForDefaultArticleName(string mediaTypeName)
        {
            // Arrange
            const string category       = "a-category";
            const string article        = DefaultHelpArticleName;
            var          expectedResult = A.Fake <ContentPageModel>();
            var          controller     = BuildPagesController(mediaTypeName);

            expectedResult.CanonicalName = article;

            A.CallTo(() => FakeContentPageService.GetByNameAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);

            // Act
            var result = await controller.Breadcrumb(category, article).ConfigureAwait(false);

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

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

            model.Paths.Count.Should().BeGreaterThan(0);

            controller.Dispose();
        }
예제 #2
0
        public async void PagesControllerBodyReturnsNotAcceptable(string mediaTypeName)
        {
            // Arrange
            const string article        = "an-article-name";
            var          expectedResult = new ContentPageModel()
            {
                Content = "<h1>A document ({0})</h1>"
            };
            var controller = BuildPagesController(mediaTypeName);

            expectedResult.CanonicalName = article;

            A.CallTo(() => FakeContentPageService.GetByNameAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map(A <ContentPageModel> .Ignored, A <BodyViewModel> .Ignored)).Returns(A.Fake <BodyViewModel>());

            // Act
            var result = await controller.Body(PagesController.CategoryNameForAlert, article).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentPageService.GetByNameAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map(A <ContentPageModel> .Ignored, A <BodyViewModel> .Ignored)).MustHaveHappenedOnceExactly();

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

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

            controller.Dispose();
        }
예제 #3
0
        public async void PagesControllerBodyWithNullArticleHtmlReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            const string article        = null;
            var          expectedResult = new ContentPageModel()
            {
                Content = "<h1>A document ({0})</h1>"
            };
            var controller = BuildPagesController(mediaTypeName);

            expectedResult.CanonicalName = article;

            A.CallTo(() => FakeContentPageService.GetByNameAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map(A <ContentPageModel> .Ignored, A <BodyViewModel> .Ignored)).Returns(A.Fake <BodyViewModel>());

            // Act
            var result = await controller.Body(PagesController.CategoryNameForHelp, article).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentPageService.GetByNameAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map(A <ContentPageModel> .Ignored, A <BodyViewModel> .Ignored)).MustHaveHappenedOnceExactly();

            var viewResult = Assert.IsType <ViewResult>(result);

            _ = Assert.IsAssignableFrom <BodyViewModel>(viewResult.ViewData.Model);

            controller.Dispose();
        }
예제 #4
0
        public async void PagesControllerBodyHtmlReturnsRedirectWhenAlternateArticleExistsForDefaultArticleName(string mediaTypeName)
        {
            // Arrange
            const string     article        = null;
            ContentPageModel expectedResult = null;
            var expectedAlternativeResult   = A.Fake <ContentPageModel>();
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakeContentPageService.GetByNameAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeContentPageService.GetByAlternativeNameAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedAlternativeResult);

            // Act
            var result = await controller.Body(PagesController.CategoryNameForAlert, article).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentPageService.GetByNameAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeContentPageService.GetByAlternativeNameAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();

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

            statusResult.Url.Should().NotBeNullOrWhiteSpace();
            A.Equals(true, statusResult.Permanent);

            controller.Dispose();
        }
        public async Task PagesControllerHeadWithNullArticleHtmlReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            const string category = "a-category";
            const string article = null;
            var expectedResult = A.Fake<ContentPageModel>();
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakeContentPageService.GetByNameAsync(A<string>.Ignored, A<string>.Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map(A<ContentPageModel>.Ignored, A<HeadViewModel>.Ignored)).Returns(A.Fake<HeadViewModel>());

            // Act
            var result = await controller.Head(category, article).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentPageService.GetByNameAsync(A<string>.Ignored, A<string>.Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map(A<ContentPageModel>.Ignored, A<HeadViewModel>.Ignored)).MustHaveHappenedOnceExactly();

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

            model.CanonicalUrl.Should().NotBeNullOrWhiteSpace();

            controller.Dispose();
        }
        public async Task PagesControllerDocumentJsonReturnsNoContentWhenNoData(string mediaTypeName)
        {
            // Arrange
            const string     category       = "a-category";
            const string     article        = "an-article-name";
            ContentPageModel expectedResult = null;
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakeContentPageService.GetByNameAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);

            // Act
            var result = await controller.Document(category, article).ConfigureAwait(false);

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

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

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

            controller.Dispose();
        }
        public async Task PagesControllerBreadcrumbJsonReturnsSuccessWhenNoData(string mediaTypeName)
        {
            // Arrange
            const string     category       = "a-category";
            const string     article        = "an-article-name";
            ContentPageModel expectedResult = null;
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakeContentPageService.GetByNameAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);

            // Act
            var result = await controller.Breadcrumb(category, article).ConfigureAwait(false);

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

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

            model.Paths.Count.Should().BeGreaterThan(0);

            controller.Dispose();
        }
        public async Task PagesControllerDocumentJsonReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            const string category       = "a-category";
            const string article        = "an-article-name";
            var          expectedResult = A.Fake <ContentPageModel>();
            var          controller     = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakeContentPageService.GetByNameAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <ContentPageModel> .Ignored)).Returns(A.Fake <DocumentViewModel>());

            // Act
            var result = await controller.Document(category, article).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentPageService.GetByNameAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <ContentPageModel> .Ignored)).MustHaveHappenedOnceExactly();

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

            controller.Dispose();
        }
        public async Task PagesControllerBreadcrumbReturnsNotAcceptable(string mediaTypeName)
        {
            // Arrange
            const string category       = "a-category";
            const string article        = "an-article-name";
            var          expectedResult = A.Fake <ContentPageModel>();
            var          controller     = BuildPagesController(mediaTypeName);

            expectedResult.CanonicalName = article;

            A.CallTo(() => FakeContentPageService.GetByNameAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);

            // Act
            var result = await controller.Breadcrumb(category, article).ConfigureAwait(false);

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

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

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

            controller.Dispose();
        }
예제 #10
0
        public async void PagesControllerBodyJsonReturnsNotFoundWhenNoAlternateHelpArticle(string mediaTypeName)
        {
            // Arrange
            const string     article                   = "an-article-name";
            ContentPageModel expectedResult            = null;
            ContentPageModel expectedAlternativeResult = null;
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakeContentPageService.GetByNameAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeContentPageService.GetByAlternativeNameAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedAlternativeResult);

            // Act
            var result = await controller.Body(PagesController.CategoryNameForHelp, article).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentPageService.GetByNameAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeContentPageService.GetByAlternativeNameAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();

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

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

            controller.Dispose();
        }