public void TestGroupMovies() { RootObject rootObject = new RootObject() { per_page = 10, total = 1, total_pages = 1, data = new List <Movie>() { new Movie { Title = "Spiderman 5", Year = 2008, imdbID = "tt3696826" } } }; YearSearchList yearSearchList = new YearSearchList() { moviesByYear = new List <YearSearch>() { new YearSearch(2008, 1) }, total = 1 }; Assert.AreEqual(yearSearchList.moviesByYear[0].year, movieSvcGRPC.GroupMovies(rootObject).moviesByYear[0].year); Assert.AreEqual(yearSearchList.moviesByYear[0].movies, movieSvcGRPC.GroupMovies(rootObject).moviesByYear[0].movies); }
public YearSearchList GroupMovies(RootObject rootObject) { YearSearchList resultList = new YearSearchList(); var groupedResult = rootObject.data.ToList().GroupBy(x => x.Year).Select(y => new { y.Key, count = y.Count() }).OrderBy(x => x.Key).ToList(); foreach (var item in groupedResult) { resultList.moviesByYear.Add(new YearSearch(item.Key, item.count)); } resultList.getTotalSum(); return(resultList); }