Skip to content

News Service

News Service

As a part of the ModelApp offerings, developers have recently added a News section to the website to render news regarding personal insurance. Articles are retrieved using NewsAPI which is a free-to-use service for grabbing the latest news.

News Controller

The ModelApp has a NewsController class that is used to retrieve articles via our news service and return a list of Articles to our View layer to render them for users. Recently a new feature was introduced to make sure article titles are fully capitalized to garner user attention.

public class NewsController : Controller
{
    private readonly INewsService _newsService;

    public NewsController(INewsService newsService)
    {
        _newsService = newsService;
    }

    public IActionResult Index()
    {
        List<Article> _articleList = (List<Article>)_newsService.TopHousingHeadlines();

        _articleList.RemoveAll(article => article.Title is null); 

        _articleList.ForEach(article => article.Title = article.Title.ToUpper()); 

        ViewData["Articles"] = _articleList;
        return View();
    }
}

Problem

Our new code has not been tested yet! We need to make sure the new logic both:

  • Produces the correct result
  • Can handle new edge cases when working with the news service