예제 #1
0
        private async Task <List <Movie> > SearchForMovieRemote(string searchString)
        {
            var searchTask = OMDbAPI.SearchForMoviesByTitle(searchString);

            Logger.Info("SEARCH", $"Searching for {searchString} in OMDB");
            List <Movie> movies = await searchTask;


            if (movies is null) // no movies found
            {
                Logger.Warn("HTTP", $"Found 0 matches in OMDB for {searchString}");
                return(null);
            }

            Logger.Info("SEARCH", $"Found {movies?.Count ?? 0} matches in OMDB for {searchString}");

            for (int i = 0; i < movies.Count; i++)
            {
                Console.WriteLine($"{i}\t{movies[i].TitleYear}");
            }

            if (!PresentYesNoQuestion("Is your movie in this list?"))
            {
                return(null);
            }

            Console.WriteLine("============");
            Console.WriteLine("Enter the ID of the movie you wish to load full info for.");

            // Select the specific movie and get the info
            string input = Console.ReadLine();

            if (int.TryParse(input, out int selection) &&
                selection >= 0 && selection < movies.Count)
            {
                Movie m = await LoadInfoForMovie(movies[selection]);  // Load the Movie from OMDB

                await movieController.AddCachedMovie(m);              // Add Movie to local cache

                Console.WriteLine($"{m.TitleYear} added to local cache");
                List <Movie> output = new List <Movie>();       // Create a new list to return
                output.Add(m);                                  // add single movie to the list
                return(output);                                 // return the list with a single movie element
            }

            else
            {
                Console.WriteLine("Invalid input");
            }

            return(null);
        }
        public async Task SearchForMoviesByTitleTest()
        {
            List <Movie> result = await OMDbAPI.SearchForMoviesByTitle(null);

            Assert.IsNull(result);
        }