public async Task <List <MovieDTO> > RecommendedMoviesByUserId(string userId) { List <string> followedMovieIds = _repo.GetFollowingMovies(userId); var numberOfMovies = Math.Min(3, followedMovieIds.Count); var randomIndiciesArray = GetRandomUniquePositiveInts(numberOfMovies, followedMovieIds.Count); var loadRecommendedTask = new List <Task <List <string> > >(); for (int i = 0; i < numberOfMovies; i++) { loadRecommendedTask.Add(ApiProcessor.LoadRecommendedMovies(followedMovieIds[randomIndiciesArray[i]])); } var movieIds = new HashSet <string>(); while (loadRecommendedTask.Count > 0) { var completedTask = await Task.WhenAny(loadRecommendedTask); foreach (var recommendedURL in completedTask.Result) { var movieId = ParseMovieIdFromURL(recommendedURL); movieIds.Add(movieId); } loadRecommendedTask.Remove(completedTask); } foreach (var followedMovieId in followedMovieIds) { movieIds.Remove(followedMovieId); } var getMovieTasks = new List <Task <MovieDTO> >(); foreach (var movieId in movieIds) { getMovieTasks.Add(GetMovie(movieId)); } var recommendedDTOs = new List <MovieDTO>(); while (getMovieTasks.Count > 0) { var completedTask = await Task.WhenAny(getMovieTasks); recommendedDTOs.Add(completedTask.Result); getMovieTasks.Remove(completedTask); } return(recommendedDTOs); }
public async Task <List <string> > GetFollowingMovies(string username) { List <Repository.Models.FollowingMovie> repoFollowingMovies = await _repo.GetFollowingMovies(username); if (repoFollowingMovies == null) { Console.WriteLine("UserLogic.GetFollowingMovies() was called for a username that doesn't exist."); return(null); } List <string> followingMovies = new List <string>(); foreach (var repoFollowingMovie in repoFollowingMovies) { followingMovies.Add(repoFollowingMovie.MovieId); } return(followingMovies); }
public async Task NoUserGetFollowingMovieTest() { object result; RelatedDataSet dataSetA = new RelatedDataSet("JimmyJimerson", "ab10101010", "Theory"); using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); RepoLogic repoLogic = new RepoLogic(context); // Test GetFollowingMovies() without User dependency result = await repoLogic.GetFollowingMovies(dataSetA.User.Username); } Assert.Null(result); }