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 PagesControllerDeleteReturnsNotFound(string mediaTypeName) { // Arrange Guid documentId = Guid.NewGuid(); var controller = BuildPagesController(mediaTypeName); A.CallTo(() => FakeJobCategoryContentPageService.DeleteAsync(A <Guid> .Ignored)).Returns(false); // Act var result = await controller.Delete(documentId).ConfigureAwait(false); // Assert A.CallTo(() => FakeJobCategoryContentPageService.DeleteAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); var statusResult = Assert.IsType <NotFoundResult>(result); A.Equals((int)HttpStatusCode.NotFound, 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(); }
public async Task PagesControllerIndexReturnsNotAcceptable(string mediaTypeName) { // Arrange const int resultsCount = 0; IEnumerable <JobCategory>?expectedResults = null; var controller = BuildPagesController(mediaTypeName); A.CallTo(() => FakeJobCategoryContentPageService.GetAllAsync()).Returns(expectedResults); A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <JobCategory> .Ignored)).Returns(A.Fake <IndexDocumentViewModel>()); // Act var result = await controller.Index().ConfigureAwait(false); // Assert A.CallTo(() => FakeJobCategoryContentPageService.GetAllAsync()).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <JobCategory> .Ignored)).MustHaveHappened(resultsCount, Times.Exactly); var statusResult = Assert.IsType <StatusCodeResult>(result); A.Equals((int)HttpStatusCode.NotAcceptable, statusResult.StatusCode); controller.Dispose(); }
public async Task PagesControllerPostReturnsAlreadyReportedForCreate(string mediaTypeName) { // Arrange const HttpStatusCode expectedResponse = HttpStatusCode.AlreadyReported; var existingModel = A.Fake <JobCategory>(); var contentPageModel = A.Fake <JobCategory>(); contentPageModel.DocumentId = Guid.NewGuid(); var controller = BuildPagesController(mediaTypeName); A.CallTo(() => FakeJobCategoryContentPageService.GetByIdAsync(A <Guid> .Ignored)).Returns(existingModel); // Act var result = await controller.Create(contentPageModel).ConfigureAwait(false); // Assert A.CallTo(() => FakeJobCategoryContentPageService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeJobCategoryContentPageService.UpsertAsync(A <JobCategory> .Ignored)).MustNotHaveHappened(); var statusCodeResult = Assert.IsType <StatusCodeResult>(result); Assert.Equal((int)expectedResponse, statusCodeResult.StatusCode); controller.Dispose(); }
public async Task PagesControllerPutReturnsNotFoundForUpdate(string mediaTypeName) { // Arrange const HttpStatusCode expectedResponse = HttpStatusCode.NotFound; JobCategory? expectedResult = null; var modelToUpsert = A.Fake <JobCategory>(); modelToUpsert.DocumentId = Guid.NewGuid(); var controller = BuildPagesController(mediaTypeName); A.CallTo(() => FakeJobCategoryContentPageService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult); // Act var result = await controller.Update(modelToUpsert).ConfigureAwait(false); // Assert A.CallTo(() => FakeJobCategoryContentPageService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); var statusCodeResult = Assert.IsType <StatusCodeResult>(result); Assert.Equal((int)expectedResponse, statusCodeResult.StatusCode); controller.Dispose(); }
public async Task PagesControllerIndexJsonReturnsSuccessWhenNoData(string mediaTypeName) { // Arrange const int resultsCount = 0; IEnumerable <JobCategory>?expectedResults = null; var controller = BuildPagesController(mediaTypeName); A.CallTo(() => FakeJobCategoryContentPageService.GetAllAsync()).Returns(expectedResults); A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <JobCategory> .Ignored)).Returns(A.Fake <IndexDocumentViewModel>()); // Act var result = await controller.Index().ConfigureAwait(false); // Assert A.CallTo(() => FakeJobCategoryContentPageService.GetAllAsync()).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <JobCategory> .Ignored)).MustHaveHappened(resultsCount, Times.Exactly); var jsonResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsAssignableFrom <IndexViewModel>(jsonResult.Value); A.Equals(null, model.Documents); controller.Dispose(); }
public async Task PagesControllerIndexHtmlReturnsSuccess(string mediaTypeName) { // Arrange const int resultsCount = 2; var expectedResults = A.CollectionOfFake <JobCategory>(resultsCount); var controller = BuildPagesController(mediaTypeName); A.CallTo(() => FakeJobCategoryContentPageService.GetAllAsync()).Returns(expectedResults); A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <JobCategory> .Ignored)).Returns(A.Fake <IndexDocumentViewModel>()); // Act var result = await controller.Index().ConfigureAwait(false); // Assert A.CallTo(() => FakeJobCategoryContentPageService.GetAllAsync()).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <JobCategory> .Ignored)).MustHaveHappened(resultsCount, Times.Exactly); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <IndexViewModel>(viewResult.ViewData.Model); A.Equals(resultsCount, model.Documents.Count()); controller.Dispose(); }