Exemplo n.º 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));
     }
 }
Exemplo n.º 2
0
 public ActionResult <List <Article> > GetArticle(string userId)
 {
     if (string.IsNullOrEmpty(userId))
     {
         return(NotFound());
     }
     return(_articlesService.GetArticle(userId));
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }