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