public async Task GetCachedMoviesTest()
        {
            MovieController movieController = new MovieController();
            List <Movie>    movies          = await movieController.GetCachedMovies();

            // Assuming the json file does not exists, this should reutrn null
            Assert.IsNull(movies);
        }
Пример #2
0
        static async Task PrintMovieCache()
        {
            Console.Clear();

            List <Movie> cachedMovies = await movieController.GetCachedMovies();

            if (cachedMovies is null)
            {
                Logger.Error("CACHE", "Unable to print movie cache. The cache is not loaded");
                PressAnyKeyToContinue();
                return;
            }

            for (int i = 0; i < cachedMovies.Count; i++)
            {
                Movie m = cachedMovies[i];
                Console.WriteLine($"{m.ID}: {m.TitleYear}");
            }

            PressAnyKeyToContinue();
        }
Пример #3
0
        private async Task <List <Movie> > SearchForMoviesLocal(string searchString)
        {
            searchString = searchString.ToLower().StripDiacritics();  // Ignore case

            var cacheTask = movieController.GetCachedMovies();

            Logger.Info("SEARCH", $"Searching for {searchString} in local cache");
            List <Movie> cachedMovies = await cacheTask;

            if (cachedMovies is null)
            {
                return(null);
            }

            // Search for exact match
            var movieQuery = from mov in cachedMovies
                             where mov.Title.ToLower().StripDiacritics() == searchString
                             select mov;

            if (movieQuery.Count() > 0)
            {
                return(movieQuery.ToList());
            }

            // Search for partial matches
            movieQuery = from mov in cachedMovies
                         where mov.Title.ToLower().StripDiacritics().Contains(searchString)
                         select mov;

            if (movieQuery.Count() > 0)
            {
                Console.WriteLine($"Found {movieQuery.Count()} partial match(es)");
                return(movieQuery.ToList());
            }

            return(null);
        }