Exemple #1
0
        public async void TestTag()
        {
            var TagArticle = await repository.FindAllbyTag(1);

            Assert.NotNull(TagArticle);
            Assert.Equal(2, TagArticle.Count);
            Assert.IsType <List <Article> >(TagArticle);
            TagArticle = await repository.FindAllbyTag(2);

            Assert.NotNull(TagArticle);
            Assert.Single(TagArticle);
            Assert.IsType <List <Article> >(TagArticle);
            Assert.Equal("Test2", TagArticle[0].Text);
            TagArticle = await repository.FindAllbyTag(14);

            Assert.IsType <List <Article> >(TagArticle);
            Assert.Empty(TagArticle);
        }
 public async Task <IActionResult> Index(int?id)
 {
     if (id != null)
     {
         List <Article> articles;
         try
         {
             articles = await _articleRepository.FindAllbyTag(id.Value);
         }
         catch (Exception)
         {
             _logger.LogError("Doesn't exist id. Controller:Home. Action:Index");
             return(NotFound());
         }
         ViewData["Tags"] = (await _tagRepository.FirstOrDefaultAsync(id.Value)).TagName;
         return(View(articles));
     }
     ViewData["Tags"] = "Все статьи";
     return(View(await _articleRepository.FindAll()));
 }