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(); }
public async Task PagesControllerBodyWithNullArticleHtmlReturnsSuccess(string mediaTypeName) { // Arrange const string?article = null; var expectedResult = new JobCategory() { Title = "Care Worker" }; var controller = BuildPagesController(mediaTypeName); expectedResult.CanonicalName = article; A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(A <string> .Ignored)).Returns(expectedResult); A.CallTo(() => FakeMapper.Map(A <JobCategory> .Ignored, A <BodyViewModel> .Ignored)).Returns(A.Fake <BodyViewModel>()); // Act var result = await controller.Body(article).ConfigureAwait(false); // Assert A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly(); var viewResult = Assert.IsType <ViewResult>(result); _ = Assert.IsAssignableFrom <BodyViewModel>(viewResult.ViewData.Model); controller.Dispose(); }
public async Task PagesControllerBodyReturnsNotAcceptable(string mediaTypeName) { // Arrange const string article = "an-article-name"; var expectedResult = new JobCategory() { Title = "Care Worker" }; var controller = BuildPagesController(mediaTypeName); expectedResult.CanonicalName = article; A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(A <string?> .Ignored)).Returns(expectedResult); A.CallTo(() => FakeMapper.Map(A <JobCategory> .Ignored, A <BodyViewModel> .Ignored)).Returns(A.Fake <BodyViewModel>()); // Act var result = await controller.Body(article).ConfigureAwait(false); // Assert A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly(); var statusResult = Assert.IsType <StatusCodeResult>(result); A.Equals((int)HttpStatusCode.NotAcceptable, statusResult.StatusCode); controller.Dispose(); }
public async Task PagesControllerSidebarRightWithNullArticleJsonReturnsSuccess(string mediaTypeName) { // Arrange const string?article = null; var controller = BuildPagesController(mediaTypeName); JobCategory? expectedResult = null; A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(A <string> .Ignored)).Returns(expectedResult); // Act var result = await controller.SidebarRight(article); // Assert var statusResult = Assert.IsType <NoContentResult>(result); A.Equals((int)HttpStatusCode.NoContent, statusResult.StatusCode); controller.Dispose(); }
public async Task PagesControllerDocumentReturnsNoContentWhenNoData(string mediaTypeName) { // Arrange const string article = "an-article-name"; JobCategory? expectedResult = null; var controller = BuildPagesController(mediaTypeName); A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(A <string> .Ignored)).Returns(expectedResult); // Act var result = await controller.Document(article).ConfigureAwait(false); // Assert A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly(); var statusResult = Assert.IsType <NoContentResult>(result); A.Equals((int)HttpStatusCode.NoContent, statusResult.StatusCode); controller.Dispose(); }
public async Task PagesControllerHtmlHeadHtmlReturnsSuccessWhenNoData(string mediaTypeName) { // Arrange const string article = "an-article-name"; JobCategory? expectedResult = null; var controller = BuildPagesController(mediaTypeName); A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(A <string> .Ignored)).Returns(expectedResult); // Act var result = await controller.HtmlHead(article).ConfigureAwait(false); // Assert A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly(); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <HtmlHeadViewModel>(viewResult.ViewData.Model); model.CanonicalUrl.Should().BeNull(); controller.Dispose(); }
public async Task PagesControllerBreadcrumbJsonReturnsSuccessWhenNoData(string mediaTypeName) { // Arrange const string article = "an-article-name"; JobCategory? expectedResult = null; var controller = BuildPagesController(mediaTypeName); A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(A <string> .Ignored)).Returns(expectedResult); // Act var result = await controller.Breadcrumb(article).ConfigureAwait(false); // Assert A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(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 PagesControllerDocumentHtmlReturnsSuccess(string mediaTypeName) { // Arrange const string article = "an-article-name"; var expectedResult = A.Fake <JobCategory>(); var controller = BuildPagesController(mediaTypeName); A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(A <string> .Ignored)).Returns(expectedResult); A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <JobCategory> .Ignored)).Returns(A.Fake <DocumentViewModel>()); // Act var result = await controller.Document(article).ConfigureAwait(false); // Assert A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <JobCategory> .Ignored)).MustHaveHappenedOnceExactly(); var viewResult = Assert.IsType <ViewResult>(result); _ = Assert.IsAssignableFrom <DocumentViewModel>(viewResult.ViewData.Model); controller.Dispose(); }