Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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));
        }