public async Task <IActionResult> GetArticleById(string id) { var article = await _articlesService.GetArticleById(id); if (article == null) { return(new StatusCodeAndDtoWrapper(404, new ErrorDtoResponse("Not Found"))); } //return NotFound(); return(new StatusCodeAndDtoWrapper(ArticleDetailsDto.Build(article))); }
public async Task ChecksIfGetArticleByIdReturnsCorrectResult() { var options = new DbContextOptionsBuilder <ElectricTravelDbContext>() .UseInMemoryDatabase(databaseName: "ArticlesTestDb").Options; using var dbContext = new ElectricTravelDbContext(options); var user = new ElectricTravelUser { UserName = "******", }; var articleToAdd = new Article { ShortDescription = "asdasd", Content = "asdasdad", CreatedBy = user, Title = "asdas", }; dbContext.Users.Add(user); dbContext.Articles.Add(articleToAdd); dbContext.SaveChanges(); using var repo = new EfDeletableEntityRepository <Article>(dbContext); var service = new ArticlesService(repo); var article = await service.GetArticleById <ArticleViewModel>(articleToAdd.Id); Assert.NotNull(article); }