You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.1 KiB

  1. using System.Linq;
  2. using Xunit;
  3. using TMDbLib.Objects.General;
  4. using TMDbLib.Objects.Movies;
  5. using TMDbLib.Objects.Search;
  6. using TMDbLibTests.Helpers;
  7. using TMDbLibTests.JsonHelpers;
  8. namespace TMDbLibTests
  9. {
  10. public class ClientKeywordTests : TestBase
  11. {
  12. [Fact]
  13. public void TestKeywordGet()
  14. {
  15. KeywordsContainer keywords = Config.Client.GetMovieKeywordsAsync(IdHelper.AGoodDayToDieHard).Result;
  16. Assert.NotNull(keywords);
  17. Assert.NotNull(keywords.Keywords);
  18. Assert.True(keywords.Keywords.Count > 0);
  19. // Try to get all keywords
  20. foreach (Keyword testKeyword in keywords.Keywords)
  21. {
  22. Keyword getKeyword = Config.Client.GetKeywordAsync(testKeyword.Id).Result;
  23. Assert.NotNull(getKeyword);
  24. Assert.Equal(testKeyword.Id, getKeyword.Id);
  25. Assert.Equal(testKeyword.Name, getKeyword.Name);
  26. }
  27. }
  28. [Fact]
  29. public void TestKeywordMovies()
  30. {
  31. // Ignore missing json
  32. IgnoreMissingJson("results[array] / media_type");
  33. KeywordsContainer keywords = Config.Client.GetMovieKeywordsAsync(IdHelper.AGoodDayToDieHard).Result;
  34. Assert.NotNull(keywords);
  35. Assert.NotNull(keywords.Keywords);
  36. Assert.True(keywords.Keywords.Count > 0);
  37. // Get first keyword
  38. Keyword testKeyword = keywords.Keywords.First();
  39. // Get movies
  40. SearchContainerWithId<SearchMovie> movies = Config.Client.GetKeywordMoviesAsync(testKeyword.Id).Result;
  41. SearchContainerWithId<SearchMovie> moviesItalian = Config.Client.GetKeywordMoviesAsync(testKeyword.Id, "it").Result;
  42. SearchContainerWithId<SearchMovie> moviesPage2 = Config.Client.GetKeywordMoviesAsync(testKeyword.Id, 2).Result;
  43. Assert.NotNull(movies);
  44. Assert.NotNull(moviesItalian);
  45. Assert.NotNull(moviesPage2);
  46. Assert.Equal(testKeyword.Id, movies.Id);
  47. Assert.Equal(testKeyword.Id, moviesItalian.Id);
  48. Assert.Equal(testKeyword.Id, moviesPage2.Id);
  49. Assert.True(movies.Results.Count > 0);
  50. Assert.True(moviesItalian.Results.Count > 0);
  51. if (movies.TotalResults > movies.Results.Count)
  52. Assert.True(moviesPage2.Results.Count > 0);
  53. else
  54. Assert.Equal(0, moviesPage2.Results.Count);
  55. Assert.Equal(1, movies.Page);
  56. Assert.Equal(1, moviesItalian.Page);
  57. Assert.Equal(2, moviesPage2.Page);
  58. // All titles on page 1 must be the same
  59. bool allTitlesIdentical = true;
  60. for (int index = 0; index < movies.Results.Count; index++)
  61. {
  62. Assert.Equal(movies.Results[index].Id, moviesItalian.Results[index].Id);
  63. // At least one title must differ in title
  64. if (movies.Results[index].Title != moviesItalian.Results[index].Title)
  65. allTitlesIdentical = false;
  66. }
  67. Assert.False(allTitlesIdentical);
  68. }
  69. }
  70. }