Пример #1
0
 public ActionResult Details(int?id)
 {
     if (id == null)
     {
         var model = articlesService.GetArticle("1");
         return(View(model));
     }
     else
     {
         var model = articlesService.GetArticle(id.ToString());
         return(View(model));
     }
 }
Пример #2
0
 public ActionResult <List <Article> > GetArticle(string userId)
 {
     if (string.IsNullOrEmpty(userId))
     {
         return(NotFound());
     }
     return(_articlesService.GetArticle(userId));
 }
Пример #3
0
        public async Task GetArticleById_Test()
        {
            // Arrange
            var articlesService = new ArticlesService(this.dbContext);

            this.dbContext.Articles.Add(new Article {
                Title = "GetTitle", Content = "GetContent"
            });
            await this.dbContext.SaveChangesAsync();

            // Act
            var article = await articlesService.GetArticle(1);

            // Assert
            Assert.AreEqual("GetTitle", article.Title);
        }
Пример #4
0
        public async Task GetArticleById_ShouldReturnNull_Test()
        {
            // Arrange
            var articlesService = new ArticlesService(this.dbContext);

            this.dbContext.Articles.Add(new Article {
                Title = "TestTitle1", Content = "TestContent1"
            });
            this.dbContext.Articles.Add(new Article {
                Title = "TestTitle2", Content = "TestContent2"
            });
            await this.dbContext.SaveChangesAsync();

            // Act
            var article = await articlesService.GetArticle(15);

            // Assert
            Assert.AreEqual(null, article);
        }