public async void TestGetItemByTitleBad() { var omdb = new AsyncOmdbClient(TestData.apikey, true); await Assert.ThrowsAsync <ArgumentException>(() => omdb.GetItemByTitleAsync(null)); await Assert.ThrowsAsync <ArgumentException>(() => omdb.GetItemByTitleAsync("")); await Assert.ThrowsAsync <ArgumentException>(() => omdb.GetItemByTitleAsync(" ")); await Assert.ThrowsAsync <ArgumentOutOfRangeException>(() => omdb.GetItemByTitleAsync("star wars", 1500)); }
public async void TestGetItemByTitleGood2() { var omdb = new AsyncOmdbClient(TestData.apikey, true); var movie = await omdb.GetItemByTitleAsync("Star Wars", OmdbType.Movie, 2017, false); var ratings = movie.Ratings.ToArray(); Assert.Equal("Internet Movie Database", ratings[0].Source); Assert.Equal("Rotten Tomatoes", ratings[1].Source); Assert.Equal("Metacritic", ratings[2].Source); Assert.Equal("Star Wars: The Last Jedi", movie.Title); Assert.Equal("2017", movie.Year); Assert.Equal("PG-13", movie.Rated); Assert.Equal("15 Dec 2017", movie.Released); Assert.Equal("152 min", movie.Runtime); Assert.Equal("Rian Johnson", movie.Director); Assert.Equal("English", movie.Language); Assert.Equal("USA", movie.Country); Assert.Equal("movie", movie.Type); Assert.Equal("http://www.rottentomatoes.com/m/star_wars_episode_viii/", movie.TomatoUrl); Assert.Equal("Walt Disney Pictures", movie.Production); Assert.Null(movie.TotalSeasons); Assert.Equal("True", movie.Response); }
public async void TestGetItemByTitleGood1() { var omdb = new AsyncOmdbClient(TestData.apikey); var movie = await omdb.GetItemByTitleAsync("Star Wars", true); var ratings = movie.Ratings.ToArray(); Assert.Equal("Internet Movie Database", ratings[0].Source); Assert.Equal("Rotten Tomatoes", ratings[1].Source); Assert.Equal("Metacritic", ratings[2].Source); Assert.Equal("Star Wars: Episode IV - A New Hope", movie.Title); Assert.Equal("1977", movie.Year); Assert.Equal("PG", movie.Rated); Assert.Equal("25 May 1977", movie.Released); Assert.Equal("121 min", movie.Runtime); Assert.Equal("George Lucas", movie.Director); Assert.Equal("George Lucas", movie.Writer); Assert.Equal("English", movie.Language); Assert.Equal("USA", movie.Country); Assert.Equal("tt0076759", movie.ImdbId); Assert.Equal("movie", movie.Type); Assert.Equal("21 Sep 2004", movie.Dvd); Assert.Equal("20th Century Fox", movie.Production); Assert.Equal("http://www.starwars.com/episode-iv/", movie.Website); Assert.Null(movie.TotalSeasons); Assert.Equal("True", movie.Response); }
public async Task <OmdbMovieInfo?> TryGetItemByTitleAsync(string title, bool fullPlot = false) { title.ThrowIfNullOrWhiteSpace(nameof(title)); _logger.Info($"Getting OMDb item by title \"{title}\" " + $"[fullPlot: {fullPlot.ToString()}]."); Item response; try { response = await _omdbClient.GetItemByTitleAsync(title, fullPlot); } catch (Exception ex) { _logger.Warn(ex, $"Exception occurred during processing response for \"{title}\"."); return(null); } if (!string.Equals(response.Response, "True", StringComparison.OrdinalIgnoreCase)) { _logger.Warn($"Got response for \"{title}\" with negative result."); return(null); } return(_dataMapper.Transform(response)); }
/// <inheritdoc /> public override async Task <bool> GetResponse(BufferBlock <string> entitiesQueue, BufferBlock <BasicInfo> responsesQueue, bool outputResults) { // Use HashSet to avoid duplicated data which can produce errors in further work. var searchResults = new HashSet <BasicInfo>(); while (await entitiesQueue.OutputAvailableAsync()) { string movie = await entitiesQueue.ReceiveAsync(); Item response; try { response = await _omdbClient.GetItemByTitleAsync(movie); } catch (Exception ex) { _logger.Warn(ex, $"{movie} wasn't processed."); GlobalMessageHandler.OutputMessage($"{movie} wasn't processed."); continue; } if (!response.Response.IsEqualWithInvariantCulture("True")) { _logger.Warn($"{movie} wasn't processed."); GlobalMessageHandler.OutputMessage($"{movie} wasn't processed."); continue; } // Get first search result from response and ignore all the rest. if (outputResults) { GlobalMessageHandler.OutputMessage($"Got {response.Title} from {Tag}"); } OmdbMovieInfo extractedInfo = _dataMapper.Transform(response); if (searchResults.Add(extractedInfo)) { await responsesQueue.SendAsync(extractedInfo); } } return(searchResults.Count != 0); }
public async void TestGetItemByTitleGood3() { var omdb = new AsyncOmdbClient(TestData.apikey, true); var movie = await omdb.GetItemByTitleAsync("Arrow", OmdbType.Series, 2012, false); var ratings = movie.Ratings.ToArray(); Assert.Equal("Internet Movie Database", ratings[0].Source); Assert.Equal("Arrow", movie.Title); Assert.Equal("2012–", movie.Year); Assert.Equal("TV-14", movie.Rated); Assert.Equal("10 Oct 2012", movie.Released); Assert.Equal("42 min", movie.Runtime); Assert.Equal("N/A", movie.Director); Assert.Equal("English", movie.Language); Assert.Equal("USA", movie.Country); Assert.Equal("series", movie.Type); Assert.Equal("N/A", movie.Dvd); Assert.Equal("N/A", movie.BoxOffice); Assert.Equal("N/A", movie.Production); Assert.Equal("N/A", movie.Website); Assert.Equal("True", movie.Response); }
public async void TestGetItemByTitleBad2() { var omdb = new AsyncOmdbClient(TestData.apikey, true); await Assert.ThrowsAsync <HttpRequestException>(() => omdb.GetItemByTitleAsync("Skyrim", OmdbType.Game)); }