public async Task ArticlesLastestTest() { // Act var id = "%c2%a1el-15-de-diciembre-llega-un-servicio-mejor-a-la-zona-sur-del-condado-de-alameda"; var call = await article.Article(id) as OkNegotiatedContentResult <Post>; Assert.IsNotNull(call); var result = call.Content; Assert.IsNotNull(result); }
void Article_InvalidArticleId_RedirectsToErrorView() { var articlesRepoMock = new Mock <IArticleRepository>(); articlesRepoMock.Setup(x => x.Articles).Returns(new Article[] { new Article { Id = 1 } } .AsQueryable()); var newsController = new NewsController(articlesRepoMock.Object, null); var result = (RedirectToActionResult)newsController.Article(0); Assert.Equal("Error", result.ControllerName); Assert.Equal("Article", result.ActionName); }
void Article_DisplaysViewWithCorrectModel() { var articlesRepoMock = new Mock <IArticleRepository>(); articlesRepoMock.Setup(x => x.Articles).Returns(new Article[] { new Article { Id = 0 }, new Article { Id = 1 }, new Article { Id = 2 } } .AsQueryable()); var newsController = new NewsController(articlesRepoMock.Object, null); var result = (ViewResult)newsController.Article(1); var viewModel = (ArticleViewModel)result.ViewData.Model; Assert.Equal(nameof(newsController.Article), result.ViewName); Assert.Equal(1, viewModel.Article.Id); articlesRepoMock.Verify(x => x.IncrementViewCount(viewModel.Article)); }