public async Task AddCachedMovieTest()
        {
            MovieController movieController = new MovieController();

            Movie testMovie1 = new Movie
            {
                Title = "test"
            };

            Movie testMovie2 = new Movie
            {
                Title = "test"
            };

            // Should return true for the first time the same movie is added, false the 2nd time
            Assert.IsTrue(await movieController.AddCachedMovie(testMovie1));
            Assert.IsFalse(await movieController.AddCachedMovie(testMovie2));

            // Clear the test cache
            A1ClearCacheTest();
        }
Example #2
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);
        }