public async Task SegmentControllerBodyReturnsNotAcceptable(string mediaTypeName)
        {
            // Arrange
            var documentId         = Guid.NewGuid();
            var expectedResult     = A.Fake <CurrentOpportunitiesSegmentModel>();
            var dummyBodyViewModel = A.Dummy <BodyViewModel>();

            dummyBodyViewModel.Data         = A.Dummy <BodyDataViewModel>();
            dummyBodyViewModel.Data.Courses = A.Dummy <BodyCoursesViewModel>();

            var controller = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <CurrentOpportunitiesSegmentModel> .Ignored)).Returns(dummyBodyViewModel);

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

            // Assert
            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <CurrentOpportunitiesSegmentModel> .Ignored)).MustHaveHappenedOnceExactly();

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

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

            controller.Dispose();
        }
Beispiel #2
0
        public async Task WebhookContentProcessorProcessContentAsyncForUpdateReturnsNoContent()
        {
            // Arrange
            const HttpStatusCode expectedResponse          = HttpStatusCode.NoContent;
            var expectedValidApiContentModel               = BuildValidPagesApiContentModel();
            ContentPageModel?expectedValidContentPageModel = default;
            var url     = new Uri("https://somewhere.com");
            var service = BuildWebhookContentProcessor();

            A.CallTo(() => FakeCmsApiService.GetItemAsync <CmsApiDataModel>(A <Uri> .Ignored)).Returns(expectedValidApiContentModel);
            A.CallTo(() => FakeMapper.Map <ContentPageModel?>(A <CmsApiDataModel> .Ignored)).Returns(expectedValidContentPageModel);

            // Act
            var result = await service.ProcessContentAsync(url, ContentIdForCreate).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeCmsApiService.GetItemAsync <CmsApiDataModel>(A <Uri> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <ContentPageModel>(A <CmsApiDataModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeContentPageService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeEventMessageService.UpdateAsync(A <ContentPageModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeEventMessageService.CreateAsync(A <ContentPageModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeEventGridService.CompareAndSendEventAsync(A <ContentPageModel> .Ignored, A <ContentPageModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeEventMessageService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened();

            Assert.Equal(expectedResponse, result);
        }
Beispiel #3
0
        public async Task ReturnsSuccessForJsonMediaType(string mediaTypeName)
        {
            // Arrange
            var expectedResult = new JobProfileTasksSegmentModel();
            var controller     = BuildSegmentController(mediaTypeName);
            var apiModel       = GetDummyApiModel();

            expectedResult.CanonicalName = ArticleName;

            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <WhatYouWillDoApiModel>(A <JobProfileTasksDataSegmentModel> .Ignored)).Returns(apiModel);

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <WhatYouWillDoApiModel>(A <JobProfileTasksDataSegmentModel> .Ignored)).MustHaveHappenedOnceExactly();

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

            Assert.IsAssignableFrom <WhatYouWillDoApiModel>(jsonResult.Value);

            controller.Dispose();
        }
        public async Task PagesControllerDocumentHtmlReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var expectedResult = A.Fake <JobGroupModel>();
            var controller     = BuildPagesController(mediaTypeName);
            var expectedModel  = new DocumentViewModel
            {
                Id           = Guid.NewGuid(),
                Soc          = 3231,
                Title        = "A title",
                PartitionKey = "partition-key",
            };

            A.CallTo(() => FakeJobGroupDocumentService.GetAsync(A <Expression <Func <JobGroupModel, bool> > > .Ignored, A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <JobGroupModel> .Ignored)).Returns(expectedModel);

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

            // Assert
            A.CallTo(() => FakeJobGroupDocumentService.GetAsync(A <Expression <Func <JobGroupModel, bool> > > .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <JobGroupModel> .Ignored)).MustHaveHappenedOnceExactly();

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

            _ = Assert.IsAssignableFrom <DocumentViewModel>(viewResult.ViewData.Model);
            var model = viewResult.ViewData.Model as DocumentViewModel;

            Assert.Equal(expectedModel, model);

            controller.Dispose();
        }
        public async Task WebhooksServiceProcessContentAsyncForUpdateReturnsSuccess()
        {
            // Arrange
            const HttpStatusCode expectedResponse    = HttpStatusCode.OK;
            var expectedValidContentItemApiDataModel = BuildValidContentItemApiDataModel();
            var expectedValidContentItemModel        = BuildValidContentItemModel();
            var url     = new Uri("https://somewhere.com");
            var service = BuildWebhooksService();

            A.CallTo(() => FakeCmsApiService.GetItemAsync <SharedContentItemApiDataModel>(A <Uri> .Ignored)).Returns(expectedValidContentItemApiDataModel);
            A.CallTo(() => FakeMapper.Map <SharedContentItemModel>(A <SharedContentItemApiDataModel> .Ignored)).Returns(expectedValidContentItemModel);
            A.CallTo(() => FakeSharedContentItemDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).Returns(expectedValidContentItemModel);
            A.CallTo(() => FakeSharedContentItemDocumentService.UpsertAsync(A <SharedContentItemModel> .Ignored)).Returns(HttpStatusCode.OK);

            // Act
            var result = await service.ProcessContentAsync(url).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeCmsApiService.GetItemAsync <SharedContentItemApiDataModel>(A <Uri> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <SharedContentItemModel>(A <SharedContentItemApiDataModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeSharedContentItemDocumentService.UpsertAsync(A <SharedContentItemModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeSharedContentItemDocumentService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened();

            Assert.Equal(expectedResponse, result);
        }
Beispiel #6
0
        public async Task PagesControllerHeadReturnsNotAcceptable(string mediaTypeName)
        {
            // Arrange
            var pageRequestModel = new PageRequestModel
            {
                Location1 = "a-location-name",
                Location2 = "an-article-name",
            };
            var expectedResult = new ContentPageModel()
            {
                PageLocation = "/" + pageRequestModel.Location1, CanonicalName = pageRequestModel.Location2
            };
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(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(pageRequestModel).ConfigureAwait(false);

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

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

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

            controller.Dispose();
        }
Beispiel #7
0
        public async Task PagesControllerHeadHtmlWithNullArticleReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var pageRequestModel = new PageRequestModel
            {
                Location1 = "a-location-name",
                Location2 = "an-article-name",
            };
            ContentPageModel?expectedResult = null;
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(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(pageRequestModel).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();

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

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

            controller.Dispose();
        }
Beispiel #8
0
        public async Task PagesControllerDocumentReturnsRedirectWhenRedirectLocationExists(string mediaTypeName)
        {
            // Arrange
            var pageRequestModel = new PageRequestModel
            {
                Location1 = "a-location-name",
                Location2 = "an-article-name",
            };
            ContentPageModel?expectedResult = null;
            var expectedRedirectResult      = A.Fake <ContentPageModel>();
            var controller = BuildPagesController(mediaTypeName);

            expectedRedirectResult.PageLocation  = pageRequestModel.Location1;
            expectedRedirectResult.CanonicalName = pageRequestModel.Location2;

            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakePagesControlerHelpers.GetRedirectedContentPageAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedRedirectResult);

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

            // Assert
            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakePagesControlerHelpers.GetRedirectedContentPageAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <ContentPageModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeMapper.Map <BreadcrumbViewModel>(A <ContentPageModel> .Ignored)).MustNotHaveHappened();

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

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

            controller.Dispose();
        }
Beispiel #9
0
        public async Task PagesControllerDocumentReturnsNoContentWhenNoData(string mediaTypeName)
        {
            // Arrange
            var pageRequestModel = new PageRequestModel
            {
                Location1 = "a-location-name",
                Location2 = "an-article-name",
            };
            ContentPageModel?expectedResult = null;
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakePagesControlerHelpers.GetRedirectedContentPageAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);

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

            // Assert
            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakePagesControlerHelpers.GetRedirectedContentPageAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <ContentPageModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeMapper.Map <BreadcrumbViewModel>(A <ContentPageModel> .Ignored)).MustNotHaveHappened();

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

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

            controller.Dispose();
        }
Beispiel #10
0
        public async Task ReturnsSuccessForHtmlMediaType(string mediaTypeName)
        {
            // Arrange
            var expectedResult    = A.Fake <JobProfileOverviewSegmentModel>();
            var fakeBodyViewModel = A.Fake <BodyViewModel>();
            var controller        = BuildSegmentController(mediaTypeName);

            expectedResult.Data    = A.Fake <JobProfileOverviewSegmentDataModel>();
            fakeBodyViewModel.Data = A.Fake <BodyDataViewModel>();

            A.CallTo(() => FakeJobProfileOverviewSegmentService.GetByNameAsync(A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileOverviewSegmentModel> .Ignored)).Returns(fakeBodyViewModel);

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

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

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

            Assert.Null(resultViewModel.Data.Breadcrumb);

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

            expectedResult.CanonicalName = article;

            A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map(A <JobCategory> .Ignored, A <HtmlHeadViewModel> .Ignored)).Returns(A.Fake <HtmlHeadViewModel>());

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

            // Assert
            A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map(A <JobCategory> .Ignored, A <HtmlHeadViewModel> .Ignored)).MustHaveHappenedOnceExactly();

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

            model.CanonicalUrl.Should().NotBeNull();

            controller.Dispose();
        }
Beispiel #12
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();
        }
Beispiel #13
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();
        }
Beispiel #14
0
        public async Task SegmentControllerGetBodyJsonReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var howToBecomeSegmentModel = new HowToBecomeSegmentModel {
                CanonicalName = "SomeCanonicalName"
            };
            var fakeHowToBecomeApiModel = A.Dummy <HowToBecomeApiModel>();

            var controller = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeHowToBecomeSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(howToBecomeSegmentModel);
            A.CallTo(() => FakeMapper.Map <HowToBecomeApiModel>(A <HowToBecomeSegmentDataModel> .Ignored)).Returns(fakeHowToBecomeApiModel);

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

            // Assert
            A.CallTo(() => FakeHowToBecomeSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <HowToBecomeApiModel>(A <HowToBecomeSegmentDataModel> .Ignored)).MustHaveHappenedOnceExactly();

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

            Assert.IsAssignableFrom <HowToBecomeApiModel>(jsonResult.Value);

            controller.Dispose();
        }
        public async Task PagesControllerBodyReturnsNotAcceptable(string mediaTypeName)
        {
            // Arrange
            var dummyJobGroupModel = A.Dummy <JobGroupModel>();
            var controller         = BuildPagesController(mediaTypeName);
            var socRequestModel    = new SocRequestModel {
                Soc = 3231, FromJobProfileCanonicalName = "a-job-profile",
            };
            var dummyBodyViewModel = A.Dummy <BodyViewModel>();

            A.CallTo(() => FakeJobGroupDocumentService.GetAsync(A <Expression <Func <JobGroupModel, bool> > > .Ignored, A <string> .Ignored)).Returns(dummyJobGroupModel);
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobGroupModel> .Ignored)).Returns(dummyBodyViewModel);

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

            // Assert
            A.CallTo(() => FakeJobGroupDocumentService.GetAsync(A <Expression <Func <JobGroupModel, bool> > > .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobGroupModel> .Ignored)).MustHaveHappenedOnceExactly();

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

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

            controller.Dispose();
        }
Beispiel #16
0
        public async Task EnterYourDetailsControllerViewPostReturnsSuccessForMissingRouting()
        {
            // Arrange
            const bool         expectedSendEmailResult    = true;
            RoutingDetailModel?expectedRoutingDetailModel = null;
            string             expectedRedirectUrl        = $"/{PagesController.LocalPath}/{HomeController.ThankyouForContactingUsCanonicalName}";
            var viewModel  = ValidModelBuilders.BuildValidEnterYourDetailsBodyViewModel();
            var controller = BuildEnterYourDetailsController(MediaTypeNames.Text.Html);

            A.CallTo(() => FakeRoutingService.GetEmailToSendTo(A <string> .Ignored, A <Category> .Ignored)).Returns(A.Dummy <string>());
            A.CallTo(() => FakeMapper.Map <ContactUsEmailRequestModel>(A <EnterYourDetailsBodyViewModel> .Ignored)).Returns(A.Fake <ContactUsEmailRequestModel>());
            A.CallTo(() => FakeNotifyEmailService.SendEmailAsync(A <ContactUsEmailRequestModel> .Ignored)).Returns(expectedSendEmailResult);

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

            // Assert
            A.CallTo(() => FakeRoutingService.GetEmailToSendTo(A <string> .Ignored, A <Category> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <ContactUsEmailRequestModel>(A <EnterYourDetailsBodyViewModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeNotifyEmailService.SendEmailAsync(A <ContactUsEmailRequestModel> .Ignored)).MustHaveHappenedOnceExactly();

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

            Assert.Equal(expectedRedirectUrl, redirectResult.Url);
            Assert.False(redirectResult.Permanent);

            controller.Dispose();
        }
Beispiel #17
0
        public async Task ReturnsSuccessWhenNoData(string mediaTypeName)
        {
            // Arrange
            IEnumerable <JobProfileSkillSegmentModel> expectedResults = null;
            var controller             = BuildSegmentController(mediaTypeName);
            var indexDocumentViewModel = new IndexDocumentViewModel {
                CanonicalName = "job-profile-1"
            };

            A.CallTo(() => FakeSkillSegmentService.GetAllAsync()).Returns(expectedResults);
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <JobProfileSkillSegmentModel> .Ignored)).Returns(indexDocumentViewModel);

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

            // Assert
            A.CallTo(() => FakeSkillSegmentService.GetAllAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <JobProfileSkillSegmentModel> .Ignored)).MustNotHaveHappened();

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

            A.Equals(null, model.Documents);

            controller.Dispose();
        }
Beispiel #18
0
        public async Task PagesControllerCallsContentPageServiceUsingPagesRouteForOkResult(string route, int soc, string actionMethod)
        {
            // Arrange
            var controller     = BuildController(route);
            var expectedResult = new JobGroupModel()
            {
                Title = "A title",
            };
            var expectedResults = new List <JobGroupModel> {
                expectedResult
            };
            var expectedViewModel = new DocumentViewModel {
                Title = "A title", Head = A.Dummy <HeadViewModel>(),
            };

            A.CallTo(() => FakeJobGroupDocumentService.GetAllAsync(A <string> .Ignored)).Returns(expectedResults);
            A.CallTo(() => FakeJobGroupDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <JobGroupModel> .Ignored)).Returns(expectedViewModel);

            // Act
            var result = await RunControllerAction(controller, soc, actionMethod).ConfigureAwait(false);

            // Assert
            Assert.IsType <OkObjectResult>(result);
            A.CallTo(() => FakeJobGroupDocumentService.GetAllAsync(A <string> .Ignored)).MustHaveHappenedOnceOrLess();
            A.CallTo(() => FakeJobGroupDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceOrLess();

            controller.Dispose();
        }
Beispiel #19
0
        public async Task PagesControllerHeadJsonReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var pageRequestModel = new PageRequestModel
            {
                Location1 = "a-location-name",
                Location2 = "an-article-name",
            };
            var expectedResult = new ContentPageModel()
            {
                PageLocation = "/" + pageRequestModel.Location1, CanonicalName = pageRequestModel.Location2
            };
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(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(pageRequestModel).ConfigureAwait(false);

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

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

            model.CanonicalUrl.Should().NotBeNull();

            controller.Dispose();
        }
        public async Task SegmentControllerIndexHtmlReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            const int resultsCount    = 2;
            var       expectedResults = A.CollectionOfFake <RelatedCareersSegmentModel>(resultsCount);
            var       controller      = BuildSegmentController(mediaTypeName);
            var       expectedIndexDocumentViewModel = new IndexDocumentViewModel {
                CanonicalName = "test-canonical-name"
            };

            A.CallTo(() => FakeRelatedCareersSegmentService.GetAllAsync()).Returns(expectedResults);
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <RelatedCareersSegmentModel> .Ignored)).Returns(expectedIndexDocumentViewModel);

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

            // Assert
            A.CallTo(() => FakeRelatedCareersSegmentService.GetAllAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <RelatedCareersSegmentModel> .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 PagesControllerDocumentReturnsNotAcceptable(string mediaTypeName)
        {
            // Arrange
            var expectedResult         = A.Fake <JobGroupModel>();
            var controller             = BuildPagesController(mediaTypeName);
            var dummyDocumentViewModel = A.Dummy <DocumentViewModel>();

            dummyDocumentViewModel.HtmlHead = A.Dummy <HtmlHeadViewModel>();

            A.CallTo(() => FakeJobGroupDocumentService.GetAsync(A <Expression <Func <JobGroupModel, bool> > > .Ignored, A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <JobGroupModel> .Ignored)).Returns(dummyDocumentViewModel);

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

            // Assert
            A.CallTo(() => FakeJobGroupDocumentService.GetAsync(A <Expression <Func <JobGroupModel, bool> > > .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <JobGroupModel> .Ignored)).MustHaveHappenedOnceExactly();

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

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

            controller.Dispose();
        }
        public async Task PagesControllerIndexHtmlReturnsSuccessWhenNoData(string mediaTypeName)
        {
            // Arrange
            var controller = BuildSegmentController(mediaTypeName);
            var expectedIndexDocumentViewModel = new IndexDocumentViewModel {
                CanonicalName = "test-canonical-name"
            };

            A.CallTo(() => FakeRelatedCareersSegmentService.GetAllAsync()).Returns((IEnumerable <RelatedCareersSegmentModel>)null);
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <RelatedCareersSegmentModel> .Ignored)).Returns(expectedIndexDocumentViewModel);

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

            // Assert
            A.CallTo(() => FakeRelatedCareersSegmentService.GetAllAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <RelatedCareersSegmentModel> .Ignored)).MustNotHaveHappened();

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

            Assert.Null(model.Documents);

            controller.Dispose();
        }
        public async Task PagesControllerDocumentJsonReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var expectedResult         = A.Fake <JobGroupModel>();
            var controller             = BuildPagesController(mediaTypeName);
            var dummyDocumentViewModel = A.Dummy <DocumentViewModel>();

            dummyDocumentViewModel.HtmlHead = A.Dummy <HtmlHeadViewModel>();

            A.CallTo(() => FakeJobGroupDocumentService.GetAsync(A <Expression <Func <JobGroupModel, bool> > > .Ignored, A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <JobGroupModel> .Ignored)).Returns(dummyDocumentViewModel);

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

            // Assert
            A.CallTo(() => FakeJobGroupDocumentService.GetAsync(A <Expression <Func <JobGroupModel, bool> > > .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <JobGroupModel> .Ignored)).MustHaveHappenedOnceExactly();

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

            _ = Assert.IsAssignableFrom <DocumentViewModel>(jsonResult.Value);

            controller.Dispose();
        }
        public async Task PagesControllerBodyWithNullArticleHtmlReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var pageRequestModel = new PageRequestModel
            {
                Location1 = "a-location-name",
            };
            var expectedResult = new ContentPageModel()
            {
                Content = "<h1>A document</h1>", PageLocation = "/" + pageRequestModel.Location1, CanonicalName = pageRequestModel.Location2
            };
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(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(pageRequestModel).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(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();
        }
        public async Task PagesControllerHeadJsonReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var dummyJobGroupModel = A.Dummy <JobGroupModel>();
            var controller         = BuildPagesController(mediaTypeName);
            var socRequestModel    = new SocRequestModel {
                Soc = 3231, FromJobProfileCanonicalName = "a-job-profile",
            };
            var dummyHeadViewModel = A.Dummy <HeadViewModel>();

            A.CallTo(() => FakeJobGroupDocumentService.GetAsync(A <Expression <Func <JobGroupModel, bool> > > .Ignored, A <string> .Ignored)).Returns(dummyJobGroupModel);
            A.CallTo(() => FakeMapper.Map <HeadViewModel>(A <JobGroupModel> .Ignored)).Returns(dummyHeadViewModel);

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

            // Assert
            A.CallTo(() => FakeJobGroupDocumentService.GetAsync(A <Expression <Func <JobGroupModel, bool> > > .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <HeadViewModel>(A <JobGroupModel> .Ignored)).MustHaveHappenedOnceExactly();

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

            _ = Assert.IsAssignableFrom <HeadViewModel>(jsonResult.Value);

            controller.Dispose();
        }
Beispiel #26
0
        public async Task WebhooksServiceProcessMessageAsyncContentUpdateConfigurationSetReturnsSuccess()
        {
            // Arrange
            const HttpStatusCode expectedResponse         = HttpStatusCode.OK;
            var expectedValidConfigurationSetApiDataModel = BuildValidConfigurationSetApiDataModel();
            var expectedValidConfigurationSetModel        = BuildValidConfigurationSetModel();
            var url     = "https://somewhere.com";
            var service = BuildWebhooksService();

            A.CallTo(() => FakeCmsApiService.GetItemAsync <ConfigurationSetApiDataModel>(A <Uri> .Ignored)).Returns(expectedValidConfigurationSetApiDataModel);
            A.CallTo(() => FakeMapper.Map <ConfigurationSetModel>(A <ConfigurationSetApiDataModel> .Ignored)).Returns(expectedValidConfigurationSetModel);
            A.CallTo(() => FakeConfigurationSetDocumentService.UpsertAsync(A <ConfigurationSetModel> .Ignored)).Returns(HttpStatusCode.OK);

            // Act
            var result = await service.ProcessMessageAsync(WebhookCacheOperation.CreateOrUpdate, Guid.NewGuid(), ContentIdForConfigurationSetUpdate, url).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeCmsApiService.GetItemAsync <EmailApiDataModel>(A <Uri> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeCmsApiService.GetItemAsync <ConfigurationSetApiDataModel>(A <Uri> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <ConfigurationSetModel>(A <ConfigurationSetApiDataModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeConfigurationSetDocumentService.UpsertAsync(A <ConfigurationSetModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeConfigurationSetDocumentService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened();

            Assert.Equal(expectedResponse, result);
        }
Beispiel #27
0
        public async Task ReturnsSuccessForHtmlMediaType(string mediaTypeName)
        {
            // Arrange
            var expectedResult = A.Fake <JobProfileTasksSegmentModel>();
            var controller     = BuildSegmentController(mediaTypeName);
            var viewModel      = GetBodyViewModel();

            expectedResult.CanonicalName = ArticleName;

            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileTasksSegmentModel> .Ignored)).Returns(viewModel);

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileTasksSegmentModel> .Ignored)).MustHaveHappenedOnceExactly();

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

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

            controller.Dispose();
        }
Beispiel #28
0
        public async Task PagesControllerDocumentHtmlReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var expectedResult = A.Fake <SharedContentItemModel>();

            using var controller = BuildPagesController(mediaTypeName);
            var expectedModel = new DocumentViewModel
            {
                Id            = Guid.NewGuid(),
                Title         = "A title",
                PartitionKey  = "partition-key",
                Url           = new Uri("https://somewhere.com", UriKind.Absolute),
                BodyViewModel = new BodyViewModel {
                    Body = new Microsoft.AspNetCore.Html.HtmlString("some content")
                },
                LastReviewed = DateTime.Now,
            };

            A.CallTo(() => FakeSharedContentItemDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <SharedContentItemModel> .Ignored)).Returns(expectedModel);

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

            // Assert
            A.CallTo(() => FakeSharedContentItemDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <SharedContentItemModel> .Ignored)).MustHaveHappenedOnceExactly();

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

            _ = Assert.IsAssignableFrom <DocumentViewModel>(viewResult.ViewData.Model);
            var model = viewResult.ViewData.Model as DocumentViewModel;

            Assert.Equal(expectedModel, model);
        }
Beispiel #29
0
        public async Task ReturnsNotAcceptableForInvalidMediaType(string mediaTypeName)
        {
            // Arrange
            var expectedResult = A.Fake <JobProfileTasksSegmentModel>();
            var controller     = BuildSegmentController(mediaTypeName);
            var viewModel      = GetBodyViewModel();

            expectedResult.CanonicalName = ArticleName;

            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileTasksSegmentModel> .Ignored)).Returns(viewModel);

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileTasksSegmentModel> .Ignored)).MustHaveHappenedOnceExactly();

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

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

            controller.Dispose();
        }
        public async Task SegmentControllerBodyJsonReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var documentId     = Guid.NewGuid();
            var expectedResult = A.Fake <CurrentOpportunitiesSegmentModel>();

            expectedResult.Data = A.Dummy <CurrentOpportunitiesSegmentDataModel>();
            var dummyBodyViewModel = A.Dummy <BodyViewModel>();

            dummyBodyViewModel.Data         = A.Dummy <BodyDataViewModel>();
            dummyBodyViewModel.Data.Courses = A.Dummy <BodyCoursesViewModel>();

            var controller = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <CurrentOpportunitiesSegmentModel> .Ignored)).Returns(dummyBodyViewModel);

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

            // Assert
            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <CurrentOpportunitiesSegmentModel> .Ignored)).MustHaveHappenedOnceExactly();

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

            controller.Dispose();
        }