Esempio n. 1
0
        private static async Task Main(string[] args)
        {
            CsfdApi csfdApi = new CsfdApi();
            // Get movie by exact URL
            Movie movie = await csfdApi.GetMovie("https://www.csfd.cz/film/6648-predator/prehled/");

            // Get all Cinema listings
            IEnumerable <Cinema> listings = await csfdApi.GetAllCinemaListings();

            // Get Cinema listings in Prague
            IEnumerable <Cinema> listingsPrague = await csfdApi.GetCinemaListing("https://www.csfd.cz/kino/?district=1&period=all");
        }
Esempio n. 2
0
        public async Task GetMovie_GetsMovie()
        {
            var mov = await _csfdApi.GetMovie("https://www.csfd.cz/film/6648-predator/");

            // Check title
            const string expectedTitle = "Predátor";

            Assert.AreEqual(expectedTitle, mov.Title);

            // Rating should be 0-100
            Assert.IsTrue(mov.Rating >= 0 && mov.Rating <= 100);

            // Check genres
            var expectedGenres = new List <string> {
                "Akční", "Sci-Fi", "Horor"
            };

            foreach (var genre in expectedGenres)
            {
                Assert.IsTrue(expectedGenres.Contains(genre),
                              $"Movie genres do not contain expected genre '{genre}'. Actual genres: '{string.Join(",", mov.Genres)}'");
            }

            // Check year
            Assert.AreEqual("1987", mov.Year);

            Assert.IsFalse(string.IsNullOrEmpty(mov.PosterUrl), $"Poster URL was empty or null: '{mov.PosterUrl}'");
        }
Esempio n. 3
0
        private int GetMovieRating(string url)
        {
            try
            {
                var cacheResult = _cache.GetString(url);
                if (cacheResult != null)
                {
                    return(int.Parse(cacheResult));
                }

                var movie = _csfdApi.GetMovie(url).Result;
                _cache.SetString(url, movie.Rating.ToString(),
                                 new DistributedCacheEntryOptions {
                    AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(8)
                });
                return(movie.Rating);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Failed to get movie, will retry. Exception:{Environment.NewLine}{e}");
                return(0);
            }
        }