public MovieControllerTests() { _collections = new List <Collection> { new Collection { Id = "id1", Name = "collection1", PrimaryImage = "image1", Type = CollectionType.Movies }, new Collection { Id = "id2", Name = "collection2", PrimaryImage = "image2", Type = CollectionType.Movies } }; _movieStats = new MovieStats { LongestMovie = new Poster { Name = "The lord of the rings" } }; _movieServiceMock = new Mock <IMovieService>(); _movieServiceMock.Setup(x => x.GetMovieCollections()).Returns(_collections); _movieServiceMock.Setup(x => x.GetGeneralStatsForCollections(It.IsAny <List <string> >())) .Returns(_movieStats); _subject = new MovieController(_movieServiceMock.Object); }
private static List <MovieStats> GetOrderedMovieStats(string path) { return(File.ReadAllLines(path) .Skip(1) .Select(v => MovieStats.FromCsv(v)) .OrderByDescending(x => x.WatchDurationMs) .ToList()); }
public IEnumerable <MovieStats> CalcStats() { var movies = new Movies().GetAll().ToList(); var instances = GetInstances(); var result = new Dictionary <int, MovieStats>(); MovieStats rec; string title = "(unknown)"; int releaseYear = 0; bool movieFound; foreach (var i in instances) { if (result.ContainsKey(i.MovieId)) { // stats record already exists, so just update it rec = result[i.MovieId]; rec.AverageWatchDurationS += i.WatchDurationMs / 1000; rec.Watches++; } else { // find the relevant movie record and make a note of some data from it movieFound = false; foreach (var movie in movies) { if (movie.MovieId == i.MovieId) { title = movie.Title; releaseYear = movie.ReleaseYear; movieFound = true; break; } } // create a new stats record with data from movie record and instance if (movieFound) { rec = new MovieStats() { MovieId = i.MovieId, Title = title, AverageWatchDurationS = i.WatchDurationMs / 1000, Watches = 1, ReleaseYear = releaseYear, }; result.Add(i.MovieId, rec); } } } return(result.Values); }
public static MovieStats MovieStatsFromCsv(string csvLine) { string[] values = csvLine.Split(','); if (values.Count() > 2) { values = Regex.Split(csvLine, ",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))"); } try{ MovieStats movieStats = new MovieStats(); movieStats.movieId = Convert.ToInt32(values[0]); movieStats.averageWatchDurationS = Convert.ToInt32(values[1]); return(movieStats); } catch (Exception ex) { return(null); } }