示例#1
0
        public async Task JobProfileControllerHeroJsonReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            const string article        = "an-article-name";
            var          expectedResult = A.Dummy <JobProfileModel>();
            var          controller     = BuildProfileController(mediaTypeName);

            expectedResult.CanonicalName = article;
            expectedResult.Segments      = new List <SegmentModel>();

            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map(A <JobProfileModel> .Ignored, A <HeroViewModel> .Ignored)).Returns(A.Fake <HeroViewModel>());

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

            // Assert
            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map(A <JobProfileModel> .Ignored, A <HeroViewModel> .Ignored)).MustHaveHappenedOnceExactly();

            var jsonResult = Assert.IsType <OkObjectResult>(result);

            Assert.IsAssignableFrom <List <SegmentModel> >(jsonResult.Value);

            controller.Dispose();
        }
        public async Task JobProfileControllerBodyJsonReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var expectedResult = A.Dummy <JobProfileModel>();
            var controller     = BuildProfileController(mediaTypeName);

            expectedResult.CanonicalName = FakeArticleName;
            expectedResult.Segments      = new List <SegmentModel>();

            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeRedirectionSecurityService.IsValidHost(A <Uri> .Ignored)).Returns(true);
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileModel> .Ignored)).Returns(DefaultBodyViewModel);

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

            // Assert
            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileModel> .Ignored)).MustHaveHappenedOnceExactly();

            var jsonResult = Assert.IsType <OkObjectResult>(result);

            Assert.IsAssignableFrom <List <SegmentModel> >(jsonResult.Value);

            controller.Dispose();
        }
示例#3
0
        public async Task JobProfileControllerProfileReturnsNotAcceptable(string mediaTypeName)
        {
            // Arrange
            var documentId     = Guid.NewGuid();
            var expectedResult = A.Fake <JobProfileModel>();
            var controller     = BuildProfileController(mediaTypeName);

            expectedResult.DocumentId = documentId;

            A.CallTo(() => FakeJobProfileService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map(A <JobProfileModel> .Ignored, A <BodyViewModel> .Ignored)).Returns(A.Fake <BodyViewModel>());

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

            // Assert
            A.CallTo(() => FakeJobProfileService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map(A <JobProfileModel> .Ignored, A <BodyViewModel> .Ignored)).MustHaveHappenedOnceExactly();

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

            Assert.Equal((int)HttpStatusCode.NotAcceptable, statusResult.StatusCode);

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

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

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

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

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

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

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

            controller.Dispose();
        }
        public async Task ProfileControllerDocumentReturnsWithCorrectlyMappedHeadAndBodyContent()
        {
            // Arrange
            const string article         = "an-article-name";
            const string headDescription = "HeadDescription";
            const string headTitle       = "HeadTitle";
            const string headKeywords    = "some keywords";
            var          jobProfileId    = Guid.NewGuid();

            var controller        = BuildControllerWithMapper();
            var jobProfileModel   = CreateJobProfileModel(headTitle, headDescription, headKeywords, jobProfileId);
            var expectedViewModel = CreateDocumentViewModel(headTitle, headDescription, headKeywords, jobProfileId);

            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).Returns(jobProfileModel);

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

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

            Assert.NotNull(resultModel.Head);
            Assert.NotNull(resultModel.Body);
            resultModel.Should().BeEquivalentTo(expectedViewModel);

            controller.Dispose();
        }
示例#6
0
        public async Task JobProfileControllerProfileJsonReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var documentId     = Guid.NewGuid();
            var expectedResult = A.Fake <JobProfileModel>();
            var controller     = BuildProfileController(mediaTypeName);

            expectedResult.DocumentId = documentId;

            A.CallTo(() => FakeJobProfileService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map(A <JobProfileModel> .Ignored, A <BodyViewModel> .Ignored)).Returns(A.Fake <BodyViewModel>());

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

            // Assert
            A.CallTo(() => FakeJobProfileService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map(A <JobProfileModel> .Ignored, A <BodyViewModel> .Ignored)).MustHaveHappenedOnceExactly();

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

            Assert.Equal(model.DocumentId, documentId);

            controller.Dispose();
        }
        public async Task BodyThrowsInvalidProfileExceptionWhenCriticalSegmentDoesNotExist()
        {
            // Arrange
            var controller    = BuildProfileController(MediaTypeNames.Application.Json);
            var bodyViewModel = new BodyViewModel
            {
                CanonicalName = FakeArticleName,
                Segments      = new List <SegmentModel>
                {
                    new SegmentModel
                    {
                        Segment = JobProfileSegment.WhatItTakes,
                        Markup  = new HtmlString("someContent"),
                    },
                    new SegmentModel
                    {
                        Segment = JobProfileSegment.HowToBecome,
                        Markup  = new HtmlString("someContent"),
                    },
                },
            };

            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).Returns(A.Fake <JobProfileModel>());
            A.CallTo(() => FakeJobProfileService.GetByAlternativeNameAsync(A <string> .Ignored)).Returns((JobProfileModel)null);
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileModel> .Ignored)).Returns(bodyViewModel);
            A.CallTo(() => FakeRedirectionSecurityService.IsValidHost(A <Uri> .Ignored)).Returns(true);

            // Act
            await Assert.ThrowsAsync <InvalidProfileException>(async() => await controller.Body(FakeArticleName).ConfigureAwait(false)).ConfigureAwait(false);

            controller.Dispose();
        }
        public async Task JobProfileControllerBodyReturnsNotAcceptable(string mediaTypeName)
        {
            // Arrange
            var expectedResult = A.Fake <JobProfileModel>();
            var controller     = BuildProfileController(mediaTypeName);

            expectedResult.CanonicalName = FakeArticleName;

            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeRedirectionSecurityService.IsValidHost(A <Uri> .Ignored)).Returns(true);
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileModel> .Ignored)).Returns(DefaultBodyViewModel);

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

            // Assert
            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileModel> .Ignored)).MustHaveHappenedOnceExactly();

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

            Assert.Equal((int)HttpStatusCode.NotAcceptable, statusResult.StatusCode);

            controller.Dispose();
        }
        public async Task JobProfileControllerBodyJsonAndHtmlReturnsRedirectWhenAlternateArticleExistsWithValidHost(string mediaTypeName)
        {
            // Arrange
            var expectedAlternativeResult = A.Fake <JobProfileModel>();
            var controller = BuildProfileController(mediaTypeName, host: "localhosttest", whitelist: new string[] { "6357b4c93a1bfd4901871836a03602586222c6a9ae05a48d67dda806d2c2eca6" });

            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).Returns((JobProfileModel)null);
            A.CallTo(() => FakeJobProfileService.GetByAlternativeNameAsync(A <string> .Ignored))
            .Returns(expectedAlternativeResult);
            A.CallTo(() => FakeRedirectionSecurityService.IsValidHost(A <Uri> .Ignored)).Returns(true);
            // Act
            var result = await controller.Body(FakeArticleName).ConfigureAwait(false);

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

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

            statusResult.Url.Should().NotBeNullOrWhiteSpace();
            Assert.True(statusResult.Permanent);

            controller.Dispose();
        }
示例#10
0
        public async Task JobProfileControllerHeroReturnsNotAcceptable(string mediaTypeName)
        {
            // Arrange
            const string article        = "an-article-name";
            var          expectedResult = A.Fake <JobProfileModel>();
            var          controller     = BuildProfileController(mediaTypeName);

            expectedResult.CanonicalName = article;

            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map(A <JobProfileModel> .Ignored, A <HeroViewModel> .Ignored)).Returns(A.Fake <HeroViewModel>());

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

            // Assert
            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map(A <JobProfileModel> .Ignored, A <HeroViewModel> .Ignored)).MustHaveHappenedOnceExactly();

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

            Assert.Equal((int)HttpStatusCode.NotAcceptable, statusResult.StatusCode);

            controller.Dispose();
        }
        public async Task JobProfileControllerBodyHtmlAndJsonReturnsBadRequestWhenHostIsInvalid(string mediaTypeName)
        {
            // Arrange
            var controller = BuildProfileController(mediaTypeName, host: "notlocalhost");

            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).Returns((JobProfileModel)null);

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

            // Assert
            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeJobProfileService.GetByAlternativeNameAsync(A <string> .Ignored)).MustNotHaveHappened();
            Assert.IsType <BadRequestObjectResult>(result);

            controller.Dispose();
        }
示例#12
0
        public async Task HealthControllerHealthReturnsServiceUnavailableWhenException()
        {
            // Arrange
            var controller = BuildHealthController(MediaTypeNames.Application.Json);

            A.CallTo(() => FakeJobProfileService.PingAsync()).Throws <Exception>();

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

            // Assert
            A.CallTo(() => FakeJobProfileService.PingAsync()).MustHaveHappenedOnceExactly();
            var statusResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)HttpStatusCode.ServiceUnavailable, statusResult.StatusCode);

            controller.Dispose();
        }
        public async Task ProfileControllerPostRefreshReturnsSuccessForUpdate(string mediaTypeName)
        {
            // Arrange
            var refreshJobProfileSegmentModel = A.Fake <RefreshJobProfileSegment>();
            var controller = BuildProfileController(mediaTypeName);

            A.CallTo(() => FakeJobProfileService.RefreshSegmentsAsync(A <RefreshJobProfileSegment> .Ignored)).Returns(HttpStatusCode.OK);

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

            // Assert
            A.CallTo(() => FakeJobProfileService.RefreshSegmentsAsync(A <RefreshJobProfileSegment> .Ignored)).MustHaveHappenedOnceExactly();
            var statusCodeResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)HttpStatusCode.OK, statusCodeResult.StatusCode);

            controller.Dispose();
        }
        public async Task ProfileControllerDocumentReturnsNoContentWhenNoData(string mediaTypeName)
        {
            // Arrange
            const string article    = "an-article-name";
            var          controller = BuildProfileController(mediaTypeName);

            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).Returns((JobProfileModel)null);

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

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

            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            Assert.Equal((int)HttpStatusCode.NotFound, statusResult.StatusCode);

            controller.Dispose();
        }
示例#15
0
        public async Task ProfileControllerCreateOrUpdateReturnsSuccessForCreate(string mediaTypeName)
        {
            // Arrange
            var jobProfileModel = A.Fake <JobProfileModel>();
            var controller      = BuildProfileController(mediaTypeName);

            A.CallTo(() => FakeJobProfileService.Create(A <JobProfileModel> .Ignored)).Returns(HttpStatusCode.Created);

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

            // Assert
            A.CallTo(() => FakeJobProfileService.Create(A <JobProfileModel> .Ignored)).MustHaveHappenedOnceExactly();

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

            Assert.Equal((int)HttpStatusCode.Created, statusCodeResult.StatusCode);

            controller.Dispose();
        }
示例#16
0
        public async Task ProfileControllerPatchReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var documentId = Guid.NewGuid();
            var jobProfileMetaDataPatchModel = new JobProfileMetadata();
            var controller = BuildProfileController(mediaTypeName);

            A.CallTo(() => FakeJobProfileService.Update(A <JobProfileMetadata> .Ignored)).Returns(HttpStatusCode.OK);

            // Act
            var result = await controller.Patch(jobProfileMetaDataPatchModel, documentId).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeJobProfileService.Update(jobProfileMetaDataPatchModel)).MustHaveHappenedOnceExactly();

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

            Assert.Equal((int)HttpStatusCode.OK, statusCodeResult.StatusCode);

            controller.Dispose();
        }
        public async Task ProfileControllerDeleteReturnsNotFound(string mediaTypeName)
        {
            // Arrange
            var             documentId     = Guid.NewGuid();
            JobProfileModel expectedResult = null;
            var             controller     = BuildProfileController(mediaTypeName);

            A.CallTo(() => FakeJobProfileService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);

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

            // Assert
            A.CallTo(() => FakeJobProfileService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();

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

            Assert.Equal((int)HttpStatusCode.NotFound, statusResult.StatusCode);

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

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

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

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

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

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

            controller.Dispose();
        }
        public async Task JobProfileControllerBodyHtmlAndJsonReturnsNoContentWhenNoAlternateArticle(
            string mediaTypeName)
        {
            // Arrange
            var controller = BuildProfileController(mediaTypeName);

            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).Returns((JobProfileModel)null);
            A.CallTo(() => FakeJobProfileService.GetByAlternativeNameAsync(A <string> .Ignored))
            .Returns((JobProfileModel)null);
            A.CallTo(() => FakeRedirectionSecurityService.IsValidHost(A <Uri> .Ignored)).Returns(true);

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

            // Assert
            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeJobProfileService.GetByAlternativeNameAsync(A <string> .Ignored))
            .MustHaveHappenedOnceExactly();
            Assert.IsType <NotFoundResult>(result);

            controller.Dispose();
        }
        public async Task ProfileControllerDocumentHtmlReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            const string article        = "an-article-name";
            var          expectedResult = A.Fake <JobProfileModel>();
            var          controller     = BuildProfileController(mediaTypeName);

            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <JobProfileModel> .Ignored)).Returns(A.Fake <DocumentViewModel>());

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

            // Assert
            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <JobProfileModel> .Ignored)).MustHaveHappenedOnceExactly();

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

            Assert.IsAssignableFrom <DocumentViewModel>(viewResult.ViewData.Model);

            controller.Dispose();
        }
示例#21
0
        public async Task JobProfileControllerHeadJsonReturnsSuccessWhenNoData(string mediaTypeName)
        {
            // Arrange
            const string article = "an-article-name";

            Data.Models.JobProfileModel expectedResult = null;
            var controller = BuildProfileController(mediaTypeName);

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

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

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

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

            model.CanonicalUrl.Should().BeNull();

            controller.Dispose();
        }
        public async Task ProfileControllerIndexReturnsNotAcceptable(string mediaTypeName)
        {
            // Arrange
            const int resultsCount = 0;
            IEnumerable <Data.Models.JobProfileModel> expectedResults = null;
            var controller = BuildProfileController(mediaTypeName);

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

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

            // Assert
            A.CallTo(() => FakeJobProfileService.GetAllAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <Data.Models.JobProfileModel> .Ignored)).MustHaveHappened(resultsCount, Times.Exactly);

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

            Assert.Equal((int)HttpStatusCode.NotAcceptable, statusResult.StatusCode);

            controller.Dispose();
        }
示例#23
0
        public async Task HealthControllerHealthReturnsSuccessWhenhealthy()
        {
            // Arrange
            const bool expectedResult = true;
            var        controller     = BuildHealthController(MediaTypeNames.Application.Json);

            A.CallTo(() => FakeJobProfileService.PingAsync()).Returns(expectedResult);

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

            // Assert
            A.CallTo(() => FakeJobProfileService.PingAsync()).MustHaveHappenedOnceExactly();

            var jsonResult = Assert.IsType <OkObjectResult>(result);
            var models     = Assert.IsAssignableFrom <List <HealthItemViewModel> >(jsonResult.Value);

            models.Count.Should().BeGreaterThan(0);
            models.First().Service.Should().NotBeNullOrWhiteSpace();
            models.First().Message.Should().NotBeNullOrWhiteSpace();

            controller.Dispose();
        }
        public async Task BodyReturnsOfflineMarkupWhenNonCriticalSegmentsHaveNoMarkup(List <SegmentModel> segments)
        {
            // Arrange
            var controller    = BuildProfileController(MediaTypeNames.Application.Json);
            var bodyViewModel = new BodyViewModel
            {
                CanonicalName = FakeArticleName,
                Segments      = segments,
            };

            var offlineSegmentModel = new OfflineSegmentModel
            {
                OfflineMarkup = new HtmlString("<h1>Some offline markup for this non-critical segment</h1>"),
            };

            A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).Returns(A.Fake <JobProfileModel>());
            A.CallTo(() => FakeJobProfileService.GetByAlternativeNameAsync(A <string> .Ignored)).Returns((JobProfileModel)null);
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileModel> .Ignored)).Returns(bodyViewModel);
            A.CallTo(() => FakeSegmentService.GetOfflineSegment(A <JobProfileSegment> .Ignored)).Returns(offlineSegmentModel);
            A.CallTo(() => FakeRedirectionSecurityService.IsValidHost(A <Uri> .Ignored)).Returns(true);

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

            // Assert
            var okObjectResult     = result as OkObjectResult;
            var resultViewModel    = Assert.IsAssignableFrom <BodyViewModel>(okObjectResult?.Value);
            var nonCriticalSegment = segments.FirstOrDefault(s => s.Segment != JobProfileSegment.Overview && s.Segment != JobProfileSegment.HowToBecome && s.Segment != JobProfileSegment.WhatItTakes);
            var resultSegmentModel = resultViewModel.Segments.FirstOrDefault(s => s.Segment == nonCriticalSegment?.Segment);

            Assert.Equal((int)HttpStatusCode.OK, okObjectResult.StatusCode);
            A.CallTo(() => FakeSegmentService.GetOfflineSegment(A <JobProfileSegment> .Ignored)).MustHaveHappenedOnceExactly();
            Assert.Equal(offlineSegmentModel.OfflineMarkup.Value, resultSegmentModel?.Markup.Value);

            controller.Dispose();
        }
        public async Task ProfileControllerIndexHtmlReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            const int resultsCount    = 2;
            var       expectedResults = A.CollectionOfFake <JobProfileModel>(resultsCount);
            var       controller      = BuildProfileController(mediaTypeName);

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

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

            // Assert
            A.CallTo(() => FakeJobProfileService.GetAllAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <Data.Models.JobProfileModel> .Ignored)).MustHaveHappened(resultsCount, Times.Exactly);

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

            Assert.Equal(resultsCount, model.Documents.Count());

            controller.Dispose();
        }
        public async Task ProfileControllerIndexJsonReturnsSuccessWhenNoData(string mediaTypeName)
        {
            // Arrange
            const int resultsCount = 0;
            IEnumerable <Data.Models.JobProfileModel> expectedResults = null;
            var controller = BuildProfileController(mediaTypeName);

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

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

            // Assert
            A.CallTo(() => FakeJobProfileService.GetAllAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <Data.Models.JobProfileModel> .Ignored)).MustHaveHappened(resultsCount, Times.Exactly);

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

            Assert.Null(model.Documents);

            controller.Dispose();
        }